feat: add attachment endpoints for credit note
This commit is contained in:
parent
5c3dc9abcd
commit
a3735abb78
2 changed files with 66 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import {
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Head,
|
||||||
Path,
|
Path,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
|
@ -23,6 +24,7 @@ import {
|
||||||
} from "../services/permission";
|
} from "../services/permission";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { CreditNotePaybackType, CreditNoteStatus, Prisma } from "@prisma/client";
|
import { CreditNotePaybackType, CreditNoteStatus, Prisma } from "@prisma/client";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot } from "../utils/relation";
|
||||||
|
|
@ -548,3 +550,64 @@ export class CreditNoteActionController extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Route("api/v1/credit-note/{creditNoteId}")
|
||||||
|
@Tags("Credit Note")
|
||||||
|
export class CreditNoteAttachmentController extends Controller {
|
||||||
|
async #checkPermission(user: RequestWithUser["user"], id: string) {
|
||||||
|
const creditNoteData = await prisma.creditNote.findFirst({
|
||||||
|
where: { id },
|
||||||
|
include: {
|
||||||
|
requestWork: true,
|
||||||
|
quotation: {
|
||||||
|
include: {
|
||||||
|
registeredBranch: { include: branchRelationPermInclude(user) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!creditNoteData) throw notFoundError("Credit Note");
|
||||||
|
await permissionCheck(user, creditNoteData.quotation.registeredBranch);
|
||||||
|
return creditNoteData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("attachment")
|
||||||
|
@Security("keycloak")
|
||||||
|
async listAttachment(@Request() req: RequestWithUser, @Path() creditNoteId: string) {
|
||||||
|
await this.#checkPermission(req.user, creditNoteId);
|
||||||
|
return await listFile(fileLocation.creditNote.attachment(creditNoteId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("attachment/{name}")
|
||||||
|
@Security("keycloak")
|
||||||
|
async getAttachment(@Path() creditNoteId: string, @Path() name: string) {
|
||||||
|
return await getFile(fileLocation.creditNote.attachment(creditNoteId, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Head("attachment/{name}")
|
||||||
|
async headAttachment(@Path() creditNoteId: string, @Path() name: string) {
|
||||||
|
return await getPresigned("head", fileLocation.creditNote.attachment(creditNoteId, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put("attachment/{name}")
|
||||||
|
@Security("keycloak")
|
||||||
|
async putAttachment(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() creditNoteId: string,
|
||||||
|
@Path() name: string,
|
||||||
|
) {
|
||||||
|
await this.#checkPermission(req.user, creditNoteId);
|
||||||
|
return await setFile(fileLocation.creditNote.attachment(creditNoteId, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("attachment/{name}")
|
||||||
|
@Security("keycloak")
|
||||||
|
async delAttachment(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() creditNoteId: string,
|
||||||
|
@Path() name: string,
|
||||||
|
) {
|
||||||
|
await this.#checkPermission(req.user, creditNoteId);
|
||||||
|
return await deleteFile(fileLocation.creditNote.attachment(creditNoteId, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,4 +112,7 @@ export const fileLocation = {
|
||||||
task: {
|
task: {
|
||||||
attachment: (taskId: string, name?: string) => `task/attachment-${taskId}/${name || ""}`,
|
attachment: (taskId: string, name?: string) => `task/attachment-${taskId}/${name || ""}`,
|
||||||
},
|
},
|
||||||
|
creditNote: {
|
||||||
|
attachment: (taskId: string, name?: string) => `credit-note/attachment-${taskId}/${name || ""}`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue