Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions src/comments/controller/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Post,
Put,
Res,
Req,
HttpStatus,
} from '@nestjs/common';

import {
Expand All @@ -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);
}
}
56 changes: 27 additions & 29 deletions src/decisions/controller/decisions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Controller,
Delete,
Get,
HttpStatus,
Param,
Post,
Put,
Expand All @@ -25,99 +26,96 @@ 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()
async createDesision(
@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 },
});
}
}
41 changes: 20 additions & 21 deletions src/follow-project/controller/follow-project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Controller,
Delete,
Get,
HttpStatus,
Param,
Post,
Res,
Expand All @@ -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,
Expand All @@ -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);
}
}
Loading