diff --git a/package-lock.json b/package-lock.json index ef101f2..0c9451b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,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", @@ -2187,6 +2188,15 @@ } } }, + "node_modules/@nestjs/passport": { + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-10.0.3.tgz", + "integrity": "sha512-znJ9Y4S8ZDVY+j4doWAJ8EuuVO7SkQN3yOBmzxbGaXbvcSwFDAdGJ+OMCg52NdzIO4tQoN4pYKx8W6M0ArfFRQ==", + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "passport": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0" + } + }, "node_modules/@nestjs/platform-express": { "version": "10.3.3", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.3.3.tgz", diff --git a/package.json b/package.json index cd75522..6baacf9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/comments/controller/comments/comments.controller.ts b/src/comments/controller/comments/comments.controller.ts index ea969fe..9449244 100644 --- a/src/comments/controller/comments/comments.controller.ts +++ b/src/comments/controller/comments/comments.controller.ts @@ -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, @@ -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, @@ -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', @@ -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', @@ -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'], }); } } diff --git a/src/comments/services/comments/comments.service.ts b/src/comments/services/comments/comments.service.ts index 6601d2b..95a043a 100644 --- a/src/comments/services/comments/comments.service.ts +++ b/src/comments/services/comments/comments.service.ts @@ -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 { @@ -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}`); diff --git a/src/core/controller.core.ts b/src/core/controller.core.ts new file mode 100644 index 0000000..1d7ae7e --- /dev/null +++ b/src/core/controller.core.ts @@ -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']; + } +} diff --git a/src/core/exception/exception.type.ts b/src/core/exception/exception.type.ts new file mode 100644 index 0000000..dd427ab --- /dev/null +++ b/src/core/exception/exception.type.ts @@ -0,0 +1,6 @@ +export type ExceptionMessage = string | { key: string; value: string }[]; + +export type Exception = { + message: ExceptionMessage; + statusCode: number; +}; diff --git a/src/decisions/controller/decisions/decisions.controller.ts b/src/decisions/controller/decisions/decisions.controller.ts index c97cf7b..6fd0751 100644 --- a/src/decisions/controller/decisions/decisions.controller.ts +++ b/src/decisions/controller/decisions/decisions.controller.ts @@ -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, @@ -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, @@ -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, @@ -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, @@ -103,7 +116,7 @@ export class DecisionsController { ); return res.status(200).json({ - msg: 'descion updated successfully', + message: i18n()['message.decisions.update'], decision: updateDecision, }); } diff --git a/src/decisions/services/decisions/decisions.service.ts b/src/decisions/services/decisions/decisions.service.ts index d74037e..48019a0 100644 --- a/src/decisions/services/decisions/decisions.service.ts +++ b/src/decisions/services/decisions/decisions.service.ts @@ -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 { @@ -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; diff --git a/src/follow-project/controller/follow-project/follow-project.controller.ts b/src/follow-project/controller/follow-project/follow-project.controller.ts index 4e35758..384c450 100644 --- a/src/follow-project/controller/follow-project/follow-project.controller.ts +++ b/src/follow-project/controller/follow-project/follow-project.controller.ts @@ -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, @@ -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, @@ -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'], }); } } diff --git a/src/follow-project/service/follow-project/follow-project.service.ts b/src/follow-project/service/follow-project/follow-project.service.ts index 44af507..9972b4c 100644 --- a/src/follow-project/service/follow-project/follow-project.service.ts +++ b/src/follow-project/service/follow-project/follow-project.service.ts @@ -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'; @@ -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}`, ); } diff --git a/src/goals/controller/goals/goals.controller.ts b/src/goals/controller/goals/goals.controller.ts index 03520df..5693745 100644 --- a/src/goals/controller/goals/goals.controller.ts +++ b/src/goals/controller/goals/goals.controller.ts @@ -17,16 +17,17 @@ import { ApiResponse, ApiTags, } from '@nestjs/swagger'; +import { i18n } from 'src/i18n'; @ApiTags('Goals') @Controller('goals') export class GoalsController { constructor(private goalsService: GoalsService) {} - @ApiResponse({ status: 200, description: 'Goal found sucessfuly' }) + @ApiResponse({ status: 200, description: i18n()['message.goals.get'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : goal does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -37,15 +38,15 @@ export class GoalsController { const goal = await this.goalsService.findGoalById(id); return res.status(200).json({ - message: 'goalFound', + message: i18n()['message.goals.get'], goal, }); } - @ApiResponse({ status: 201, description: 'Goal created sucessfuly' }) + @ApiResponse({ status: 201, description: i18n()['message.goals.created'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project or user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -56,15 +57,15 @@ export class GoalsController { const create = await this.goalsService.createGoal(goals); return res.status(200).json({ - message: 'create goal successfully', + message: i18n()['message.goals.created'], create, }); } - @ApiResponse({ status: 200, description: 'Goal updated sucessfuly' }) + @ApiResponse({ status: 200, description: i18n()['message.goals.update'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : goal or project or user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -79,15 +80,15 @@ export class GoalsController { const update = await this.goalsService.findGoalByIdAndUpdate(id, goals); return res.status(200).json({ - message: 'update goal successfully', + message: i18n()['message.goals.update'], update, }); } - @ApiResponse({ status: 200, description: 'Goal deleted sucessfuly' }) + @ApiResponse({ status: 200, description: i18n()['message.goals.deleted'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : goal does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -98,7 +99,7 @@ export class GoalsController { await this.goalsService.findGoalByIdAndDelete(id); return res.status(200).json({ - message: 'goal deleted', + message: i18n()['message.goals.deleted'], }); } } diff --git a/src/goals/services/goals/goals.service.ts b/src/goals/services/goals/goals.service.ts index 5c22f9c..24f7892 100644 --- a/src/goals/services/goals/goals.service.ts +++ b/src/goals/services/goals/goals.service.ts @@ -4,8 +4,8 @@ import { TGoals } from 'src/goals/types/gaols'; import { ProjectsService } from 'src/projects/services/projects/projects.service'; import { UserService } from 'src/user/services/user/user.service'; import { Goals } from '@prisma/client'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; @Injectable() export class GoalsService { @@ -81,7 +81,7 @@ export class GoalsService { return goal; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, goal_id); + throw new NotFoundException(i18n()['exception.notFound'], goal_id); } this.logger.error(`some error ocurred : ${error.message}`); throw error; diff --git a/src/helpers/errors.ts b/src/helpers/errors.ts deleted file mode 100644 index 464177f..0000000 --- a/src/helpers/errors.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const Errors = { - RESOURCE_NOT_FOUND: 'Recurso não encontrado no banco de dados', - RESOURCE_ALREADY_EXISTS: 'Recurso já existe', - MISSING_RESOURCE: 'Recurso ausente', -}; diff --git a/src/i18n/en/comments-messages.json b/src/i18n/en/comments-messages.json new file mode 100644 index 0000000..176baa6 --- /dev/null +++ b/src/i18n/en/comments-messages.json @@ -0,0 +1,6 @@ +{ + "message.comment.created": "Comment has been created successfully", + "message.comment.deleted": "Comment has been deleted successfully", + "message.comment.update": "Comment has been updated successfully", + "message.comment.get": "Comment found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/decisions-messages.json b/src/i18n/en/decisions-messages.json new file mode 100644 index 0000000..752b901 --- /dev/null +++ b/src/i18n/en/decisions-messages.json @@ -0,0 +1,6 @@ +{ + "message.decisions.created": "Decisions has been created successfully", + "message.decisions.deleted": "Decisions has been deleted successfully", + "message.decisions.update": "Decisions has been updated successfully", + "message.decisions.get": "Decisions found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/exception.json b/src/i18n/en/exception.json new file mode 100644 index 0000000..312dcbd --- /dev/null +++ b/src/i18n/en/exception.json @@ -0,0 +1,13 @@ +{ + "exception.badRequest": "The server could not understand the request due to invalid syntax.", + "exception.conflict": "The request could not be completed due to a conflict with the current state of the resource.", + "exception.deleteError": "The requested resource could not be deleted. Please check your request.", + "exception.emptyBody": "The request body is empty. Please provide the necessary data.", + "exception.forbidden": "You do not have permission to access the requested resource.", + "exception.notFound": "The requested resource could not be found. Please check your request.", + "exception.serverError": "The server encountered an error while processing the request.", + "exception.tokenExpired": "The provided token has expired. Please refresh your token.", + "exception.tokenMalformed": "The provided token is malformed. Please check your token.", + "exception.tokenNotProvided": "No authentication token provided. Please include a token in your request.", + "exception.tokenVerify": "An error occurred while verifying the token. Please check your token." +} \ No newline at end of file diff --git a/src/i18n/en/follow-project-messages.json b/src/i18n/en/follow-project-messages.json new file mode 100644 index 0000000..0eae01b --- /dev/null +++ b/src/i18n/en/follow-project-messages.json @@ -0,0 +1,5 @@ +{ + "message.followProject.created": "Follow has been created successfully", + "message.followProject.deleted": "Follow has been deleted successfully", + "message.followProject.all": "All Followers found successfully" +} diff --git a/src/i18n/en/goals-messages.json b/src/i18n/en/goals-messages.json new file mode 100644 index 0000000..88d426d --- /dev/null +++ b/src/i18n/en/goals-messages.json @@ -0,0 +1,6 @@ +{ + "message.goals.created": "Goals has been created successfully", + "message.goals.deleted": "Goals has been deleted successfully", + "message.goals.update": "Goals has been updated successfully", + "message.goals.get": "Goals found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts new file mode 100644 index 0000000..e1fce83 --- /dev/null +++ b/src/i18n/en/index.ts @@ -0,0 +1,29 @@ +import Exception from './exception.json'; +import UserMessages from './users-messages.json'; +import ProjectsMessages from './projects-messages.json'; +import ProfileMessages from './profile-messages.json'; +import CommentMessages from './comments-messages.json'; +import QuestionsMessages from './question-messages.json'; +import GoalsMessages from './goals-messages.json'; +import TeamMessages from './team-messages.json'; +import ProjectIdea from './project-idea-messages.json'; +import Updates from './updates-messages.json'; +import Decisions from './decisions-messages.json'; +import FollowProject from './follow-project-messages.json'; +import TaskList from './tasklist-messages.json'; + +export default { + ...Exception, + ...UserMessages, + ...ProjectsMessages, + ...ProfileMessages, + ...QuestionsMessages, + ...CommentMessages, + ...GoalsMessages, + ...TeamMessages, + ...ProjectIdea, + ...Updates, + ...Decisions, + ...FollowProject, + ...TaskList, +}; diff --git a/src/i18n/en/profile-messages.json b/src/i18n/en/profile-messages.json new file mode 100644 index 0000000..1fa584c --- /dev/null +++ b/src/i18n/en/profile-messages.json @@ -0,0 +1,6 @@ +{ + "message.profile.created": "Profile has been created successfully", + "message.profile.deleted": "Profile has been deleted successfully", + "message.profile.update": "Profile has been updated successfully", + "message.profile.get": "Profile found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/project-idea-messages.json b/src/i18n/en/project-idea-messages.json new file mode 100644 index 0000000..2de7b77 --- /dev/null +++ b/src/i18n/en/project-idea-messages.json @@ -0,0 +1,7 @@ +{ + "message.projectIdea.created": "Project idea has been created successfully", + "message.projectIdea.deleted": "Project idea has been deleted successfully", + "message.projectIdea.update": "Project idea has been updated successfully", + "message.projectIdea.get": "Project idea found successfully", + "message.projectIdea.userId": "All Project idea found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/projects-messages.json b/src/i18n/en/projects-messages.json new file mode 100644 index 0000000..80d828d --- /dev/null +++ b/src/i18n/en/projects-messages.json @@ -0,0 +1,8 @@ +{ + "message.project.created": "Project has been created successfully", + "message.project.deleted": "Project has been deleted successfully", + "message.project.update": "Project has been updated successfully", + "message.project.get": "Project found successfully", + "message.project.userId": "All projects found successfully", + "message.project.priority": "All projects found by priority" +} \ No newline at end of file diff --git a/src/i18n/en/question-messages.json b/src/i18n/en/question-messages.json new file mode 100644 index 0000000..e5ee1e3 --- /dev/null +++ b/src/i18n/en/question-messages.json @@ -0,0 +1,7 @@ +{ + "message.question.created": "Question has been created successfully", + "message.question.deleted": "Question has been deleted successfully", + "message.question.update": "Question has been updated successfully", + "message.question.get": "Question found successfully", + "message.question.userId": "All Questions found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/tasklist-messages.json b/src/i18n/en/tasklist-messages.json new file mode 100644 index 0000000..f9f7939 --- /dev/null +++ b/src/i18n/en/tasklist-messages.json @@ -0,0 +1,8 @@ +{ + "message.taskList.created": "Task has been created successfully", + "message.taskList.deleted": "Task has been deleted successfully", + "message.taskList.update": "Task has been updated successfully", + "message.taskList.get": "Task found successfully", + "message.taskList.userId": "All Task found successfully", + "message.taskList.priority": "All Task found by priority" +} \ No newline at end of file diff --git a/src/i18n/en/team-messages.json b/src/i18n/en/team-messages.json new file mode 100644 index 0000000..aa7b785 --- /dev/null +++ b/src/i18n/en/team-messages.json @@ -0,0 +1,6 @@ +{ + "message.team.created": "Team has been created successfully", + "message.team.deleted": "Team has been deleted successfully", + "message.team.update": "Team has been updated successfully", + "message.team.get": "Team found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/updates-messages.json b/src/i18n/en/updates-messages.json new file mode 100644 index 0000000..d8486a8 --- /dev/null +++ b/src/i18n/en/updates-messages.json @@ -0,0 +1,6 @@ +{ + "message.updates.created": "Update has been created successfully", + "message.updates.deleted": "Update has been deleted successfully", + "message.updates.update": "Update has been updated successfully", + "message.updates.get": "Update found successfully" +} \ No newline at end of file diff --git a/src/i18n/en/users-messages.json b/src/i18n/en/users-messages.json new file mode 100644 index 0000000..a3d5286 --- /dev/null +++ b/src/i18n/en/users-messages.json @@ -0,0 +1,13 @@ +{ + "message.ok": "Operation successful", + "message.emailVerify.sentToEmail": "Verification code has been sent to your email", + "message.emailVerify.successfully": "Email has been verified successfully", + "message.passwordReset.sentToEmail": "Password reset code has been sent to your email", + "message.passwordReset.successfully": "Password has been reset successfully", + "message.user.created": "User has been created successfully", + "message.user.deleted": "User has been deleted successfully", + "message.user.update": "User has been updated successfully", + "message.user.get": "User found successfully", + "message.user.notFound": "User not found", + "message.user.conflict": "User already exist" +} diff --git a/src/i18n/index.ts b/src/i18n/index.ts new file mode 100644 index 0000000..92fc691 --- /dev/null +++ b/src/i18n/index.ts @@ -0,0 +1,3 @@ +import en from './en'; + +export const i18n = () => en; diff --git a/src/profile/controller/profile/profile.controller.ts b/src/profile/controller/profile/profile.controller.ts index 538f869..69ce1ae 100644 --- a/src/profile/controller/profile/profile.controller.ts +++ b/src/profile/controller/profile/profile.controller.ts @@ -6,6 +6,7 @@ import { ApiTags, } from '@nestjs/swagger'; import { Response } from 'express'; +import { i18n } from 'src/i18n'; import { CreateProfileDTO } from 'src/profile/dto/create-profile.dto'; import { ProfileService } from 'src/profile/services/profile/profile.service'; @@ -14,10 +15,10 @@ import { ProfileService } from 'src/profile/services/profile/profile.service'; export class ProfileController { constructor(private profileService: ProfileService) {} - @ApiResponse({ status: 200, description: 'Profile found successfully' }) + @ApiResponse({ status: 200, description: i18n()['message.profile.get'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : profile does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -28,15 +29,18 @@ export class ProfileController { const profile = await this.profileService.findProfileById(profile_id); return res.status(200).json({ - message: 'profile found', + message: i18n()['message.profile.get'], profile, }); } - @ApiResponse({ status: 201, description: 'Profile created successfully' }) + @ApiResponse({ + status: 201, + description: i18n()['message.profile.created'], + }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -51,15 +55,18 @@ export class ProfileController { await this.profileService.createProfile(createProfileDTO); return res.status(201).json({ - message: 'profile created successfully', + message: i18n()['message.profile.created'], profile: createProfile, }); } - @ApiResponse({ status: 200, description: 'Profile updated successfully' }) + @ApiResponse({ + status: 200, + description: i18n()['message.profile.update'], + }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -76,7 +83,7 @@ export class ProfileController { updateProfile, ); return res.status(200).json({ - message: 'profile updated', + message: i18n()['message.profile.update'], update, }); } diff --git a/src/profile/services/profile/profile.service.ts b/src/profile/services/profile/profile.service.ts index efe9d81..9596d73 100644 --- a/src/profile/services/profile/profile.service.ts +++ b/src/profile/services/profile/profile.service.ts @@ -3,8 +3,8 @@ import { PrismaService } from 'src/database/prisma.service'; import { TProfile } from 'src/profile/types/profile'; import { UserService } from 'src/user/services/user/user.service'; import { Profile } from '@prisma/client'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; @Injectable() export class ProfileService { @@ -28,7 +28,7 @@ export class ProfileService { return profile; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, profile_id); + throw new NotFoundException(i18n()['exception.notFound'], profile_id); } this.logger.error(`some error ocurred : ${error.message}`); throw error; diff --git a/src/project-idea/controllers/project-idea.controller.ts b/src/project-idea/controllers/project-idea.controller.ts index 280181c..a4ceda9 100644 --- a/src/project-idea/controllers/project-idea.controller.ts +++ b/src/project-idea/controllers/project-idea.controller.ts @@ -17,16 +17,17 @@ import { ApiResponse, ApiTags, } from '@nestjs/swagger'; +import { i18n } from 'src/i18n'; @ApiTags('Project-idea') @Controller('projectIdea') export class ProjectIdeaController { constructor(private projectIdeaService: ProjectIdeaService) {} - @ApiResponse({ status: 200, description: 'Project idea found successfully' }) + @ApiResponse({ status: 200, description: i18n()['message.projectIdea.get'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project idea does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -37,18 +38,18 @@ export class ProjectIdeaController { const projectIdea = await this.projectIdeaService.findProjectIdeaById(id); return res.status(200).json({ - message: 'project idea', + message: i18n()['message.projectIdea.get'], projectIdea, }); } @ApiResponse({ status: 200, - description: 'All projects idea found successfully', + description: i18n()['message.projectIdea.userId'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -63,18 +64,18 @@ export class ProjectIdeaController { await this.projectIdeaService.findAllProjectIdeas(userId); return res.status(200).json({ - message: 'all projects ideas are here', + message: i18n()['message.projectIdea.userId'], allProjectsIdeas, }); } @ApiResponse({ status: 201, - description: 'project idea created successfully', + description: i18n()['message.projectIdea.created'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -89,18 +90,18 @@ export class ProjectIdeaController { await this.projectIdeaService.createProjectIdea(createProjectIdea); return res.status(201).json({ - message: 'project idea created sucessfuly', + message: i18n()['message.projectIdea.created'], projectIdea: createIdea, }); } @ApiResponse({ status: 200, - description: 'project idea updated successfully', + description: i18n()['message.projectIdea.update'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user or project does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -118,18 +119,18 @@ export class ProjectIdeaController { ); return res.status(200).json({ - message: 'project idea was updated', + message: i18n()['message.projectIdea.update'], update: updateIdea, }); } @ApiResponse({ status: 200, - description: 'project idea delete successfully', + description: i18n()['message.projectIdea.deleted'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project idea does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -140,7 +141,7 @@ export class ProjectIdeaController { await this.projectIdeaService.DeleteProjectIdea(id); return res.status(200).json({ - message: 'project idea was deleted', + message: i18n()['message.projectIdea.deleted'], }); } } diff --git a/src/project-idea/services/project-idea.service.ts b/src/project-idea/services/project-idea.service.ts index 14d36d7..e7ee542 100644 --- a/src/project-idea/services/project-idea.service.ts +++ b/src/project-idea/services/project-idea.service.ts @@ -2,8 +2,8 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { PrismaService } from 'src/database/prisma.service'; import { ProjectIdea } from '../types/projectIdea'; import { UserService } from 'src/user/services/user/user.service'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; @Injectable() export class ProjectIdeaService { @@ -56,7 +56,7 @@ export class ProjectIdeaService { return projectIdea; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, id); + throw new NotFoundException(i18n()['exception.notFound'], id); } this.logger.error(`some errror ocurred : ${error.message}`); throw error; diff --git a/src/projects/controller/projects/projects.controller.ts b/src/projects/controller/projects/projects.controller.ts index c2962b0..48e416b 100644 --- a/src/projects/controller/projects/projects.controller.ts +++ b/src/projects/controller/projects/projects.controller.ts @@ -18,6 +18,7 @@ import { ApiResponse, ApiTags, } from '@nestjs/swagger'; +import { i18n } from 'src/i18n'; @ApiTags('Projects') @Controller('/projects') @@ -26,11 +27,11 @@ export class ProjectsController { @ApiResponse({ status: 201, - description: 'Project created successfully', + description: i18n()['message.project.created'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -40,18 +41,18 @@ export class ProjectsController { async create(@Body() dataProjects: ProjectDto, @Res() res: Response) { const createProject = await this.projectsServices.create(dataProjects); return res.status(201).json({ - msg: 'project created successfully', + msg: i18n()['message.project.created'], project: createProject, }); } @ApiResponse({ status: 200, - description: 'Project found successfully', + description: i18n()['message.project.get'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project does not exist', + description: 'Bad Reques', }) @ApiInternalServerErrorResponse({ status: 500, @@ -61,18 +62,18 @@ export class ProjectsController { async findProjectById(@Param('id') id: string, @Res() res: Response) { const project = await this.projectsServices.findById(id); return res.status(200).json({ - msg: 'project found successfully', + message: i18n()['message.project.get'], project, }); } @ApiResponse({ status: 200, - description: 'All project found successfully', + description: i18n()['message.project.userId'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -83,10 +84,23 @@ export class ProjectsController { const allProjectsUsers = await this.projectsServices.findAllProjectsUser(userId); return res.status(200).json({ - msg: 'all projects found successfully', + msg: i18n()['message.project.userId'], projects: allProjectsUsers, }); } + + @ApiResponse({ + status: 200, + description: i18n()['message.project.priority'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) @Get('/filter') async findProjectByPriority( @Query('priority') priority: string, @@ -94,16 +108,16 @@ export class ProjectsController { ) { await this.projectsServices.findProjectsByPriority(priority); return res.status(200).json({ - msg: 'projects found successfully', + msg: i18n()['message.project.priority'], }); } @ApiResponse({ status: 200, - description: 'Project delete successfully', + description: 'Project has been deleted successfully', }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -113,17 +127,17 @@ export class ProjectsController { async deleteProjectById(@Param('id') id: string, @Res() res: Response) { await this.projectsServices.deleteProjectById(id); return res.status(200).json({ - msg: 'project deleted successfully', + msg: i18n()['message.project.deleted'], }); } @ApiResponse({ status: 200, - description: 'Project update successfully', + description: i18n()['message.project.update'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project or user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -140,7 +154,7 @@ export class ProjectsController { dataProject, ); return res.status(200).json({ - msg: 'Project updated successfully', + msg: i18n()['message.project.update'], project, }); } diff --git a/src/projects/services/projects/projects.service.ts b/src/projects/services/projects/projects.service.ts index 0a1d078..256e350 100644 --- a/src/projects/services/projects/projects.service.ts +++ b/src/projects/services/projects/projects.service.ts @@ -3,16 +3,19 @@ import { PrismaService } from 'src/database/prisma.service'; import { Project } from 'src/projects/types'; import { UserService } from 'src/user/services/user/user.service'; import { Projects } from '@prisma/client'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from '../../../i18n/index'; +import { ControllerCore } from 'src/core/controller.core'; @Injectable() -export class ProjectsService { +export class ProjectsService extends ControllerCore { constructor( private prismaService: PrismaService, private userService: UserService, private logger: LoggerService, - ) {} + ) { + super(); + } async checkProjectExistence(project_id: string): Promise { try { @@ -29,7 +32,9 @@ export class ProjectsService { return project; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, project_id); + const messsage = this.getMessage(i18n()['exception.notFound']); + + throw new NotFoundException(messsage.message, project_id); } this.logger.error( `some error ocurred checking project existence : ${error.message}`, diff --git a/src/questions/controller/questions/questions.controller.ts b/src/questions/controller/questions/questions.controller.ts index 2aa96af..426c1c8 100644 --- a/src/questions/controller/questions/questions.controller.ts +++ b/src/questions/controller/questions/questions.controller.ts @@ -15,6 +15,8 @@ import { ApiTags, } from '@nestjs/swagger'; import { Response } from 'express'; +import { i18n } from '../../../i18n'; + import { QuestionsDTO } from 'src/questions/dto/questions.dto'; import { QuestionsService } from 'src/questions/services/questions/questions.service'; @@ -23,10 +25,13 @@ import { QuestionsService } from 'src/questions/services/questions/questions.ser export class QuestionsController { constructor(private questionsServices: QuestionsService) {} - @ApiResponse({ status: 201, description: 'Question created successfully' }) + @ApiResponse({ + status: 201, + description: i18n()['message.question.created'], + }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : project or user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -40,15 +45,15 @@ export class QuestionsController { const question = await this.questionsServices.createQuestion(createQuestion); return res.status(201).json({ - message: 'question created successfully', + message: i18n()['message.question.created'], question, }); } - @ApiResponse({ status: 200, description: 'Question found successfully' }) + @ApiResponse({ status: 200, description: i18n()['message.question.get'] }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : question does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -59,18 +64,18 @@ export class QuestionsController { const question = await this.questionsServices.findQuestionById(id); return res.status(200).json({ - message: 'question found successfully', + message: i18n()['message.question.get'], question, }); } @ApiResponse({ status: 200, - description: 'All Question by user found successfully', + description: i18n()['message.question.userId'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -84,18 +89,18 @@ export class QuestionsController { const question = await this.questionsServices.allQuestionsUser(userId); return res.status(200).json({ - message: 'all Questions user', + message: i18n()['message.question.userId'], question, }); } @ApiResponse({ status: 200, - description: 'Question updated successfully', + description: i18n()['message.question.update'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user or project does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -113,14 +118,14 @@ export class QuestionsController { updateQuestion, ); return res.status(200).json({ - message: 'question updated', + message: i18n()['message.question.update'], question: questionUpdated, }); } @ApiResponse({ status: 200, - description: 'Question deleted successfully', + description: i18n()['message.question.deleted'], }) @ApiBadRequestResponse({ status: 400, @@ -135,7 +140,7 @@ export class QuestionsController { await this.questionsServices.findQuestionByIdAndDelete(id); return res.status(200).json({ - message: 'question deleted', + message: i18n()['message.question.deleted'], }); } } diff --git a/src/questions/services/questions/questions.service.ts b/src/questions/services/questions/questions.service.ts index 7c3f97d..5711be8 100644 --- a/src/questions/services/questions/questions.service.ts +++ b/src/questions/services/questions/questions.service.ts @@ -3,8 +3,8 @@ import { PrismaService } from 'src/database/prisma.service'; import { TQuestion } from 'src/questions/types/question'; import { UserService } from 'src/user/services/user/user.service'; import { Questions } from '@prisma/client'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; @Injectable() export class QuestionsService { @@ -38,7 +38,7 @@ export class QuestionsService { }, }); if (!question) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, question_id); + throw new NotFoundException(i18n()['exception.notFound'], question_id); } return question; } catch (error) { diff --git a/src/send-email/service/send-email/send-email.service.ts b/src/send-email/service/send-email/send-email.service.ts index 5d612ed..e171a7d 100644 --- a/src/send-email/service/send-email/send-email.service.ts +++ b/src/send-email/service/send-email/send-email.service.ts @@ -2,7 +2,7 @@ import { MailerService } from '@nestjs-modules/mailer'; import { Injectable, NotFoundException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { PrismaService } from 'src/database/prisma.service'; -import { Errors } from 'src/helpers/errors'; +import { i18n } from 'src/i18n'; import { LoggerService } from 'src/logger/logger.service'; @Injectable() @@ -48,7 +48,7 @@ export class SendEmailService { }); if (!user) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND); + throw new NotFoundException(i18n()['message.user.notFound']); } await this.prismaService.user.update({ @@ -60,15 +60,15 @@ export class SendEmailService { }, }); - console.log('token decoded', decodedToken); return decodedToken; } catch (error) { if (error.name === 'TokenExpiredError') { - throw new Error('Token expired'); + throw new Error(i18n()['exception.tokenExpired']); } if (error.name === 'JsonWebTokenError') { - throw new Error('invalid token'); + throw new Error(i18n()['exception.tokenMalformed']); } + this.logger.error(`some error ocurred : ${error.message}`); } } diff --git a/src/task-list-project/controller/task-list-project/task-list-project.controller.ts b/src/task-list-project/controller/task-list-project/task-list-project.controller.ts index afd3e5f..4e1e34f 100644 --- a/src/task-list-project/controller/task-list-project/task-list-project.controller.ts +++ b/src/task-list-project/controller/task-list-project/task-list-project.controller.ts @@ -1,4 +1,115 @@ -import { Controller } from '@nestjs/common'; +import { + Body, + Controller, + Delete, + Get, + Param, + Post, + Put, + Res, +} from '@nestjs/common'; +import { TaskListProjectService } from 'src/task-list-project/service/task-list-project/task-list-project.service'; +import { Response } from 'express'; +import { i18n } from 'src/i18n'; +import { + ApiBadRequestResponse, + ApiInternalServerErrorResponse, + ApiResponse, +} from '@nestjs/swagger'; -@Controller('task-list-project') -export class TaskListProjectController {} +@Controller('task') +export class TaskListProjectController { + constructor(private taskListService: TaskListProjectService) {} + + @ApiResponse({ + status: 201, + description: i18n()['message.taskList.get'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) + @Get('/:id') + async findById(@Param('id') id: string, @Res() res: Response) { + const question = await this.taskListService.findTaskById(id); + + return res.status(200).json({ + message: i18n()['message.taskList.get'], + question, + }); + } + + @ApiResponse({ + status: 201, + description: i18n()['message.taskList.created'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) + @Post('/') + async createTask(@Body() data: any, @Res() res: Response) { + const question = await this.taskListService.createTaskProject(data); + + return res.status(200).json({ + message: i18n()['message.taskList.created'], + question, + }); + } + + @ApiResponse({ + status: 201, + description: i18n()['message.taskList.update'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) + @Put('/:id') + async updateTask( + @Param() id: string, + @Body() data: any, + @Res() res: Response, + ) { + const question = await this.taskListService.updateTask(id, data); + + return res.status(200).json({ + message: i18n()['message.taskList.update'], + question, + }); + } + + @ApiResponse({ + status: 201, + description: i18n()['message.taskList.deleted'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) + @Delete('/:id') + async deleteTask(@Param('id') id: string, @Res() res: Response) { + const question = await this.taskListService.deleteTask(id); + + return res.status(200).json({ + message: i18n()['message.taskList.deleted'], + question, + }); + } +} diff --git a/src/task-list-project/dtos/index.ts b/src/task-list-project/dtos/index.ts new file mode 100644 index 0000000..1c861dc --- /dev/null +++ b/src/task-list-project/dtos/index.ts @@ -0,0 +1,24 @@ +import { Priority } from '@prisma/client'; +import { IsEnum, IsNotEmpty, IsString } from 'class-validator'; + +export class TaskListDTO { + @IsNotEmpty() + @IsString() + title: string; + + @IsString() + @IsNotEmpty() + description: string; + + @IsEnum(Priority) + @IsNotEmpty() + priority: string; + + @IsNotEmpty() + @IsString() + userId: string; + + @IsNotEmpty() + @IsString() + projectId: string; +} diff --git a/src/task-list-project/service/task-list-project/task-list-project.service.ts b/src/task-list-project/service/task-list-project/task-list-project.service.ts index cf8d573..dc0f0b4 100644 --- a/src/task-list-project/service/task-list-project/task-list-project.service.ts +++ b/src/task-list-project/service/task-list-project/task-list-project.service.ts @@ -1,4 +1,71 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; +import { PrismaService } from 'src/database/prisma.service'; +import { i18n } from 'src/i18n'; +import { LoggerService } from 'src/logger/logger.service'; +import { ProjectsService } from 'src/projects/services/projects/projects.service'; +import { TaskListProject } from 'src/task-list-project/types'; +import { UserService } from 'src/user/services/user/user.service'; @Injectable() -export class TaskListProjectService {} +export class TaskListProjectService { + constructor( + private prismaService: PrismaService, + private userService: UserService, + private projectService: ProjectsService, + private logger: LoggerService, + ) {} + + createTaskProject = async (data: TaskListProject) => { + this.logger.log('make all verifications before create tasklist...'); + await this.userService.checkUserExistence(data.userId); + await this.projectService.checkProjectExistence(data.projectId); + + const taskList = await this.prismaService.taskListProject.create({ + data: { + ...data, + }, + }); + return taskList; + }; + + findTaskById = async ( + task_list_id: string, + ): Promise => { + const taskList = await this.prismaService.taskListProject.findUnique({ + where: { + id: task_list_id, + }, + }); + + if (!taskList) { + throw new NotFoundException(i18n()['exception.notFound']); + } + return taskList; + }; + + deleteTask = async (task_list_id: string): Promise => { + await this.findTaskById(task_list_id); + await this.prismaService.taskListProject.delete({ + where: { + id: task_list_id, + }, + }); + }; + + updateTask = async ( + task_list_id: string, + data: TaskListProject, + ): Promise => { + this.logger.log('make all verifications before create tasklist...'); + await this.projectService.checkProjectExistence(data.projectId); + const taskList = await this.prismaService.taskListProject.update({ + where: { + id: task_list_id, + }, + data: { + ...data, + }, + }); + return taskList; + }; +} diff --git a/src/task-list-project/task-list-project.module.ts b/src/task-list-project/task-list-project.module.ts index cf75cca..0da1406 100644 --- a/src/task-list-project/task-list-project.module.ts +++ b/src/task-list-project/task-list-project.module.ts @@ -1,9 +1,17 @@ import { Module } from '@nestjs/common'; import { TaskListProjectController } from './controller/task-list-project/task-list-project.controller'; import { TaskListProjectService } from './service/task-list-project/task-list-project.service'; +import { UserService } from 'src/user/services/user/user.service'; +import { ProjectsService } from 'src/projects/services/projects/projects.service'; +import { HashService } from 'src/hash/service/hash/hash.service'; @Module({ controllers: [TaskListProjectController], - providers: [TaskListProjectService], + providers: [ + TaskListProjectService, + UserService, + ProjectsService, + HashService, + ], }) export class TaskListProjectModule {} diff --git a/src/task-list-project/types/index.ts b/src/task-list-project/types/index.ts new file mode 100644 index 0000000..9cc11ba --- /dev/null +++ b/src/task-list-project/types/index.ts @@ -0,0 +1,9 @@ +import { Priority } from '@prisma/client'; + +export type TaskListProject = { + title: string; + description: string; + priority: Priority; + userId: string; + projectId: string; +}; diff --git a/src/team/controller/team/team.controller.ts b/src/team/controller/team/team.controller.ts index 1bdadcf..0bd74b0 100644 --- a/src/team/controller/team/team.controller.ts +++ b/src/team/controller/team/team.controller.ts @@ -10,6 +10,7 @@ import { } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { Response } from 'express'; +import { i18n } from 'src/i18n'; import { TeamDTO } from 'src/team/dto/team.dto'; import { TeamService } from 'src/team/services/team/team.service'; @@ -23,7 +24,7 @@ export class TeamController { const team = await this.teamService.findTeamById(id); return res.status(200).json({ - msg: 'team found successfully', + message: i18n()['message.team.get'], team, }); } @@ -33,7 +34,7 @@ export class TeamController { const createTeam = await this.teamService.createTeam(team); return res.status(201).json({ - msg: 'team successfully created', + message: i18n()['message.team.created'], team: createTeam, }); } @@ -42,7 +43,7 @@ export class TeamController { async delete(@Param('id') id: string, @Res() res: Response) { await this.teamService.findTeamByIdAnDelete(id); return res.status(200).json({ - msg: 'team deleted successfully', + message: i18n()['message.team.deleted'], }); } @@ -55,7 +56,7 @@ export class TeamController { const updateTeam = await this.teamService.findTeamByIdAndUpdate(id, data); return res.status(200).json({ - msg: 'team updated successfully', + message: i18n()['message.team.update'], updateTeam, }); } diff --git a/src/team/services/team/team.service.ts b/src/team/services/team/team.service.ts index a995274..202053a 100644 --- a/src/team/services/team/team.service.ts +++ b/src/team/services/team/team.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { Team } from '@prisma/client'; import { PrismaService } from 'src/database/prisma.service'; -import { Errors } from 'src/helpers/errors'; +import { i18n } from 'src/i18n'; import { LoggerService } from 'src/logger/logger.service'; import { TTeam } from 'src/team/types/team'; import { UserService } from 'src/user/services/user/user.service'; @@ -40,7 +40,7 @@ export class TeamService { return team; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, team_id); + throw new NotFoundException(i18n()['exception.notFound'], team_id); } this.logger.error(`some error ocurred : ${error.message}`); diff --git a/src/updates/controller/updates/updates.controller.ts b/src/updates/controller/updates/updates.controller.ts index 9b9a725..3d92713 100644 --- a/src/updates/controller/updates/updates.controller.ts +++ b/src/updates/controller/updates/updates.controller.ts @@ -15,6 +15,7 @@ import { ApiTags, } from '@nestjs/swagger'; import { Response } from 'express'; +import { i18n } from 'src/i18n'; import { UpdateDTO } from 'src/updates/dto/update.dto'; import { UpdatesService } from 'src/updates/services/updates/updates.service'; @@ -25,7 +26,7 @@ export class UpdatesController { @ApiResponse({ status: 200, - description: 'Update found successfully', + description: i18n()['message.updates.get'], }) @ApiBadRequestResponse({ status: 400, @@ -40,18 +41,18 @@ export class UpdatesController { const updateFound = await this.updateService.findUpdateById(id); return res.status(200).json({ - msg: 'updated found successfully', + message: i18n()['message.updates.get'], updateFound, }); } @ApiResponse({ status: 201, - description: 'Update create successfully', + description: i18n()['message.updates.created'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user or project does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -66,18 +67,18 @@ export class UpdatesController { await this.updateService.createUpdateToProject(createUpdateProject); return res.status(200).json({ - msg: 'update created successfully', + message: i18n()['message.updates.created'], update, }); } @ApiResponse({ status: 200, - description: 'Update projects updated successfully', + description: i18n()['message.updates.update'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user or project does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -94,14 +95,14 @@ export class UpdatesController { updateData, ); return res.status(200).json({ - msg: 'update edit successfully', + message: i18n()['message.updates.update'], updated: editUpdateProject, }); } @ApiResponse({ status: 200, - description: 'Update deleted successfully', + description: i18n()['message.updates.deleted'], }) @ApiBadRequestResponse({ status: 400, @@ -115,7 +116,7 @@ export class UpdatesController { async deleteUpdate(@Param('id') id: string, @Res() res: Response) { await this.updateService.findByIdAndDeleteUpdate(id); return res.status(200).json({ - msg: 'delete sucessfully', + message: i18n()['message.updates.deleted'], }); } } diff --git a/src/updates/services/updates/updates.service.ts b/src/updates/services/updates/updates.service.ts index 4b5f0a8..d4adae9 100644 --- a/src/updates/services/updates/updates.service.ts +++ b/src/updates/services/updates/updates.service.ts @@ -4,8 +4,8 @@ import { ProjectsService } from 'src/projects/services/projects/projects.service import { TUpdate } from 'src/updates/types/updates'; import { UserService } from 'src/user/services/user/user.service'; import { Updates } from '@prisma/client'; -import { Errors } from 'src/helpers/errors'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; @Injectable() export class UpdatesService { @@ -46,7 +46,7 @@ export class UpdatesService { return updateFound; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, update_id); + throw new NotFoundException(i18n()['exception.notFound'], update_id); } this.logger.error(`some error ocurred : ${error.message}`); throw error; @@ -58,6 +58,7 @@ export class UpdatesService { data: TUpdate, ): Promise { try { + this.logger.log('verifiy if project and updates exist before update...'); await this.userService.checkUserExistence(data.userId); await this.projectService.checkProjectExistence(data.projectId); const update = await this.prismaService.updates.update({ @@ -77,6 +78,7 @@ export class UpdatesService { async findByIdAndDeleteUpdate(update_id: string): Promise { try { + await this.findUpdateById(update_id); return await this.prismaService.updates.delete({ where: { id: update_id, diff --git a/src/user/controller/user/user.controller.ts b/src/user/controller/user/user.controller.ts index ce7dc8e..21c05f0 100644 --- a/src/user/controller/user/user.controller.ts +++ b/src/user/controller/user/user.controller.ts @@ -15,6 +15,7 @@ import { ApiTags, } from '@nestjs/swagger'; import { Response } from 'express'; +import { i18n } from 'src/i18n'; import { UserDto } from 'src/user/dto/user.dto'; import { UserService } from 'src/user/services/user/user.service'; @@ -25,11 +26,11 @@ export class UserController { @ApiResponse({ status: 200, - description: 'User found successfully', + description: i18n()['message.user.get'], }) @ApiBadRequestResponse({ status: 400, - description: 'Bad Request : user does not exist', + description: 'Bad Request', }) @ApiInternalServerErrorResponse({ status: 500, @@ -39,14 +40,14 @@ export class UserController { async findUserById(@Param('id') id: string, @Res() res: Response) { const user = await this.userService.findUserById(id); return res.status(200).json({ - msg: 'user found successfully', + msg: i18n()['message.user.get'], user, }); } @ApiResponse({ status: 200, - description: 'User created successfully', + description: i18n()['message.user.created'], }) @ApiBadRequestResponse({ status: 400, @@ -60,14 +61,14 @@ export class UserController { async createUser(@Body() createUserDto: UserDto, @Res() res: Response) { const user = await this.userService.createUser(createUserDto); return res.json({ - msg: 'user created successfully', + msg: i18n()['message.user.created'], user, }); } @ApiResponse({ status: 200, - description: 'User deleted successfully', + description: i18n()['message.user.deleted'], }) @ApiBadRequestResponse({ status: 400, @@ -81,11 +82,22 @@ export class UserController { async deleteUser(@Param('id') id: string, @Res() res: Response) { await this.userService.findUserByIdAndDelete(id); return res.json({ - msg: 'user delete successfully', + msg: i18n()['message.user.deleted'], }); } - // manutation in this part of project + @ApiResponse({ + status: 200, + description: i18n()['message.user.update'], + }) + @ApiBadRequestResponse({ + status: 400, + description: 'Bad Request', + }) + @ApiInternalServerErrorResponse({ + status: 500, + description: 'Internal server error', + }) @Put('/:id') async updateUser( @Param('id') id: string, @@ -97,7 +109,7 @@ export class UserController { editUserDTO, ); return res.json({ - msg: 'user successfully', + msg: i18n()['message.user.update'], user: updateUser, }); } diff --git a/src/user/services/user/user.service.ts b/src/user/services/user/user.service.ts index bd11e22..239bcf6 100644 --- a/src/user/services/user/user.service.ts +++ b/src/user/services/user/user.service.ts @@ -7,10 +7,11 @@ import { PrismaService } from 'src/database/prisma.service'; import { TUser } from 'src/user/ultils/types'; import { User } from '@prisma/client'; import { SendEmailService } from 'src/send-email/service/send-email/send-email.service'; -import { Errors } from 'src/helpers/errors'; import { HashService } from 'src/hash/service/hash/hash.service'; import { LoggerService } from 'src/logger/logger.service'; +import { i18n } from 'src/i18n'; + @Injectable() export class UserService { constructor( @@ -35,7 +36,7 @@ export class UserService { return user; } catch (error) { if (error instanceof NotFoundException) { - throw new NotFoundException(Errors.RESOURCE_NOT_FOUND, user_id); + throw new ConflictException(i18n()['message.user.notFound'], user_id); } throw new Error( @@ -59,7 +60,7 @@ export class UserService { return user; } catch (error) { if (error instanceof ConflictException) { - throw new ConflictException(Errors.RESOURCE_ALREADY_EXISTS, email); + throw new ConflictException(i18n()['message.user.conflict'], email); } this.logger.error(`some error ocurred : ${error.message}`); @@ -69,6 +70,7 @@ export class UserService { async createUser(user: TUser): Promise { try { + this.logger.warn('virify if user already exist'); await this.findUserByEmail(user.email); const hashPassword = await this.hash.generateHash(user.password); @@ -79,6 +81,7 @@ export class UserService { }, }); + this.logger.log('send email to confirm account...'); await this.sendEmail.sendEmailService(createNewUser.email); return createNewUser; diff --git a/tsconfig.json b/tsconfig.json index 95f5641..e5389db 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,35 @@ { "compilerOptions": { + "lib": ["ES2023"], "module": "commonjs", - "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, + "target": "ES2022", "allowSyntheticDefaultImports": true, - "target": "ES2021", - "sourceMap": true, + "removeComments": true, + "noImplicitAny": false, "outDir": "./dist", "baseUrl": "./", - "incremental": true, + "sourceMap": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "forceConsistentCasingInFileNames": true, + "alwaysStrict": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "strictBindCallApply": true, + "noPropertyAccessFromIndexSignature": false, + "noUncheckedIndexedAccess": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noImplicitUseStrict": false, "skipLibCheck": true, - "strictNullChecks": false, - "noImplicitAny": false, - "strictBindCallApply": false, - "forceConsistentCasingInFileNames": false, - "noFallthroughCasesInSwitch": false + "incremental": true, + "typeRoots": ["./@types", "./node_modules/@types"], + "types": ["node", "jest"] } }