Skip to content

Commit

Permalink
Merge pull request #14 from hebertsanto/feature-task-list-project
Browse files Browse the repository at this point in the history
feat : add feature to add tasks in project
  • Loading branch information
hebertzin authored Apr 2, 2024
2 parents 5e884ea + 5aec3b0 commit d9dcd0a
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 6 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
2 changes: 2 additions & 0 deletions src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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,
Expand All @@ -24,4 +25,5 @@ export default {
...Updates,
...Decisions,
...FollowProject,
...TaskList,
};
8 changes: 8 additions & 0 deletions src/i18n/en/tasklist-messages.json
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"
}
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,
});
}
}
24 changes: 24 additions & 0 deletions src/task-list-project/dtos/index.ts
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;
}
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;
};
}
10 changes: 9 additions & 1 deletion src/task-list-project/task-list-project.module.ts
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 {}
9 changes: 9 additions & 0 deletions src/task-list-project/types/index.ts
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;
};

0 comments on commit d9dcd0a

Please sign in to comment.