diff --git a/src/comments/controller/comments.controller.ts b/src/comments/controller/comments.controller.ts index 177718d..6210dfb 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 { @@ -27,93 +27,94 @@ import { i18n } from 'src/i18n'; export class CommentsController { 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({ + @Get(':id') + 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'], - 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('') + @Post() async create(@Body() commentDTO: CommentDTO, @Res() res: Response) { - const commentCreated = - await this.commentsServices.createComment(commentDTO); + 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') + @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); } } diff --git a/src/decisions/controller/decisions.controller.ts b/src/decisions/controller/decisions.controller.ts index 36d3ead..ec250b9 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, @@ -25,15 +26,15 @@ export class DecisionsController { 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,80 @@ 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') + @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') + @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 }, }); } } diff --git a/src/follow-project/controller/follow-project.controller.ts b/src/follow-project/controller/follow-project.controller.ts index ff0fac5..29bb24a 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, @@ -23,18 +24,18 @@ export class FollowProjectController { 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); } } diff --git a/src/goals/controller/goals.controller.ts b/src/goals/controller/goals.controller.ts index 006ec6a..301ff4a 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'; @@ -24,82 +25,88 @@ import { i18n } from 'src/i18n'; export class GoalsController { 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) { 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('') + @Post() async createGoal(@Body() goals: GoalDTO, @Res() res: Response) { - const create = await this.goalsService.createGoal(goals); - - return res.status(200).json({ + 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') + @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); } } diff --git a/src/profile/controller/profile.controller.ts b/src/profile/controller/profile.controller.ts index e7466b5..05f1863 100644 --- a/src/profile/controller/profile.controller.ts +++ b/src/profile/controller/profile.controller.ts @@ -1,4 +1,13 @@ -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, @@ -15,35 +24,38 @@ import { ProfileService } from 'src/profile/services/profile.service'; export class ProfileController { 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') + @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 +63,39 @@ export class ProfileController { @Body() createProfileDTO: CreateProfileDTO, @Res() res: Response, ) { - const createProfile = - await this.profileService.createProfile(createProfileDTO); + 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 }, }); } } diff --git a/src/project-idea/controllers/project-idea.controller.ts b/src/project-idea/controllers/project-idea.controller.ts index a4ceda9..00e3f5e 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, @@ -24,61 +25,61 @@ import { i18n } from 'src/i18n'; export class ProjectIdeaController { 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') + @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') - async getAllProjectIdea( - @Param('userId') userId: string, - @Res() res: Response, - ) { - const allProjectsIdeas = + @Get(':id/all') + async getAllProjectIdea(@Param('id') userId: string, @Res() res: Response) { + 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 +87,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); } } diff --git a/src/projects/controller/projects.controller.ts b/src/projects/controller/projects.controller.ts index 91cfd5f..1e4f778 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,129 +22,135 @@ import { i18n } from 'src/i18n'; import { ProjectsService } from '../services/projects.service'; @ApiTags('Projects') -@Controller('/projects') +@Controller('projects') export class ProjectsController { 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') + @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') + @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') + @Put(':id') async updateProjectById( @Param('id') id: string, @Body() dataProject: ProjectDto, @@ -153,9 +160,9 @@ export class ProjectsController { id, dataProject, ); - return res.status(200).json({ - msg: i18n()['message.project.update'], - project, + return res.status(HttpStatus.OK).json({ + message: i18n()['message.project.update'], + data: { project }, }); } } diff --git a/src/questions/controller/questions.controller.ts b/src/questions/controller/questions.controller.ts index 67c9a22..c41518c 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, @@ -26,15 +27,15 @@ export class QuestionsController { 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,102 @@ 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 = - await this.questionsServices.findQuestionByIdAndUpdate( - id, - updateQuestion, - ); - return res.status(200).json({ + const question = await this.questionsServices.findQuestionByIdAndUpdate( + id, + updateQuestion, + ); + 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); } } 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, }); } 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..8f7dbe3 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, @@ -22,94 +23,91 @@ export class TaskListProjectController { 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') + @Get(':id') async findById(@Param('id') id: string, @Res() res: Response) { - const question = await this.taskListService.findTaskById(id); + 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') + @Delete(':id') async deleteTask(@Param('id') id: string, @Res() res: Response) { - const question = await this.taskListService.deleteTask(id); + await this.taskListService.deleteTask(id); - return res.status(200).json({ - message: i18n()['message.taskList.deleted'], - question, - }); + return res.status(HttpStatus.NO_CONTENT); } } diff --git a/src/team/controller/team.controller.ts b/src/team/controller/team.controller.ts index 49e4d6b..37e2c1d 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, @@ -19,45 +20,41 @@ import { TeamService } from 'src/team/services/team.service'; export class TeamController { 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') + @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 }, }); } } diff --git a/src/updates/controller/updates.controller.ts b/src/updates/controller/updates.controller.ts index 4dc37b9..36450f2 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, @@ -25,37 +26,37 @@ export class UpdatesController { 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') + @Get(':id') async getUpdateById(@Param('id') id: string, @Res() res: Response) { - const updateFound = await this.updateService.findUpdateById(id); + 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 +67,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); } } 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 }, }); } }