mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-26 06:09:41 +00:00
fix: fix tasks submission journey
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import moment from 'moment';
|
||||
import { FindOptionsWhere } from 'typeorm';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { OciService } from '~/document/services';
|
||||
@ -11,6 +12,13 @@ import { TaskRepository } from '../repositories';
|
||||
export class TaskService {
|
||||
constructor(private readonly taskRepository: TaskRepository, private readonly ociService: OciService) {}
|
||||
async createTask(userId: string, body: CreateTaskRequestDto) {
|
||||
if (moment(body.dueDate).isBefore(moment(body.startDate))) {
|
||||
throw new BadRequestException('TASK.DUE_DATE_BEFORE_START_DATE');
|
||||
}
|
||||
|
||||
if (moment(body.dueDate).isBefore(moment())) {
|
||||
throw new BadRequestException('TASK.DUE_DATE_IN_PAST');
|
||||
}
|
||||
const task = await this.taskRepository.createTask(userId, body);
|
||||
return this.findTask({ id: task.id });
|
||||
}
|
||||
@ -22,12 +30,14 @@ export class TaskService {
|
||||
throw new BadRequestException('TASK.NOT_FOUND');
|
||||
}
|
||||
|
||||
await this.prepareTasksPictures([task]);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
async findTasks(user: IJwtPayload, query: TasksFilterOptions): Promise<[Task[], number]> {
|
||||
const [tasks, count] = await this.taskRepository.findTasks(user, query);
|
||||
|
||||
console.log(tasks);
|
||||
await this.prepareTasksPictures(tasks);
|
||||
|
||||
return [tasks, count];
|
||||
@ -53,7 +63,7 @@ export class TaskService {
|
||||
throw new BadRequestException('TASK.NO_SUBMISSION');
|
||||
}
|
||||
|
||||
if (task.submission.status !== SubmissionStatus.PENDING) {
|
||||
if (task.submission.status == SubmissionStatus.APPROVED) {
|
||||
throw new BadRequestException('TASK.SUBMISSION_ALREADY_REVIEWED');
|
||||
}
|
||||
|
||||
@ -67,7 +77,7 @@ export class TaskService {
|
||||
throw new BadRequestException('TASK.NO_SUBMISSION');
|
||||
}
|
||||
|
||||
if (task.submission.status !== SubmissionStatus.PENDING) {
|
||||
if (task.submission.status == SubmissionStatus.REJECTED) {
|
||||
throw new BadRequestException('TASK.SUBMISSION_ALREADY_REVIEWED');
|
||||
}
|
||||
|
||||
@ -85,7 +95,7 @@ export class TaskService {
|
||||
|
||||
task.image.url = imageUrl;
|
||||
|
||||
if (task.submission) {
|
||||
if (task.submission?.proofOfCompletion) {
|
||||
task.submission.proofOfCompletion.url = submissionUrl;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user