feat: add find task by id endpoint

This commit is contained in:
Abdalhamid Alhamad
2025-01-13 14:15:29 +03:00
parent 62621c1a15
commit 221f3bae4f
7 changed files with 406 additions and 66 deletions

View File

@ -41,6 +41,13 @@ export class TaskController {
);
}
@Get(':taskId')
@UseGuards(AccessTokenGuard)
async findTask(@Param('taskId', CustomParseUUIDPipe) taskId: string, @AuthenticatedUser() user: IJwtPayload) {
const task = await this.taskService.findTaskForUser(taskId, user);
return ResponseFactory.data(new TaskResponseDto(task));
}
@Patch(':taskId/submit')
@UseGuards(RolesGuard)
@AllowedRoles(Roles.JUNIOR)

View File

@ -1,6 +1,7 @@
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import moment from 'moment';
import { FindOptionsWhere } from 'typeorm';
import { Roles } from '~/auth/enums';
import { IJwtPayload } from '~/auth/interfaces';
import { DocumentService, OciService } from '~/document/services';
import { CreateTaskRequestDto, TasksFilterOptions, TaskSubmissionRequestDto } from '../dtos/request';
@ -35,6 +36,16 @@ export class TaskService {
return this.findTask({ id: task.id });
}
findTaskForUser(taskId: string, user: IJwtPayload) {
this.logger.log(`Finding task ${taskId} for user ${user.sub}`);
return this.findTask({
id: taskId,
assignedById: user.roles.includes(Roles.GUARDIAN) ? user.sub : undefined,
assignedToId: user.roles.includes(Roles.JUNIOR) ? user.sub : undefined,
});
}
async findTask(where: FindOptionsWhere<Task>) {
this.logger.log(`Finding task with where ${JSON.stringify(where)}`);
const task = await this.taskRepository.findTask(where);