mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 13:47:57 +00:00
feat: tasks jounrey
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './task.controller';
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Post, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { AllowedRoles, AuthenticatedUser } from '~/common/decorators';
|
||||
import { AccessTokenGuard, RolesGuard } from '~/common/guards';
|
||||
import { CustomParseUUIDPipe } from '~/core/pipes';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { CreateTaskRequestDto, TaskSubmissionRequestDto } from '../dtos/request';
|
||||
import { TasksFilterOptions } from '../dtos/request/tasks-filter-options.request.dto';
|
||||
import { TaskResponseDto } from '../dtos/response';
|
||||
import { TaskService } from '../services';
|
||||
|
||||
@Controller('tasks')
|
||||
@ApiTags('Tasks')
|
||||
@ApiBearerAuth()
|
||||
export class TaskController {
|
||||
constructor(private readonly taskService: TaskService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
async createTask(@AuthenticatedUser() { sub }: IJwtPayload, @Body() body: CreateTaskRequestDto) {
|
||||
const task = await this.taskService.createTask(sub, body);
|
||||
return ResponseFactory.data(new TaskResponseDto(task));
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AccessTokenGuard)
|
||||
async findTasks(@Query() query: TasksFilterOptions, @AuthenticatedUser() user: IJwtPayload) {
|
||||
const [tasks, itemCount] = await this.taskService.findTasks(user, query);
|
||||
return ResponseFactory.dataPage(
|
||||
tasks.map((task) => new TaskResponseDto(task)),
|
||||
{
|
||||
page: query.page,
|
||||
size: query.size,
|
||||
itemCount,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Patch(':taskId/submit')
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.JUNIOR)
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async submitTask(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('taskId', CustomParseUUIDPipe) taskId: string,
|
||||
@Body() body: TaskSubmissionRequestDto,
|
||||
) {
|
||||
await this.taskService.submitTask(sub, taskId, body);
|
||||
}
|
||||
|
||||
@Patch(':taskId/approve')
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async approveTaskSubmission(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('taskId', CustomParseUUIDPipe) taskId: string,
|
||||
) {
|
||||
await this.taskService.approveTaskSubmission(sub, taskId);
|
||||
}
|
||||
|
||||
@Patch(':taskId/reject')
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async rejectTaskSubmission(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('taskId', CustomParseUUIDPipe) taskId: string,
|
||||
) {
|
||||
await this.taskService.rejectTaskSubmission(sub, taskId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user