fix: auth related error

This commit is contained in:
Methapon Metanipat 2024-10-29 15:47:10 +07:00
parent 719a1fb70e
commit 0d6d44f20b

View file

@ -210,6 +210,7 @@ export class PaymentController extends Controller {
} }
@Get() @Get()
@Security("keycloak")
async listAttachment(@Request() req: RequestWithUser, @Path() paymentId: string) { async listAttachment(@Request() req: RequestWithUser, @Path() paymentId: string) {
const { quotationId } = await this.checkPermission(req.user, paymentId); const { quotationId } = await this.checkPermission(req.user, paymentId);
return await listFile(fileLocation.quotation.payment(quotationId, paymentId)); return await listFile(fileLocation.quotation.payment(quotationId, paymentId));
@ -221,9 +222,16 @@ export class PaymentController extends Controller {
@Path() paymentId: string, @Path() paymentId: string,
@Path() name: string, @Path() name: string,
) { ) {
const { quotationId } = await this.checkPermission(req.user, paymentId); const data = await prisma.payment.findUnique({
where: { id: paymentId },
include: { invoice: true },
});
if (!data) throw notFoundError("Payment");
return req.res?.redirect( return req.res?.redirect(
await getPresigned("head", fileLocation.quotation.payment(quotationId, paymentId, name)), await getPresigned(
"head",
fileLocation.quotation.payment(data.invoice.quotationId, paymentId, name),
),
); );
} }
@ -233,9 +241,13 @@ export class PaymentController extends Controller {
@Path() paymentId: string, @Path() paymentId: string,
@Path() name: string, @Path() name: string,
) { ) {
const { quotationId } = await this.checkPermission(req.user, paymentId); const data = await prisma.payment.findUnique({
where: { id: paymentId },
include: { invoice: true },
});
if (!data) throw notFoundError("Payment");
return req.res?.redirect( return req.res?.redirect(
await getFile(fileLocation.quotation.payment(quotationId, paymentId, name)), await getFile(fileLocation.quotation.payment(data.invoice.quotationId, paymentId, name)),
); );
} }