Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Use explicit ID type in params
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 15, 2020
1 parent 3d73c61 commit 5abcc56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
20 changes: 12 additions & 8 deletions src/modules/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,40 @@ export class GroupController {
});
}

@Get(':id')
@Get(':groupId')
@Scopes('group-{id}:read-info')
async get(@Param('id', ParseIntPipe) id: number): Promise<Expose<groups>> {
async get(
@Param('groupId', ParseIntPipe) id: number,
): Promise<Expose<groups>> {
return this.groupsService.getGroup(Number(id));
}

@Patch(':id')
@Patch(':groupId')
@AuditLog('update-info')
@Scopes('group-{id}:write-info')
async update(
@Body() data: UpdateGroupDto,
@Param('id', ParseIntPipe) id: number,
@Param('groupId', ParseIntPipe) id: number,
): Promise<Expose<groups>> {
return this.groupsService.updateGroup(Number(id), data);
}

@Put(':id')
@Put(':groupId')
@AuditLog('update-info')
@Scopes('group-{id}:write-info')
async replace(
@Body() data: ReplaceGroupDto,
@Param('id', ParseIntPipe) id: number,
@Param('groupId', ParseIntPipe) id: number,
): Promise<Expose<groups>> {
return this.groupsService.updateGroup(Number(id), data);
}

@Delete(':id')
@Delete(':groupId')
@AuditLog('delete')
@Scopes('group-{id}:delete')
async remove(@Param('id', ParseIntPipe) id: number): Promise<Expose<groups>> {
async remove(
@Param('groupId', ParseIntPipe) id: number,
): Promise<Expose<groups>> {
return this.groupsService.deleteGroup(Number(id));
}
}
18 changes: 10 additions & 8 deletions src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,38 @@ export class UserController {
return this.usersService.getUsers({ skip, take, orderBy, cursor, where });
}

@Get(':id')
@Get(':userId')
@Scopes('user-{id}:read-info')
async get(@Param('id', ParseIntPipe) id: number): Promise<Expose<users>> {
async get(@Param('userId', ParseIntPipe) id: number): Promise<Expose<users>> {
return this.usersService.getUser(Number(id));
}

@Patch(':id')
@Patch(':userId')
@Scopes('user-{id}:write-info')
async update(
@Param('id', ParseIntPipe) id: number,
@Param('userId', ParseIntPipe) id: number,
@Body() data: UpdateUserDto,
): Promise<Expose<users>> {
return this.usersService.updateUser(Number(id), data);
}

@Delete(':id')
@Delete(':userId')
@Scopes('user-{id}:deactivate')
async remove(@Param('id', ParseIntPipe) id: number): Promise<Expose<users>> {
async remove(
@Param('userId', ParseIntPipe) id: number,
): Promise<Expose<users>> {
return this.usersService.deactivateUser(Number(id));
}

@Post(':id/merge-request')
@Post(':userId/merge-request')
@Scopes('user-{id}:merge')
@RateLimit({
points: 10,
duration: 60,
errorMessage: 'Wait for 60 seconds before trying to merge again',
})
async mergeRequest(
@Param('id', ParseIntPipe) id: number,
@Param('userId', ParseIntPipe) id: number,
@Body('email') email: string,
): Promise<void> {
return this.usersService.requestMerge(Number(id), email);
Expand Down

0 comments on commit 5abcc56

Please sign in to comment.