mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 10:26:16 +00:00
feat: add find task by id endpoint
This commit is contained in:
@ -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)
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user