feat: add task file upload
This commit is contained in:
parent
88034cf064
commit
2e0cb7661d
1 changed files with 52 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import {
|
|||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Head,
|
||||
Path,
|
||||
Post,
|
||||
Put,
|
||||
|
|
@ -23,6 +24,7 @@ import {
|
|||
} from "../services/permission";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||
|
||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "document_checker"];
|
||||
|
||||
|
|
@ -378,4 +380,53 @@ export class TaskActionController extends Controller {
|
|||
|
||||
@Route("api/v1/task-order/{taskId}")
|
||||
@Tags("Task Order")
|
||||
export class TaskOrderAttachmentController extends Controller {}
|
||||
export class TaskOrderAttachmentController extends Controller {
|
||||
private async checkPermission(user: RequestWithUser["user"], id: string) {
|
||||
const data = await prisma.taskOrder.findUnique({
|
||||
include: { registeredBranch: { include: branchRelationPermInclude(user) } },
|
||||
where: { id },
|
||||
});
|
||||
if (!data) throw notFoundError("Branch");
|
||||
await permissionCheck(user, data.registeredBranch);
|
||||
}
|
||||
@Get("attachment")
|
||||
@Security("keycloak")
|
||||
async listAttachment(@Request() req: RequestWithUser, @Path() taskId: string) {
|
||||
await this.checkPermission(req.user, taskId);
|
||||
return await listFile(fileLocation.task.attachment(taskId));
|
||||
}
|
||||
|
||||
@Get("attachment/{name}")
|
||||
@Security("keycloak")
|
||||
async getAttachment(@Path() taskId: string, @Path() name: string) {
|
||||
return await getFile(fileLocation.task.attachment(taskId, name));
|
||||
}
|
||||
|
||||
@Head("attachment/{name}")
|
||||
@Security("keycloak")
|
||||
async headAttachment(@Path() taskId: string, @Path() name: string) {
|
||||
return await getPresigned("head", fileLocation.task.attachment(taskId, name));
|
||||
}
|
||||
|
||||
@Put("attachment/{name}")
|
||||
@Security("keycloak")
|
||||
async putAttachment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() taskId: string,
|
||||
@Path() name: string,
|
||||
) {
|
||||
await this.checkPermission(req.user, taskId);
|
||||
return await setFile(fileLocation.task.attachment(taskId, name));
|
||||
}
|
||||
|
||||
@Delete("attachment/{name}")
|
||||
@Security("keycloak")
|
||||
async delAttachment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() taskId: string,
|
||||
@Path() name: string,
|
||||
) {
|
||||
await this.checkPermission(req.user, taskId);
|
||||
return await deleteFile(fileLocation.task.attachment(taskId, name));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue