Skip to content

Commit

Permalink
Merge pull request #15 from hebertsanto/main
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
hebertzin authored Apr 2, 2024
2 parents 6393bb5 + d9dcd0a commit 3de326b
Show file tree
Hide file tree
Showing 49 changed files with 666 additions and 168 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@nestjs/common": "^10.3.3",
"@nestjs/core": "^10.3.3",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/sequelize": "^10.0.0",
"@nestjs/swagger": "^7.3.0",
Expand Down
21 changes: 11 additions & 10 deletions src/comments/controller/comments/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import {
import { Response } from 'express';
import { CommentDTO } from 'src/comments/dto/comments.dto';
import { CommentsService } from 'src/comments/services/comments/comments.service';
import { i18n } from 'src/i18n';

@ApiTags('Comments')
@Controller('comments')
export class CommentsController {
constructor(private commentsServices: CommentsService) {}

@ApiResponse({ status: 200, description: 'comment found successfully' })
@ApiResponse({ status: 200, description: i18n()['message.comment.get'] })
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : comment dos not exist',
description: 'Bad Request ',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -38,15 +39,15 @@ export class CommentsController {
const commentFound = await this.commentsServices.findCommentById(id);

return res.status(200).json({
message: 'comment found successfully',
message: i18n()['message.comment.get'],
comment: commentFound,
});
}

@ApiResponse({ status: 201, description: 'comment created successfully' })
@ApiResponse({ status: 201, description: i18n()['message.comment.created'] })
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : userID or postId or questionID does not exist',
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -58,12 +59,12 @@ export class CommentsController {
await this.commentsServices.createComment(commentDTO);

return res.status(201).json({
message: 'comment created successfully',
message: i18n()['message.comment.created'],
comment: commentCreated,
});
}

@ApiResponse({ status: 200, description: 'comment updated successfully' })
@ApiResponse({ status: 200, description: i18n()['message.comment.update'] })
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : user or post or question does not exist',
Expand All @@ -84,12 +85,12 @@ export class CommentsController {
);

return res.status(200).json({
message: 'comement update sucessfully',
message: i18n()['message.comment.update'],
comment: updated,
});
}

@ApiResponse({ status: 200, description: 'comment deleted successfully' })
@ApiResponse({ status: 200, description: i18n()['message.comment.deleted'] })
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : comment does not exist',
Expand All @@ -103,7 +104,7 @@ export class CommentsController {
await this.commentsServices.findByIdAndDeleteComment(id);

return res.status(200).json({
msg: 'comment deleted',
message: i18n()['message.comment.deleted'],
});
}
}
4 changes: 2 additions & 2 deletions src/comments/services/comments/comments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PrismaService } from 'src/database/prisma.service';
import { UserService } from 'src/user/services/user/user.service';
import { ProjectsService } from 'src/projects/services/projects/projects.service';
import { Comments } from '@prisma/client';
import { Errors } from 'src/helpers/errors';
import { LoggerService } from 'src/logger/logger.service';
import { i18n } from 'src/i18n';

@Injectable()
export class CommentsService {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class CommentsService {
return comment;
} catch (error) {
if (error instanceof NotFoundException) {
throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, comment_id);
throw new NotFoundException(i18n()['exception.notFound'], comment_id);
}

this.logger.error(`some error ocurred : ${error.message}`);
Expand Down
15 changes: 15 additions & 0 deletions src/core/controller.core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { i18n } from 'src/i18n';
import { Exception } from './exception/exception.type';

export class ControllerCore {
protected getMessage(message?: string, statusCode?: number): Exception {
return {
message: this.getDefaultMessage(message),
statusCode: statusCode | 500,
};
}

private getDefaultMessage(message?: string): string {
return message || i18n()['message.ok'];
}
}
6 changes: 6 additions & 0 deletions src/core/exception/exception.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ExceptionMessage = string | { key: string; value: string }[];

export type Exception = {
message: ExceptionMessage;
statusCode: number;
};
37 changes: 25 additions & 12 deletions src/decisions/controller/decisions/decisions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import {
import { Response } from 'express';
import { DecisionDTO } from 'src/decisions/dto/decisions.dto';
import { DecisionsService } from 'src/decisions/services/decisions/decisions.service';
import { i18n } from 'src/i18n';

@ApiTags('Decisions')
@Controller('decisions')
export class DecisionsController {
constructor(private decisionService: DecisionsService) {}

@ApiResponse({ status: 201, description: 'Decision created successfully' })
@ApiResponse({
status: 201,
description: i18n()['message.decisions.created'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : user or project does not exist',
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -40,15 +44,18 @@ export class DecisionsController {
const desicion = await this.decisionService.create(createDecision);

return res.status(201).json({
message: 'Decision created successfully',
message: i18n()['message.decisions.created'],
desicion,
});
}

@ApiResponse({ status: 200, description: 'Decision found successfully' })
@ApiResponse({
status: 200,
description: i18n()['message.decisions.get'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : decision does not exist',
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -59,15 +66,18 @@ export class DecisionsController {
const decision = await this.decisionService.findDecisionById(id);

return res.status(200).json({
msg: 'decision found',
message: i18n()['message.decisions.get'],
decision,
});
}

@ApiResponse({ status: 200, description: 'Decision deleted successfully' })
@ApiResponse({
status: 200,
description: i18n()['message.decisions.deleted'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : decision does not exist',
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -78,14 +88,17 @@ export class DecisionsController {
await this.decisionService.findDecisionByIdAndDelete(id);

return res.status(200).json({
message: 'decision was deleted successfully',
message: i18n()['message.decisions.deleted'],
});
}

@ApiResponse({ status: 200, description: 'Decision updated successfully' })
@ApiResponse({
status: 200,
description: i18n()['message.decisions.update'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request : decision or user or project does not exist',
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
Expand All @@ -103,7 +116,7 @@ export class DecisionsController {
);

return res.status(200).json({
msg: 'descion updated successfully',
message: i18n()['message.decisions.update'],
decision: updateDecision,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/decisions/services/decisions/decisions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Decision } from 'src/decisions/types/decision';
import { ProjectsService } from 'src/projects/services/projects/projects.service';
import { UserService } from 'src/user/services/user/user.service';
import { Decisions } from '@prisma/client';
import { Errors } from 'src/helpers/errors';
import { LoggerService } from 'src/logger/logger.service';
import { i18n } from 'src/i18n';

@Injectable()
export class DecisionsService {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class DecisionsService {
return decision;
} catch (error) {
if (error instanceof NotFoundException) {
throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, decision_id);
throw new NotFoundException(i18n()['exception.notFound'], decision_id);
}
this.logger.error(`some error ocurred : ${error.message}`);
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ import {
} from '@nestjs/common';
import { FollowProjectService } from 'src/follow-project/service/follow-project/follow-project.service';
import { Response } from 'express';
import { ApiTags } from '@nestjs/swagger';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { i18n } from 'src/i18n';

@ApiTags('Follow-project')
@Controller('follow-project')
export class FollowProjectController {
constructor(private followProjectService: FollowProjectService) {}

@ApiResponse({
status: 200,
description: i18n()['message.followProject.created'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
description: 'Internal server error',
})
@Post('/:projectId/follow')
async followProject(
@Body() data: any,
Expand All @@ -28,11 +46,23 @@ export class FollowProjectController {
);

return res.status(200).json({
msg: 'you started follow project',
msg: i18n()['message.followProject.created'],
follow,
});
}

@ApiResponse({
status: 200,
description: i18n()['message.followProject.all'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
description: 'Internal server error',
})
@Get('/:projectId/all-followers')
async allFollowers(
@Res() res: Response,
Expand All @@ -41,15 +71,28 @@ export class FollowProjectController {
const all =
await this.followProjectService.getProjectsUserFollow(projectId);
return res.status(200).json({
msg: 'all followers of this project',
msg: i18n()['message.followProject.all'],
all,
});
}

@ApiResponse({
status: 200,
description: i18n()['message.followProject.deleted'],
})
@ApiBadRequestResponse({
status: 400,
description: 'Bad Request',
})
@ApiInternalServerErrorResponse({
status: 500,
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: 'you stop follow this project',
msg: i18n()['message.followProject.deleted'],
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConflictException, Injectable } from '@nestjs/common';
import { PrismaService } from 'src/database/prisma.service';
import { Data } from 'src/follow-project/types/follow';
import { Errors } from 'src/helpers/errors';
import { i18n } from 'src/i18n';
import { LoggerService } from 'src/logger/logger.service';
import { ProjectsService } from 'src/projects/services/projects/projects.service';
import { UserService } from 'src/user/services/user/user.service';
Expand Down Expand Up @@ -36,7 +36,7 @@ export class FollowProjectService {
} catch (error) {
if (error instanceof ConflictException) {
throw new ConflictException(
Errors.RESOURCE_ALREADY_EXISTS,
i18n()['exception.conflict'],
`${userId} - ${projectId}`,
);
}
Expand Down
Loading

0 comments on commit 3de326b

Please sign in to comment.