Skip to content

Commit 489d0e3

Browse files
author
hirsch88
committed
Fix and refactor validator annotaion
1 parent a745e73 commit 489d0e3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/api/services/UserService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class UserService {
7777
* @param {*} data is the json body of the request
7878
* @returns {Promise<User>}
7979
*/
80-
@Validate
80+
@Validate()
8181
public async create( @Request(UserCreateRequest) data: any): Promise<User> {
8282
// If the request body was valid we will create the user
8383
const user = await this.userRepo.create(data);
@@ -93,7 +93,7 @@ export class UserService {
9393
* @param {*} newUser is the json body of the request
9494
* @returns {Promise<User>}
9595
*/
96-
@Validate
96+
@Validate()
9797
public async update(id: number, @Request(UserUpdateRequest) newUser: any): Promise<User> {
9898
// Find or fail
9999
const user = await this.findOne(id);

src/console/templates/service.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export class {{name.capitalize}}Service {
3939
return {{name.camelCase}};
4040
}
4141

42-
@Validate
42+
@Validate()
4343
public async create( @Request({{name.capitalize}}CreateRequest) body: any): Promise<{{name.capitalize}}> {
4444
// If the request body was valid we will create the {{name.camelCase}}
4545
const {{name.camelCase}} = await this.{{name.camelCase}}Repo.create(body);
4646
return {{name.camelCase}};
4747
}
4848

49-
@Validate
49+
@Validate()
5050
public async update(id: number, @Request({{name.capitalize}}UpdateRequest) body: any): Promise<{{name.capitalize}}> {
5151
// Find or fail
5252
const {{name.camelCase}} = await this.findOne(id);

src/core/api/Validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const Request = (request: typeof RequestBody) => (target: object, propert
4040
* @param propertyName
4141
* @param descriptor
4242
*/
43-
export const Validate = (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<() => void>): any => {
43+
export const Validate = () => (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>): any => {
4444
const method = descriptor.value;
4545
descriptor.value = async function(...args: any[]): Promise<any> {
4646
const requestParameters: RequestParameter[] = Reflect.getOwnMetadata(requestMetadataKey, target, propertyName);

0 commit comments

Comments
 (0)