Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/delete task #45

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1ccf235
feat: add delete task
lauanegcsilva Jan 30, 2024
e2585ef
fix: change httcode and add messagem
lauanegcsilva Jan 30, 2024
1cb5633
feat: add delete task endpoint
lauanegcsilva Jan 30, 2024
91b0c56
refactor: delete task
Kauanedev Mar 13, 2024
071c298
Merge branch 'develop' of github.com:loryblu/loryblu-api into feat/de…
Kauanedev Mar 14, 2024
63f6e4d
chore: set-up rest
Kauanedev Mar 19, 2024
d4a7aeb
chore: update rest
Kauanedev Mar 20, 2024
bdca173
docs: update prisma
Kauanedev Mar 20, 2024
ca8ceae
feat: delete task
Kauanedev Mar 20, 2024
1d31317
ci: node version
viniciuscosmome Mar 21, 2024
9f110bd
fix: fix modules version
viniciuscosmome Mar 21, 2024
6ab8d2e
Merge pull request #48 from loryblu/ci/github-actions
viniciuscosmome Mar 21, 2024
1ca16e8
chore: update yarn.lock
Kauanedev Mar 21, 2024
055f443
refactor: update deleteTask func
Kauanedev Apr 5, 2024
d5471f4
fix: update types of Delete Task
Daaaiii May 9, 2024
0a3d422
fix: remove unnecessary code
Daaaiii May 9, 2024
7870d59
feat: add children Id on get task payload
Daaaiii May 9, 2024
4a583d4
fix: update childrenId on Get tasks response
Daaaiii May 9, 2024
490d68a
fix: remove unnecessary code
Daaaiii May 9, 2024
7a7241e
fix: add await
Daaaiii May 9, 2024
ac9998f
feat: add check to verify if task belong to child
Daaaiii May 9, 2024
c712921
fix: change search method to findUnique
Daaaiii May 9, 2024
af63231
fix: update response message on delete task
Daaaiii May 9, 2024
35d3341
fix: add children id to query
Daaaiii Jun 5, 2024
32b4a9b
fix: add childrenId to DeleteTaskDto
Daaaiii Jun 5, 2024
55a2f7c
fix: update task entity types to use number instead of string for tas…
Daaaiii Jun 5, 2024
9e0d02d
fix: Update deleteTask method parameter name to taskId
Daaaiii Jun 5, 2024
bed88b6
fix: Update deleteTask method parameter name to taskId
Daaaiii Jun 5, 2024
6774b5a
fix: remove parent validation func
Kauanedev Jul 3, 2024
5373258
feat: add parentId at findTaskByIdAndChildren
Kauanedev Jul 3, 2024
98e27e9
feat: add exist parent validation
Kauanedev Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/globals/entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type EncryptDataAsyncProps = {
salt: number;
};

type DeleteHandler = (id: string, request: Request) => Promise<void>;
Daaaiii marked this conversation as resolved.
Show resolved Hide resolved

export type ApiResponses = {
ok: ApiResponseOptions;
created: ApiResponseOptions;
Expand Down
23 changes: 23 additions & 0 deletions src/modules/task/task.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
Body,
Controller,
Delete,
Get,
HttpCode,
Param,
Patch,
Post,
Query,
Expand Down Expand Up @@ -107,4 +109,25 @@ export class TaskController {
message: 'Tarefas atualizadas',
};
}

@RequestToken({ type: 'access', role: 'user' })
@Delete(':id')
@HttpCode(200)
@ApiResponse(responses.badRequest)
@ApiResponse(responses.unauthorized)
@ApiResponse(responses.forbidden)
@ApiResponse(responses.unprocessable)
@ApiResponse(responses.internalError)
async delete(@Param('id') id: string, @Req() request: Request) {
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
const sessionInfo = request[sessionPayloadKey] as iAuthTokenPayload;

await this.service.deleteTask({
id: id,
parentId: sessionInfo.pid,
});

return {
message: 'Tarefa excluída',
};
}
}
41 changes: 39 additions & 2 deletions src/modules/task/task.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import { handleErrors } from 'src/globals/errors';
import {
Expand All @@ -25,7 +25,7 @@ export class TaskRepository {
parentId: parentId,
},
frequency: {
hasSome: frequency,
hasSome: Array.isArray(frequency) ? frequency : [frequency],
},
Daaaiii marked this conversation as resolved.
Show resolved Hide resolved
},
select: {
Expand Down Expand Up @@ -101,4 +101,41 @@ export class TaskRepository {
})
.catch((error) => handleErrors(error));
}

async findTaskById(id: string, parentId: string) {
// Adicione a lógica para encontrar a tarefa pelo ID e parentId
return this.prisma.task.findFirst({
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
where: {
id: parseInt(id),
children: {
parentId: parentId,
},
},
});
}

Daaaiii marked this conversation as resolved.
Show resolved Hide resolved
async deleteTask(id: string, parentId: string) {
// Verifique se a tarefa existe antes de tentar excluí-la
const existingTask = await this.prisma.task.findFirst({
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
where: {
id: parseInt(id),
children: {
parentId: parentId,
},
},
});

if (!existingTask) {
throw new NotFoundException(`Tarefa com ID ${id} não encontrada.`);
}

Daaaiii marked this conversation as resolved.
Show resolved Hide resolved
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
// Exclua a tarefa
await this.prisma.task
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
.delete({
where: {
id: parseInt(id),
},
})
.catch((error) => handleErrors(error));
}
}
12 changes: 11 additions & 1 deletion src/modules/task/task.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { TaskRepository } from './task.repository';
import {
iTaskRepositoryInput,
Expand Down Expand Up @@ -42,6 +42,16 @@ export class TaskService {
await this.repository.updateTask(input);
}

async deleteTask({ id, parentId }: { id: string; parentId: string }) {
const existingTask = await this.repository.findTaskById(id, parentId);
Daaaiii marked this conversation as resolved.
Show resolved Hide resolved
if (!existingTask) {
throw new NotFoundException(`Tarefa com ID ${id} não encontrada.`);
}
Daaaiii marked this conversation as resolved.
Show resolved Hide resolved

// Implemente a lógica de exclusão no seu repositório
await this.repository.deleteTask(id, parentId);
viniciuscosmome marked this conversation as resolved.
Show resolved Hide resolved
}

private processTasks(
result: object,
currentItem: iTaskRepositoryReadManyOutput,
Expand Down
Loading
Loading