-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from hebertsanto/feature-task-list-project
feat : add feature to add tasks in project
- Loading branch information
Showing
9 changed files
with
246 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
117 changes: 114 additions & 3 deletions
117
src/task-list-project/controller/task-list-project/task-list-project.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
71 changes: 69 additions & 2 deletions
71
src/task-list-project/service/task-list-project/task-list-project.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TaskListProject | null> => { | ||
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<void> => { | ||
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<TaskListProject | null> => { | ||
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Priority } from '@prisma/client'; | ||
|
||
export type TaskListProject = { | ||
title: string; | ||
description: string; | ||
priority: Priority; | ||
userId: string; | ||
projectId: string; | ||
}; |