I am in the process of creating a decorator to verify the validity of certain parameters.
Below is the method I am working on,
getUsers(offset, limit, orderBy, sort){
....
}
I want to ensure that the value of orderBy is either 'createdAt' or 'updatedAt'; otherwise, an HTTP response will be returned.
Similarly, for the sort parameter, it should only be 'ASC' or 'DESC'.
Therefore, I am looking for a way to utilize a decorator to streamline this validation process and make my code more concise. Currently, I have the following block of code to perform these checks:
if (!includes(this.orderByFields, orderBy)) {
return Utils.HttpError.badRequest(`You are allowed to order by [ ${this.orderByFields.join(', ')} ] only.`);
}
If you have any suggestions on how to achieve this using decorators, that would be greatly appreciated. Thank you in advance :-)