Skip to content

Commit

Permalink
feat: add check to verify if task belong to child
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaiii committed May 9, 2024
1 parent 7a7241e commit ac9998f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/modules/task/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class TaskController {
await this.service.deleteTask({
id: id,
parentId: sessionInfo.pid,
childrenId: sessionInfo.cid,
});

return {
Expand Down
1 change: 1 addition & 0 deletions src/modules/task/task.entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ export type iTaskRepositoryUpadateInput = {
export type iTaskRepositoryDeleteTaskInput = {
id: string;
parentId: string;
childrenId: string;
};
3 changes: 2 additions & 1 deletion src/modules/task/task.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ export class TaskRepository {
.catch((error) => handleErrors(error));
}

async findTaskById(id: number) {
async findTaskByIdAndChildren(id: number, childrenId: number) {
return await this.prisma.task.findFirst({
where: {
id,
childrenId,
},
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/modules/task/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export class TaskService {
}

async deleteTask(input: iTaskRepositoryDeleteTaskInput) {
const idNumber = parseInt(input.id);
const taskId = parseInt(input.id);
const childrenId = parseInt(input.childrenId);

const existingTask = await this.repository.findTaskById(idNumber);
const existingTask = await this.repository.findTaskByIdAndChildren(
taskId,
childrenId,
);
const parent = await this.repository.validateParent(input.parentId);

if (!existingTask) {
Expand All @@ -60,7 +64,7 @@ export class TaskService {
);
}

await this.repository.deleteTask(idNumber);
await this.repository.deleteTask(taskId);
}

private processTasks(
Expand Down

0 comments on commit ac9998f

Please sign in to comment.