1
我想写一个装饰,可以检查查询参数的长度,我有这样的方法:我可以在装饰器方法中获取变量的名称吗?
@httpPost("doAuth")
@ValidateSize([{login: {min: 6}}, {password: {min: 6}}])
public async auth(@requestBody("login") login :string, @requestBody("password") pass :string, @response() response :express.Response){
let user :UserData = await this.authService.auth(login, pass);
if(!user) return response.sendStatus(403);
return user;
}
的装饰自己:
export function ValidateSize(param :Object) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
return {
value: function (...args: any[]) {
//Here I need to get the variables login, pass that to check their length
}
};
}
}
的问题是,args
是具有数字索引的数组,但我需要通过名称获取参数。我怎样才能做到这一点?
JS/TS没有命名参数,'login'将会是'args [0]'。 – jonrsharpe