From 2ffe18188633b8ae779ab21f09ce858b1a205080 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:18:23 -0300 Subject: [PATCH 01/13] refactor: comments controller improve --- .../controller/comments.controller.ts | 83 +++++++++++-------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/comments/controller/comments.controller.ts b/src/comments/controller/comments.controller.ts index 177718d..d3fc69f 100644 --- a/src/comments/controller/comments.controller.ts +++ b/src/comments/controller/comments.controller.ts @@ -7,7 +7,7 @@ import { Post, Put, Res, - Req, + HttpStatus, } from '@nestjs/common'; import { @@ -25,95 +25,106 @@ import { i18n } from 'src/i18n'; @ApiTags('Comments') @Controller('comments') export class CommentsController { - constructor(private commentsServices: CommentsService) {} + constructor(private commentsServices: CommentsService) { } - @ApiResponse({ status: 200, description: i18n()['message.comment.get'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.comment.get'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request ', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Get('/:id') async getCommentById( @Param('id') id: string, @Res() res: Response, - @Req() req, ) { - const user = req.user; - - console.log(user); - const commentFound = await this.commentsServices.findCommentById(id); - - return res.status(200).json({ + const comment = await this.commentsServices.findCommentById(id); + return res.status(HttpStatus.OK).json({ message: i18n()['message.comment.get'], - comment: commentFound, + data: { comment }, }); } - @ApiResponse({ status: 201, description: i18n()['message.comment.created'] }) + @ApiResponse({ + status: HttpStatus.CREATED, + description: i18n()['message.comment.created'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('') - async create(@Body() commentDTO: CommentDTO, @Res() res: Response) { - const commentCreated = + @Post() + async create( + @Body() commentDTO: CommentDTO, + @Res() res: Response + ) { + const comment = await this.commentsServices.createComment(commentDTO); - return res.status(201).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.comment.created'], - comment: commentCreated, + data: { comment }, }); } - @ApiResponse({ status: 200, description: i18n()['message.comment.update'] }) + @ApiResponse({ + status: HttpStatus.CREATED, + description: i18n()['message.comment.update'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : user or post or question does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateComment( @Param('id') id: string, @Body() commentDTO: CommentDTO, @Res() res: Response, ) { - const updated = await this.commentsServices.findByIdAndUpdateComment( + const comment = await this.commentsServices.findByIdAndUpdateComment( id, commentDTO, ); - return res.status(200).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.comment.update'], - comment: updated, + data: { comment }, }); } - @ApiResponse({ status: 200, description: i18n()['message.comment.deleted'] }) + @ApiResponse({ + status: HttpStatus.NO_CONTENT, + description: i18n()['message.comment.deleted'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : comment does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') - async deleteComment(@Param('id') id: string, @Res() res: Response) { + @Delete(':id') + async deleteComment( + @Param('id') id: string, + @Res() res: Response + ) { await this.commentsServices.findByIdAndDeleteComment(id); - return res.status(200).json({ - message: i18n()['message.comment.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT); } } From 15e911ebbe229127dce2ac49d02db85acbcef193 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:22:37 -0300 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20decisions=20controllers=20ref?= =?UTF-8?q?actor=C3=B0]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/comments.controller.ts | 25 +++---- .../controller/decisions.controller.ts | 68 ++++++++++--------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/comments/controller/comments.controller.ts b/src/comments/controller/comments.controller.ts index d3fc69f..70bb0a0 100644 --- a/src/comments/controller/comments.controller.ts +++ b/src/comments/controller/comments.controller.ts @@ -29,7 +29,7 @@ export class CommentsController { @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.comment.get'] + description: i18n()['message.comment.get'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -39,10 +39,10 @@ export class CommentsController { status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') + @Get(':id') async getCommentById( @Param('id') id: string, - @Res() res: Response, + @Res() res: Response ) { const comment = await this.commentsServices.findCommentById(id); return res.status(HttpStatus.OK).json({ @@ -53,7 +53,7 @@ export class CommentsController { @ApiResponse({ status: HttpStatus.CREATED, - description: i18n()['message.comment.created'] + description: i18n()['message.comment.created'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -64,12 +64,8 @@ export class CommentsController { description: 'Internal server error', }) @Post() - async create( - @Body() commentDTO: CommentDTO, - @Res() res: Response - ) { - const comment = - await this.commentsServices.createComment(commentDTO); + async create(@Body() commentDTO: CommentDTO, @Res() res: Response) { + const comment = await this.commentsServices.createComment(commentDTO); return res.status(HttpStatus.CREATED).json({ message: i18n()['message.comment.created'], @@ -79,7 +75,7 @@ export class CommentsController { @ApiResponse({ status: HttpStatus.CREATED, - description: i18n()['message.comment.update'] + description: i18n()['message.comment.update'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -108,7 +104,7 @@ export class CommentsController { @ApiResponse({ status: HttpStatus.NO_CONTENT, - description: i18n()['message.comment.deleted'] + description: i18n()['message.comment.deleted'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -119,10 +115,7 @@ export class CommentsController { description: 'Internal server error', }) @Delete(':id') - async deleteComment( - @Param('id') id: string, - @Res() res: Response - ) { + async deleteComment(@Param('id') id: string, @Res() res: Response) { await this.commentsServices.findByIdAndDeleteComment(id); return res.status(HttpStatus.NO_CONTENT); diff --git a/src/decisions/controller/decisions.controller.ts b/src/decisions/controller/decisions.controller.ts index 36d3ead..db46f59 100644 --- a/src/decisions/controller/decisions.controller.ts +++ b/src/decisions/controller/decisions.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -22,18 +23,18 @@ import { i18n } from 'src/i18n'; @ApiTags('Decisions') @Controller('decisions') export class DecisionsController { - constructor(private decisionService: DecisionsService) {} + constructor(private decisionService: DecisionsService) { } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.decisions.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Post() @@ -41,83 +42,86 @@ export class DecisionsController { @Body() createDecision: DecisionDTO, @Res() res: Response, ) { - const desicion = await this.decisionService.create(createDecision); + const decision = await this.decisionService.create(createDecision); - return res.status(201).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.decisions.created'], - desicion, + data: { decision }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.decisions.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async findDecisionById(@Param('id') id: string, @Res() res: Response) { + @Get(':id') + async findDecisionById( + @Param('id') id: string, + @Res() res: Response + ) { const decision = await this.decisionService.findDecisionById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.decisions.get'], decision, }); } @ApiResponse({ - status: 200, - description: i18n()['message.decisions.deleted'], + status: HttpStatus.NO_CONTENT, + description: i18n()['message.decisions.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') - async findByIdAndDelete(@Param('id') id: string, @Res() res: Response) { + @Delete(':id') + async findByIdAndDelete( + @Param('id') id: string, + @Res() res: Response + ) { await this.decisionService.findDecisionByIdAndDelete(id); - - return res.status(200).json({ - message: i18n()['message.decisions.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.decisions.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async findDecisionByIdAndUpdate( @Param('id') id: string, - @Body() decision: DecisionDTO, + @Body() decisionDTO: DecisionDTO, @Res() res: Response, ) { - const updateDecision = await this.decisionService.findDecisionByIdAndUpdate( + const decision = await this.decisionService.findDecisionByIdAndUpdate( id, - decision, + decisionDTO, ); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.decisions.update'], - decision: updateDecision, + data: { decision } }); } } From d305c60b85e378cbb54bf86c87a94203d8e38447 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:25:15 -0300 Subject: [PATCH 03/13] refactor: follow project controller improve --- .../controller/comments.controller.ts | 7 +-- .../controller/decisions.controller.ts | 16 +++---- .../controller/follow-project.controller.ts | 43 +++++++++---------- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/comments/controller/comments.controller.ts b/src/comments/controller/comments.controller.ts index 70bb0a0..6210dfb 100644 --- a/src/comments/controller/comments.controller.ts +++ b/src/comments/controller/comments.controller.ts @@ -25,7 +25,7 @@ import { i18n } from 'src/i18n'; @ApiTags('Comments') @Controller('comments') export class CommentsController { - constructor(private commentsServices: CommentsService) { } + constructor(private commentsServices: CommentsService) {} @ApiResponse({ status: HttpStatus.OK, @@ -40,10 +40,7 @@ export class CommentsController { description: 'Internal server error', }) @Get(':id') - async getCommentById( - @Param('id') id: string, - @Res() res: Response - ) { + async getCommentById(@Param('id') id: string, @Res() res: Response) { const comment = await this.commentsServices.findCommentById(id); return res.status(HttpStatus.OK).json({ message: i18n()['message.comment.get'], diff --git a/src/decisions/controller/decisions.controller.ts b/src/decisions/controller/decisions.controller.ts index db46f59..ec250b9 100644 --- a/src/decisions/controller/decisions.controller.ts +++ b/src/decisions/controller/decisions.controller.ts @@ -23,7 +23,7 @@ import { i18n } from 'src/i18n'; @ApiTags('Decisions') @Controller('decisions') export class DecisionsController { - constructor(private decisionService: DecisionsService) { } + constructor(private decisionService: DecisionsService) {} @ApiResponse({ status: HttpStatus.CREATED, @@ -63,10 +63,7 @@ export class DecisionsController { description: 'Internal server error', }) @Get(':id') - async findDecisionById( - @Param('id') id: string, - @Res() res: Response - ) { + async findDecisionById(@Param('id') id: string, @Res() res: Response) { const decision = await this.decisionService.findDecisionById(id); return res.status(HttpStatus.OK).json({ @@ -88,12 +85,9 @@ export class DecisionsController { description: 'Internal server error', }) @Delete(':id') - async findByIdAndDelete( - @Param('id') id: string, - @Res() res: Response - ) { + async findByIdAndDelete(@Param('id') id: string, @Res() res: Response) { await this.decisionService.findDecisionByIdAndDelete(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } @ApiResponse({ @@ -121,7 +115,7 @@ export class DecisionsController { return res.status(HttpStatus.OK).json({ message: i18n()['message.decisions.update'], - data: { decision } + data: { decision }, }); } } diff --git a/src/follow-project/controller/follow-project.controller.ts b/src/follow-project/controller/follow-project.controller.ts index ff0fac5..46300f0 100644 --- a/src/follow-project/controller/follow-project.controller.ts +++ b/src/follow-project/controller/follow-project.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Res, @@ -20,21 +21,21 @@ import { i18n } from 'src/i18n'; @ApiTags('Follow-project') @Controller('follow-project') export class FollowProjectController { - constructor(private followProjectService: FollowProjectService) {} + constructor(private followProjectService: FollowProjectService) { } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.followProject.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('/:projectId/follow') + @Post(':projectId/follow') async followProject( @Body() data: any, @Res() res: Response, @@ -45,54 +46,52 @@ export class FollowProjectController { data.userId, ); - return res.status(200).json({ - msg: i18n()['message.followProject.created'], - follow, + return res.status(HttpStatus.OK).json({ + message: i18n()['message.followProject.created'], + data: { follow }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.followProject.all'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:projectId/all-followers') + @Get(':projectId/followers') async allFollowers( @Res() res: Response, @Param('projectId') projectId: string, ) { - const all = + const followers = await this.followProjectService.getProjectsUserFollow(projectId); - return res.status(200).json({ - msg: i18n()['message.followProject.all'], - all, + return res.status(HttpStatus.OK).json({ + message: i18n()['message.followProject.all'], + data: { followers }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.NO_CONTENT, description: i18n()['message.followProject.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Delete('/:id/stop') async stopFollowProject(@Res() res: Response, @Param('id') id: string) { await this.followProjectService.stopFollowProject(id); - return res.status(200).json({ - msg: i18n()['message.followProject.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } } From b135e038655fbcf5feb9e1bd50ae1185be9d8673 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:28:43 -0300 Subject: [PATCH 04/13] refactor: goal controller improve --- .../controller/follow-project.controller.ts | 4 +- src/goals/controller/goals.controller.ts | 84 +++++++++++-------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/follow-project/controller/follow-project.controller.ts b/src/follow-project/controller/follow-project.controller.ts index 46300f0..29bb24a 100644 --- a/src/follow-project/controller/follow-project.controller.ts +++ b/src/follow-project/controller/follow-project.controller.ts @@ -21,7 +21,7 @@ import { i18n } from 'src/i18n'; @ApiTags('Follow-project') @Controller('follow-project') export class FollowProjectController { - constructor(private followProjectService: FollowProjectService) { } + constructor(private followProjectService: FollowProjectService) {} @ApiResponse({ status: HttpStatus.OK, @@ -92,6 +92,6 @@ export class FollowProjectController { @Delete('/:id/stop') async stopFollowProject(@Res() res: Response, @Param('id') id: string) { await this.followProjectService.stopFollowProject(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/goals/controller/goals.controller.ts b/src/goals/controller/goals.controller.ts index 006ec6a..975bc54 100644 --- a/src/goals/controller/goals.controller.ts +++ b/src/goals/controller/goals.controller.ts @@ -7,6 +7,7 @@ import { Res, Post, Put, + HttpStatus, } from '@nestjs/common'; import { GoalsService } from 'src/goals/services/goals.service'; import { Response } from 'express'; @@ -22,84 +23,99 @@ import { i18n } from 'src/i18n'; @ApiTags('Goals') @Controller('goals') export class GoalsController { - constructor(private goalsService: GoalsService) {} + constructor(private goalsService: GoalsService) { } - @ApiResponse({ status: 200, description: i18n()['message.goals.get'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.goals.get'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Get('/:id') - async getGoalById(@Param('id') id: string, @Body() res: Response) { + async getGoalById( + @Param('id') id: string, + @Body() res: Response + ) { const goal = await this.goalsService.findGoalById(id); - - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.goals.get'], - goal, + data: { goal }, }); } - @ApiResponse({ status: 201, description: i18n()['message.goals.created'] }) + @ApiResponse({ + status: HttpStatus.CREATED, + description: i18n()['message.goals.created'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('') - async createGoal(@Body() goals: GoalDTO, @Res() res: Response) { - const create = await this.goalsService.createGoal(goals); - - return res.status(200).json({ + @Post() + async createGoal( + @Body() goals: GoalDTO, + @Res() res: Response + ) { + const goal = await this.goalsService.createGoal(goals); + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.goals.created'], - create, + data: { goal }, }); } - @ApiResponse({ status: 200, description: i18n()['message.goals.update'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.goals.update'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateGoal( @Param('id') id: string, @Body() goals: GoalDTO, @Res() res: Response, ) { - const update = await this.goalsService.findGoalByIdAndUpdate(id, goals); - - return res.status(200).json({ + const goal = await this.goalsService.findGoalByIdAndUpdate(id, goals); + return res.status(HttpStatus.OK).json({ message: i18n()['message.goals.update'], - update, + data: { goal }, }); } - @ApiResponse({ status: 200, description: i18n()['message.goals.deleted'] }) + @ApiResponse({ + status: HttpStatus.NO_CONTENT, + description: i18n()['message.goals.deleted'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') - async deleteGoal(@Param('id') id: string, @Res() res: Response) { + @Delete(':id') + async deleteGoal( + @Param('id') id: string, + @Res() res: Response + ) { await this.goalsService.findGoalByIdAndDelete(id); - - return res.status(200).json({ - message: i18n()['message.goals.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } } From 8c82b2d137fc730500a423f455b93ef2faf16ffb Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:31:02 -0300 Subject: [PATCH 05/13] refactor: profile controller improve --- src/goals/controller/goals.controller.ts | 27 ++++------- src/profile/controller/profile.controller.ts | 50 +++++++++++--------- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/goals/controller/goals.controller.ts b/src/goals/controller/goals.controller.ts index 975bc54..301ff4a 100644 --- a/src/goals/controller/goals.controller.ts +++ b/src/goals/controller/goals.controller.ts @@ -23,11 +23,11 @@ import { i18n } from 'src/i18n'; @ApiTags('Goals') @Controller('goals') export class GoalsController { - constructor(private goalsService: GoalsService) { } + constructor(private goalsService: GoalsService) {} @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.goals.get'] + description: i18n()['message.goals.get'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -38,10 +38,7 @@ export class GoalsController { description: 'Internal server error', }) @Get('/:id') - async getGoalById( - @Param('id') id: string, - @Body() res: Response - ) { + async getGoalById(@Param('id') id: string, @Body() res: Response) { const goal = await this.goalsService.findGoalById(id); return res.status(HttpStatus.OK).json({ message: i18n()['message.goals.get'], @@ -51,7 +48,7 @@ export class GoalsController { @ApiResponse({ status: HttpStatus.CREATED, - description: i18n()['message.goals.created'] + description: i18n()['message.goals.created'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -62,10 +59,7 @@ export class GoalsController { description: 'Internal server error', }) @Post() - async createGoal( - @Body() goals: GoalDTO, - @Res() res: Response - ) { + async createGoal(@Body() goals: GoalDTO, @Res() res: Response) { const goal = await this.goalsService.createGoal(goals); return res.status(HttpStatus.CREATED).json({ message: i18n()['message.goals.created'], @@ -75,7 +69,7 @@ export class GoalsController { @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.goals.update'] + description: i18n()['message.goals.update'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -100,7 +94,7 @@ export class GoalsController { @ApiResponse({ status: HttpStatus.NO_CONTENT, - description: i18n()['message.goals.deleted'] + description: i18n()['message.goals.deleted'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -111,11 +105,8 @@ export class GoalsController { description: 'Internal server error', }) @Delete(':id') - async deleteGoal( - @Param('id') id: string, - @Res() res: Response - ) { + async deleteGoal(@Param('id') id: string, @Res() res: Response) { await this.goalsService.findGoalByIdAndDelete(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/profile/controller/profile.controller.ts b/src/profile/controller/profile.controller.ts index e7466b5..e7700f5 100644 --- a/src/profile/controller/profile.controller.ts +++ b/src/profile/controller/profile.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Post, Put, Res } from '@nestjs/common'; +import { Body, Controller, Get, HttpStatus, Param, Post, Put, Res } from '@nestjs/common'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, @@ -13,37 +13,43 @@ import { ProfileService } from 'src/profile/services/profile.service'; @ApiTags('Profile') @Controller('profile') export class ProfileController { - constructor(private profileService: ProfileService) {} + constructor(private profileService: ProfileService) { } - @ApiResponse({ status: 200, description: i18n()['message.profile.get'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.profile.get'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async getProfile(@Param('id') profile_id: string, @Res() res: Response) { + @Get(':id') + async getProfile( + @Param('id') profile_id: string, + @Res() res: Response + ) { const profile = await this.profileService.findProfileById(profile_id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.profile.get'], - profile, + data: { profile }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.profile.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Post() @@ -51,40 +57,40 @@ export class ProfileController { @Body() createProfileDTO: CreateProfileDTO, @Res() res: Response, ) { - const createProfile = + const profile = await this.profileService.createProfile(createProfileDTO); - return res.status(201).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.profile.created'], - profile: createProfile, + data: { profile }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.profile.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async upateProfile( @Param('id') profile_id: string, @Body() updateProfile: CreateProfileDTO, @Res() res: Response, ) { - const update = await this.profileService.findProfileByIdAndUpdate( + const profile = await this.profileService.findProfileByIdAndUpdate( profile_id, updateProfile, ); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.profile.update'], - update, + data: { profile }, }); } } From 286e02960467002ab72d009f4f043a7724561c45 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:34:04 -0300 Subject: [PATCH 06/13] refactor: project idea controller improve --- src/profile/controller/profile.controller.ts | 23 +++--- .../controllers/project-idea.controller.ts | 77 ++++++++++--------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/src/profile/controller/profile.controller.ts b/src/profile/controller/profile.controller.ts index e7700f5..05f1863 100644 --- a/src/profile/controller/profile.controller.ts +++ b/src/profile/controller/profile.controller.ts @@ -1,4 +1,13 @@ -import { Body, Controller, Get, HttpStatus, Param, Post, Put, Res } from '@nestjs/common'; +import { + Body, + Controller, + Get, + HttpStatus, + Param, + Post, + Put, + Res, +} from '@nestjs/common'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, @@ -13,11 +22,11 @@ import { ProfileService } from 'src/profile/services/profile.service'; @ApiTags('Profile') @Controller('profile') export class ProfileController { - constructor(private profileService: ProfileService) { } + constructor(private profileService: ProfileService) {} @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.profile.get'] + description: i18n()['message.profile.get'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -28,10 +37,7 @@ export class ProfileController { description: 'Internal server error', }) @Get(':id') - async getProfile( - @Param('id') profile_id: string, - @Res() res: Response - ) { + async getProfile(@Param('id') profile_id: string, @Res() res: Response) { const profile = await this.profileService.findProfileById(profile_id); return res.status(HttpStatus.OK).json({ @@ -57,8 +63,7 @@ export class ProfileController { @Body() createProfileDTO: CreateProfileDTO, @Res() res: Response, ) { - const profile = - await this.profileService.createProfile(createProfileDTO); + const profile = await this.profileService.createProfile(createProfileDTO); return res.status(HttpStatus.CREATED).json({ message: i18n()['message.profile.created'], diff --git a/src/project-idea/controllers/project-idea.controller.ts b/src/project-idea/controllers/project-idea.controller.ts index a4ceda9..bf552a3 100644 --- a/src/project-idea/controllers/project-idea.controller.ts +++ b/src/project-idea/controllers/project-idea.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -22,63 +23,69 @@ import { i18n } from 'src/i18n'; @ApiTags('Project-idea') @Controller('projectIdea') export class ProjectIdeaController { - constructor(private projectIdeaService: ProjectIdeaService) {} + constructor(private projectIdeaService: ProjectIdeaService) { } - @ApiResponse({ status: 200, description: i18n()['message.projectIdea.get'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.projectIdea.get'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async getProjectIdeaById(@Param('id') id: string, @Res() res: Response) { + @Get(':id') + async getProjectIdeaById( + @Param('id') id: string, + @Res() res: Response + ) { const projectIdea = await this.projectIdeaService.findProjectIdeaById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.projectIdea.get'], - projectIdea, + data: { projectIdea }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.projectIdea.userId'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:userId/all') + @Get(':id/all') async getAllProjectIdea( - @Param('userId') userId: string, + @Param('id') userId: string, @Res() res: Response, ) { - const allProjectsIdeas = + const projectsIdeas = await this.projectIdeaService.findAllProjectIdeas(userId); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.projectIdea.userId'], - allProjectsIdeas, + data: { projectsIdeas }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.projectIdea.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Post() @@ -86,62 +93,60 @@ export class ProjectIdeaController { @Body() createProjectIdea: CreateProjectIdeaDTO, @Res() res: Response, ) { - const createIdea = + const idea = await this.projectIdeaService.createProjectIdea(createProjectIdea); - return res.status(201).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.projectIdea.created'], - projectIdea: createIdea, + data: { idea }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.projectIdea.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateProjectIdea( @Param('id') id: string, @Body() updateProjectIdea: CreateProjectIdeaDTO, @Res() res: Response, ) { - const updateIdea = await this.projectIdeaService.updateProjectIdea( + const idea = await this.projectIdeaService.updateProjectIdea( id, updateProjectIdea, ); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.projectIdea.update'], - update: updateIdea, + data: { idea }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.NO_CONTENT, description: i18n()['message.projectIdea.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') + @Delete(':id') async deleteProjectIdea(@Param('id') id: string, @Res() res: Response) { await this.projectIdeaService.DeleteProjectIdea(id); - return res.status(200).json({ - message: i18n()['message.projectIdea.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } } From cf5e4e699c6b6948233170c17034601df54b9cfe Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:37:06 -0300 Subject: [PATCH 07/13] refactor: projects controllers improve --- .../controllers/project-idea.controller.ts | 16 +-- .../controller/projects.controller.ts | 98 +++++++++++-------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/src/project-idea/controllers/project-idea.controller.ts b/src/project-idea/controllers/project-idea.controller.ts index bf552a3..00e3f5e 100644 --- a/src/project-idea/controllers/project-idea.controller.ts +++ b/src/project-idea/controllers/project-idea.controller.ts @@ -23,11 +23,11 @@ import { i18n } from 'src/i18n'; @ApiTags('Project-idea') @Controller('projectIdea') export class ProjectIdeaController { - constructor(private projectIdeaService: ProjectIdeaService) { } + constructor(private projectIdeaService: ProjectIdeaService) {} @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.projectIdea.get'] + description: i18n()['message.projectIdea.get'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -38,10 +38,7 @@ export class ProjectIdeaController { description: 'Internal server error', }) @Get(':id') - async getProjectIdeaById( - @Param('id') id: string, - @Res() res: Response - ) { + async getProjectIdeaById(@Param('id') id: string, @Res() res: Response) { const projectIdea = await this.projectIdeaService.findProjectIdeaById(id); return res.status(HttpStatus.OK).json({ @@ -63,10 +60,7 @@ export class ProjectIdeaController { description: 'Internal server error', }) @Get(':id/all') - async getAllProjectIdea( - @Param('id') userId: string, - @Res() res: Response, - ) { + async getAllProjectIdea(@Param('id') userId: string, @Res() res: Response) { const projectsIdeas = await this.projectIdeaService.findAllProjectIdeas(userId); @@ -147,6 +141,6 @@ export class ProjectIdeaController { async deleteProjectIdea(@Param('id') id: string, @Res() res: Response) { await this.projectIdeaService.DeleteProjectIdea(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/projects/controller/projects.controller.ts b/src/projects/controller/projects.controller.ts index 91cfd5f..d1723d6 100644 --- a/src/projects/controller/projects.controller.ts +++ b/src/projects/controller/projects.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -21,126 +22,137 @@ import { i18n } from 'src/i18n'; import { ProjectsService } from '../services/projects.service'; @ApiTags('Projects') -@Controller('/projects') +@Controller('projects') export class ProjectsController { - constructor(private projectsServices: ProjectsService) {} + constructor(private projectsServices: ProjectsService) { } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.project.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('') - async create(@Body() dataProjects: ProjectDto, @Res() res: Response) { - const createProject = await this.projectsServices.create(dataProjects); - return res.status(201).json({ - msg: i18n()['message.project.created'], - project: createProject, + @Post() + async create( + @Body() dataProjects: + ProjectDto, @Res() + res: Response + ) { + const project = await this.projectsServices.create(dataProjects); + return res.status(HttpStatus.CREATED).json({ + message: i18n()['message.project.created'], + data: { project }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.project.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Reques', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async findProjectById(@Param('id') id: string, @Res() res: Response) { + @Get(':id') + async findProjectById( + @Param('id') id: string, + @Res() res: Response + ) { const project = await this.projectsServices.findById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.project.get'], - project, + data: { project }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.project.userId'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/all/:userId') - async findAllProjects(@Param('userId') userId: string, @Res() res: Response) { + @Get('all/:userId') + async findAllProjects( + @Param('userId') userId: string, + @Res() res: Response + ) { const allProjectsUsers = await this.projectsServices.findAllProjectsUser(userId); - return res.status(200).json({ - msg: i18n()['message.project.userId'], - projects: allProjectsUsers, + return res.status(HttpStatus.OK).json({ + message: i18n()['message.project.userId'], + data: { allProjectsUsers }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.project.priority'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/filter') + @Get('filter') async findProjectByPriority( @Query('priority') priority: string, @Res() res: Response, ) { - await this.projectsServices.findProjectsByPriority(priority); - return res.status(200).json({ - msg: i18n()['message.project.priority'], + const project = await this.projectsServices.findProjectsByPriority(priority); + return res.status(HttpStatus.OK).json({ + message: i18n()['message.project.priority'], + data: { project } }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: 'Project has been deleted successfully', }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Delete('/:id') async deleteProjectById(@Param('id') id: string, @Res() res: Response) { await this.projectsServices.deleteProjectById(id); - return res.status(200).json({ - msg: i18n()['message.project.deleted'], + return res.status(HttpStatus.OK).json({ + message: i18n()['message.project.deleted'], }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.project.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Put('/:id') @@ -153,8 +165,8 @@ export class ProjectsController { id, dataProject, ); - return res.status(200).json({ - msg: i18n()['message.project.update'], + return res.status(HttpStatus.OK).json({ + message: i18n()['message.project.update'], project, }); } From 6fcd6ecde2d8618cb813c03338496d32bf6e9f64 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:39:49 -0300 Subject: [PATCH 08/13] refactor: quesions controllers improve --- .../controller/projects.controller.ts | 27 +++----- .../controller/questions.controller.ts | 67 ++++++++++--------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/projects/controller/projects.controller.ts b/src/projects/controller/projects.controller.ts index d1723d6..55325b7 100644 --- a/src/projects/controller/projects.controller.ts +++ b/src/projects/controller/projects.controller.ts @@ -24,7 +24,7 @@ import { ProjectsService } from '../services/projects.service'; @ApiTags('Projects') @Controller('projects') export class ProjectsController { - constructor(private projectsServices: ProjectsService) { } + constructor(private projectsServices: ProjectsService) {} @ApiResponse({ status: HttpStatus.CREATED, @@ -40,9 +40,9 @@ export class ProjectsController { }) @Post() async create( - @Body() dataProjects: - ProjectDto, @Res() - res: Response + @Body() dataProjects: ProjectDto, + @Res() + res: Response, ) { const project = await this.projectsServices.create(dataProjects); return res.status(HttpStatus.CREATED).json({ @@ -64,10 +64,7 @@ export class ProjectsController { description: 'Internal server error', }) @Get(':id') - async findProjectById( - @Param('id') id: string, - @Res() res: Response - ) { + async findProjectById(@Param('id') id: string, @Res() res: Response) { const project = await this.projectsServices.findById(id); return res.status(HttpStatus.OK).json({ message: i18n()['message.project.get'], @@ -88,10 +85,7 @@ export class ProjectsController { description: 'Internal server error', }) @Get('all/:userId') - async findAllProjects( - @Param('userId') userId: string, - @Res() res: Response - ) { + async findAllProjects(@Param('userId') userId: string, @Res() res: Response) { const allProjectsUsers = await this.projectsServices.findAllProjectsUser(userId); return res.status(HttpStatus.OK).json({ @@ -117,10 +111,11 @@ export class ProjectsController { @Query('priority') priority: string, @Res() res: Response, ) { - const project = await this.projectsServices.findProjectsByPriority(priority); + const project = + await this.projectsServices.findProjectsByPriority(priority); return res.status(HttpStatus.OK).json({ message: i18n()['message.project.priority'], - data: { project } + data: { project }, }); } @ApiResponse({ @@ -155,7 +150,7 @@ export class ProjectsController { status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateProjectById( @Param('id') id: string, @Body() dataProject: ProjectDto, @@ -167,7 +162,7 @@ export class ProjectsController { ); return res.status(HttpStatus.OK).json({ message: i18n()['message.project.update'], - project, + data: { project } , }); } } diff --git a/src/questions/controller/questions.controller.ts b/src/questions/controller/questions.controller.ts index 67c9a22..e7cb941 100644 --- a/src/questions/controller/questions.controller.ts +++ b/src/questions/controller/questions.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -23,18 +24,18 @@ import { QuestionsService } from 'src/questions/services/questions.service'; @ApiTags('Questions') @Controller('questions') export class QuestionsController { - constructor(private questionsServices: QuestionsService) {} + constructor(private questionsServices: QuestionsService) { } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.question.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Post() @@ -44,103 +45,103 @@ export class QuestionsController { ) { const question = await this.questionsServices.createQuestion(createQuestion); - return res.status(201).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.question.created'], - question, + data: { question }, }); } - @ApiResponse({ status: 200, description: i18n()['message.question.get'] }) + @ApiResponse({ + status: HttpStatus.OK, + description: i18n()['message.question.get'] + }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') + @Get(':id') async findById(@Param('id') id: string, @Res() res: Response) { const question = await this.questionsServices.findQuestionById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.question.get'], - question, + data: { question }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.question.userId'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/all/:userId') + @Get('all/:userId') async findAllQuestionsUser( @Param('userId') userId: string, @Res() res: Response, ) { const question = await this.questionsServices.allQuestionsUser(userId); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.question.userId'], - question, + data: { question }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.question.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateQuestionById( @Param('id') id: string, @Body() updateQuestion: QuestionsDTO, @Res() res: Response, ) { - const questionUpdated = + const question = await this.questionsServices.findQuestionByIdAndUpdate( id, updateQuestion, ); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.question.update'], - question: questionUpdated, + data: { question }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.NO_CONTENT, description: i18n()['message.question.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : project does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') + @Delete(':id') async deleteQuestionById(@Param('id') id: string, @Res() res: Response) { await this.questionsServices.findQuestionByIdAndDelete(id); - - return res.status(200).json({ - message: i18n()['message.question.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } } From 2fd1ed5f513875305b096a8b2d2c69e3c012d97d Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:41:07 -0300 Subject: [PATCH 09/13] refactor: send email controler improve --- src/projects/controller/projects.controller.ts | 2 +- .../controller/questions.controller.ts | 15 +++++++-------- src/send-email/controller/email.controller.ts | 18 +++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/projects/controller/projects.controller.ts b/src/projects/controller/projects.controller.ts index 55325b7..1e4f778 100644 --- a/src/projects/controller/projects.controller.ts +++ b/src/projects/controller/projects.controller.ts @@ -162,7 +162,7 @@ export class ProjectsController { ); return res.status(HttpStatus.OK).json({ message: i18n()['message.project.update'], - data: { project } , + data: { project }, }); } } diff --git a/src/questions/controller/questions.controller.ts b/src/questions/controller/questions.controller.ts index e7cb941..c41518c 100644 --- a/src/questions/controller/questions.controller.ts +++ b/src/questions/controller/questions.controller.ts @@ -24,7 +24,7 @@ import { QuestionsService } from 'src/questions/services/questions.service'; @ApiTags('Questions') @Controller('questions') export class QuestionsController { - constructor(private questionsServices: QuestionsService) { } + constructor(private questionsServices: QuestionsService) {} @ApiResponse({ status: HttpStatus.CREATED, @@ -53,7 +53,7 @@ export class QuestionsController { @ApiResponse({ status: HttpStatus.OK, - description: i18n()['message.question.get'] + description: i18n()['message.question.get'], }) @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST, @@ -116,11 +116,10 @@ export class QuestionsController { @Body() updateQuestion: QuestionsDTO, @Res() res: Response, ) { - const question = - await this.questionsServices.findQuestionByIdAndUpdate( - id, - updateQuestion, - ); + const question = await this.questionsServices.findQuestionByIdAndUpdate( + id, + updateQuestion, + ); return res.status(HttpStatus.OK).json({ message: i18n()['message.question.update'], data: { question }, @@ -142,6 +141,6 @@ export class QuestionsController { @Delete(':id') async deleteQuestionById(@Param('id') id: string, @Res() res: Response) { await this.questionsServices.findQuestionByIdAndDelete(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/send-email/controller/email.controller.ts b/src/send-email/controller/email.controller.ts index 6bd89a8..11be2c9 100644 --- a/src/send-email/controller/email.controller.ts +++ b/src/send-email/controller/email.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Headers, Post, Res } from '@nestjs/common'; +import { Controller, Headers, HttpStatus, Post, Res } from '@nestjs/common'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, @@ -14,18 +14,18 @@ export class EmailController { constructor(private sendEmailConfimation: SendEmailService) {} @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: 'Confirmed email', }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : Token expired or invalid token', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('/confirm') + @Post('confirm') async validateTokenEmail( @Headers('authorization') authorization: any, @Res() @@ -36,12 +36,12 @@ export class EmailController { const decoded = await this.sendEmailConfimation.validate(token); - return res.status(200).json({ - msg: 'Email confirmed', - token: decoded, + return res.status(HttpStatus.OK).json({ + message: 'Email confirmed', + data: { decoded }, }); } catch (error) { - return res.status(400).json({ + return res.status(HttpStatus.BAD_REQUEST).json({ error: error.message, }); } From 02030c44a1ebb6c6fd0ac0ac9f5ae4b07e80b903 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:44:17 -0300 Subject: [PATCH 10/13] refactor: task list controller improve --- .../task-list-project.controller.ts | 70 ++++++++++--------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/task-list-project/controller/task-list-project.controller.ts b/src/task-list-project/controller/task-list-project.controller.ts index 627a603..168001c 100644 --- a/src/task-list-project/controller/task-list-project.controller.ts +++ b/src/task-list-project/controller/task-list-project.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -19,97 +20,100 @@ import { @Controller('task') export class TaskListProjectController { - constructor(private taskListService: TaskListProjectService) {} + constructor(private taskListService: TaskListProjectService) { } @ApiResponse({ - status: 201, + status: HttpStatus.OK, description: i18n()['message.taskList.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async findById(@Param('id') id: string, @Res() res: Response) { - const question = await this.taskListService.findTaskById(id); + @Get(':id') + async findById( + @Param('id') id: string, + @Res() res: Response + ) { + const taskList = await this.taskListService.findTaskById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.taskList.get'], - question, + data: { taskList }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.OK, description: i18n()['message.taskList.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('/') + @Post() async createTask(@Body() data: any, @Res() res: Response) { - const question = await this.taskListService.createTaskProject(data); + const taskList = await this.taskListService.createTaskProject(data); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.taskList.created'], - question, + data: { taskList }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.OK, description: i18n()['message.taskList.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateTask( @Param() id: string, @Body() data: any, @Res() res: Response, ) { - const question = await this.taskListService.updateTask(id, data); + const taskList = await this.taskListService.updateTask(id, data); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.taskList.update'], - question, + data: { taskList }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.NO_CONTENT, description: i18n()['message.taskList.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') - async deleteTask(@Param('id') id: string, @Res() res: Response) { - const question = await this.taskListService.deleteTask(id); + @Delete(':id') + async deleteTask( + @Param('id') id: string, + @Res() res: Response + ) { + await this.taskListService.deleteTask(id); - return res.status(200).json({ - message: i18n()['message.taskList.deleted'], - question, - }); + return res.status(HttpStatus.NO_CONTENT) } } From bb42568490a1fd9eb1c7bfcb5f25473a03b21ed5 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:47:43 -0300 Subject: [PATCH 11/13] refactor: team controller improve --- .../task-list-project.controller.ts | 14 ++----- src/team/controller/team.controller.ts | 41 ++++++++++--------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/task-list-project/controller/task-list-project.controller.ts b/src/task-list-project/controller/task-list-project.controller.ts index 168001c..8f7dbe3 100644 --- a/src/task-list-project/controller/task-list-project.controller.ts +++ b/src/task-list-project/controller/task-list-project.controller.ts @@ -20,7 +20,7 @@ import { @Controller('task') export class TaskListProjectController { - constructor(private taskListService: TaskListProjectService) { } + constructor(private taskListService: TaskListProjectService) {} @ApiResponse({ status: HttpStatus.OK, @@ -35,10 +35,7 @@ export class TaskListProjectController { description: 'Internal server error', }) @Get(':id') - async findById( - @Param('id') id: string, - @Res() res: Response - ) { + async findById(@Param('id') id: string, @Res() res: Response) { const taskList = await this.taskListService.findTaskById(id); return res.status(HttpStatus.OK).json({ @@ -108,12 +105,9 @@ export class TaskListProjectController { description: 'Internal server error', }) @Delete(':id') - async deleteTask( - @Param('id') id: string, - @Res() res: Response - ) { + async deleteTask(@Param('id') id: string, @Res() res: Response) { await this.taskListService.deleteTask(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/team/controller/team.controller.ts b/src/team/controller/team.controller.ts index 49e4d6b..acedb38 100644 --- a/src/team/controller/team.controller.ts +++ b/src/team/controller/team.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -17,47 +18,49 @@ import { TeamService } from 'src/team/services/team.service'; @ApiTags('Team') @Controller('team') export class TeamController { - constructor(private teamService: TeamService) {} + constructor(private teamService: TeamService) { } - @Get('/:id') + @Get(':id') async findById(@Param('id') id: string, @Res() res: Response) { const team = await this.teamService.findTeamById(id); - - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.team.get'], - team, + data: { team }, }); } @Post() - async create(@Body() team: TeamDTO, @Res() res: Response) { - const createTeam = await this.teamService.createTeam(team); - - return res.status(201).json({ + async create( + @Body() teamDTO: TeamDTO, + @Res() res: Response + ) { + const team = await this.teamService.createTeam(teamDTO); + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.team.created'], - team: createTeam, + data: { team }, }); } - @Delete('/:id') - async delete(@Param('id') id: string, @Res() res: Response) { + @Delete(':id') + async delete( + @Param('id') id: string, + @Res() res: Response + ) { await this.teamService.findTeamByIdAnDelete(id); - return res.status(200).json({ - message: i18n()['message.team.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } - @Put('/:id') + @Put(':id') async update( @Param() id: string, @Body() data: TeamDTO, @Res() res: Response, ) { - const updateTeam = await this.teamService.findTeamByIdAndUpdate(id, data); + const team = await this.teamService.findTeamByIdAndUpdate(id, data); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.team.update'], - updateTeam, + data: { team}, }); } } From 87176ca8e5c0a39494a2484e1a1eff939edfad45 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:49:39 -0300 Subject: [PATCH 12/13] refactor: updates controller improve --- src/team/controller/team.controller.ts | 16 ++---- src/updates/controller/updates.controller.ts | 58 ++++++++++---------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/team/controller/team.controller.ts b/src/team/controller/team.controller.ts index acedb38..37e2c1d 100644 --- a/src/team/controller/team.controller.ts +++ b/src/team/controller/team.controller.ts @@ -18,7 +18,7 @@ import { TeamService } from 'src/team/services/team.service'; @ApiTags('Team') @Controller('team') export class TeamController { - constructor(private teamService: TeamService) { } + constructor(private teamService: TeamService) {} @Get(':id') async findById(@Param('id') id: string, @Res() res: Response) { @@ -30,10 +30,7 @@ export class TeamController { } @Post() - async create( - @Body() teamDTO: TeamDTO, - @Res() res: Response - ) { + async create(@Body() teamDTO: TeamDTO, @Res() res: Response) { const team = await this.teamService.createTeam(teamDTO); return res.status(HttpStatus.CREATED).json({ message: i18n()['message.team.created'], @@ -42,12 +39,9 @@ export class TeamController { } @Delete(':id') - async delete( - @Param('id') id: string, - @Res() res: Response - ) { + async delete(@Param('id') id: string, @Res() res: Response) { await this.teamService.findTeamByIdAnDelete(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } @Put(':id') @@ -60,7 +54,7 @@ export class TeamController { return res.status(HttpStatus.OK).json({ message: i18n()['message.team.update'], - data: { team}, + data: { team }, }); } } diff --git a/src/updates/controller/updates.controller.ts b/src/updates/controller/updates.controller.ts index 4dc37b9..b5ff26c 100644 --- a/src/updates/controller/updates.controller.ts +++ b/src/updates/controller/updates.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -22,40 +23,43 @@ import { UpdatesService } from 'src/updates/services/updates.service'; @ApiTags('Updates') @Controller('updates') export class UpdatesController { - constructor(private updateService: UpdatesService) {} + constructor(private updateService: UpdatesService) { } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.updates.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : update does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async getUpdateById(@Param('id') id: string, @Res() res: Response) { - const updateFound = await this.updateService.findUpdateById(id); + @Get(':id') + async getUpdateById( + @Param('id') id: string, + @Res() res: Response + ) { + const update = await this.updateService.findUpdateById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.updates.get'], - updateFound, + data: { update }, }); } @ApiResponse({ - status: 201, + status: HttpStatus.CREATED, description: i18n()['message.updates.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) @Post() @@ -66,57 +70,55 @@ export class UpdatesController { const update = await this.updateService.createUpdateToProject(createUpdateProject); - return res.status(200).json({ + return res.status(HttpStatus.CREATED).json({ message: i18n()['message.updates.created'], - update, + data: { update }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.updates.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async update( @Param('id') id: string, @Body() updateData: UpdateDTO, @Res() res: Response, ) { - const editUpdateProject = await this.updateService.editUpdateProjectbyId( + const updates = await this.updateService.editUpdateProjectbyId( id, updateData, ); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ message: i18n()['message.updates.update'], - updated: editUpdateProject, + data: { updates }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.NO_CONTENT, description: i18n()['message.updates.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request :update does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') + @Delete(':id') async deleteUpdate(@Param('id') id: string, @Res() res: Response) { await this.updateService.findByIdAndDeleteUpdate(id); - return res.status(200).json({ - message: i18n()['message.updates.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } } From 944653d54362acbe1018002f68b367e56338a6a3 Mon Sep 17 00:00:00 2001 From: hebertsanto Date: Thu, 10 Apr 2025 20:52:35 -0300 Subject: [PATCH 13/13] refactor: user controller improve --- src/updates/controller/updates.controller.ts | 9 +-- src/user/controller/user.controller.ts | 72 +++++++++++--------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/updates/controller/updates.controller.ts b/src/updates/controller/updates.controller.ts index b5ff26c..36450f2 100644 --- a/src/updates/controller/updates.controller.ts +++ b/src/updates/controller/updates.controller.ts @@ -23,7 +23,7 @@ import { UpdatesService } from 'src/updates/services/updates.service'; @ApiTags('Updates') @Controller('updates') export class UpdatesController { - constructor(private updateService: UpdatesService) { } + constructor(private updateService: UpdatesService) {} @ApiResponse({ status: HttpStatus.OK, @@ -38,10 +38,7 @@ export class UpdatesController { description: 'Internal server error', }) @Get(':id') - async getUpdateById( - @Param('id') id: string, - @Res() res: Response - ) { + async getUpdateById(@Param('id') id: string, @Res() res: Response) { const update = await this.updateService.findUpdateById(id); return res.status(HttpStatus.OK).json({ @@ -119,6 +116,6 @@ export class UpdatesController { @Delete(':id') async deleteUpdate(@Param('id') id: string, @Res() res: Response) { await this.updateService.findByIdAndDeleteUpdate(id); - return res.status(HttpStatus.NO_CONTENT) + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/user/controller/user.controller.ts b/src/user/controller/user.controller.ts index c38c622..6f7828d 100644 --- a/src/user/controller/user.controller.ts +++ b/src/user/controller/user.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpStatus, Param, Post, Put, @@ -22,105 +23,112 @@ import { UserService } from 'src/user/services/user.service'; @ApiTags('User') @Controller('/user') export class UserController { - constructor(private readonly userService: UserService) {} + constructor(private readonly userService: UserService) { } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.user.get'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Get('/:id') - async findUserById(@Param('id') id: string, @Res() res: Response) { + @Get(':id') + async findUserById( + @Param('id') id: string, + @Res() res: Response + ) { const user = await this.userService.findUserById(id); - return res.status(200).json({ + return res.status(HttpStatus.OK).json({ msg: i18n()['message.user.get'], - user, + data: { user }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.CREATED, description: i18n()['message.user.created'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : user already exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Post('') - async createUser(@Body() createUserDto: UserDto, @Res() res: Response) { + @Post() + async createUser( + @Body() createUserDto: UserDto, + @Res() res: Response + ) { const user = await this.userService.createUser(createUserDto); - return res.json({ + return res.status(HttpStatus.CREATED).json({ msg: i18n()['message.user.created'], - user, + data: { user }, }); } @ApiResponse({ - status: 200, + status: HttpStatus.NO_CONTENT, description: i18n()['message.user.deleted'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request : user does not exist', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Delete('/:id') + @Delete(':id') async deleteUser(@Param('id') id: string, @Res() res: Response) { await this.userService.findUserByIdAndDelete(id); - return res.json({ - msg: i18n()['message.user.deleted'], - }); + return res.status(HttpStatus.NO_CONTENT) } @ApiResponse({ - status: 200, + status: HttpStatus.OK, description: i18n()['message.user.update'], }) @ApiBadRequestResponse({ - status: 400, + status: HttpStatus.BAD_REQUEST, description: 'Bad Request', }) @ApiInternalServerErrorResponse({ - status: 500, + status: HttpStatus.INTERNAL_SERVER_ERROR, description: 'Internal server error', }) - @Put('/:id') + @Put(':id') async updateUser( @Param('id') id: string, @Body() editUserDTO: UserDto, @Res() res: Response, ) { - const updateUser = await this.userService.findUserByIdAndUpdate( + const user = await this.userService.findUserByIdAndUpdate( id, editUserDTO, ); return res.json({ msg: i18n()['message.user.update'], - user: updateUser, + data: { user }, }); } @Post('/login') - async login(@Body() email: string, password: string, @Res() res: Response) { + async login( + @Body() email: string, + password: string, + @Res() res: Response + ) { const { token } = await this.userService.auth(email, password); - - return res.json({ + return res.status(HttpStatus.OK).json({ msg: i18n()['message.user.login'], - token, + data: { token }, }); } }