mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
feat: working on signed url for private files
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { FindOptionsWhere } from 'typeorm';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { OciService } from '~/document/services';
|
||||
import { CreateTaskRequestDto, TasksFilterOptions, TaskSubmissionRequestDto } from '../dtos/request';
|
||||
import { Task } from '../entities';
|
||||
import { SubmissionStatus, TaskStatus } from '../enums';
|
||||
@ -8,7 +9,7 @@ import { TaskRepository } from '../repositories';
|
||||
|
||||
@Injectable()
|
||||
export class TaskService {
|
||||
constructor(private readonly taskRepository: TaskRepository) {}
|
||||
constructor(private readonly taskRepository: TaskRepository, private readonly ociService: OciService) {}
|
||||
async createTask(userId: string, body: CreateTaskRequestDto) {
|
||||
const task = await this.taskRepository.createTask(userId, body);
|
||||
return this.findTask({ id: task.id });
|
||||
@ -24,8 +25,12 @@ export class TaskService {
|
||||
return task;
|
||||
}
|
||||
|
||||
findTasks(user: IJwtPayload, query: TasksFilterOptions) {
|
||||
return this.taskRepository.findTasks(user, query);
|
||||
async findTasks(user: IJwtPayload, query: TasksFilterOptions): Promise<[Task[], number]> {
|
||||
const [tasks, count] = await this.taskRepository.findTasks(user, query);
|
||||
|
||||
await this.prepareTasksPictures(tasks);
|
||||
|
||||
return [tasks, count];
|
||||
}
|
||||
async submitTask(userId: string, taskId: string, body: TaskSubmissionRequestDto) {
|
||||
const task = await this.findTask({ id: taskId, assignedToId: userId });
|
||||
@ -68,4 +73,26 @@ export class TaskService {
|
||||
|
||||
await this.taskRepository.rejectSubmission(task.submission);
|
||||
}
|
||||
|
||||
async prepareTasksPictures(tasks: Task[]) {
|
||||
await Promise.all(
|
||||
tasks.map(async (task) => {
|
||||
const [imageUrl, submissionUrl, profilePictureUrl] = await Promise.all([
|
||||
this.ociService.generatePreSignedUrl(task.image),
|
||||
this.ociService.generatePreSignedUrl(task.submission?.proofOfCompletion),
|
||||
this.ociService.generatePreSignedUrl(task.assignedTo.customer.user.profilePicture),
|
||||
]);
|
||||
|
||||
task.image.url = imageUrl;
|
||||
|
||||
if (task.submission) {
|
||||
task.submission.proofOfCompletion.url = submissionUrl;
|
||||
}
|
||||
|
||||
if (task.assignedTo.customer.user.profilePicture) {
|
||||
task.assignedTo.customer.user.profilePicture.url = profilePictureUrl;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user