feat: add branch bank qr
This commit is contained in:
parent
ef735bd9d7
commit
a8ad8e37d4
1 changed files with 63 additions and 0 deletions
|
|
@ -745,4 +745,67 @@ export class BranchController extends Controller {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("{branchId}/bank-qr/{bankId}")
|
||||||
|
async getBankQRByBranchIdAndBankId(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() branchId: string,
|
||||||
|
@Path() bankId: string,
|
||||||
|
) {
|
||||||
|
const url = await presignedGetObjectIfExist(
|
||||||
|
MINIO_BUCKET,
|
||||||
|
fileLocation.branch.bank(branchId, bankId),
|
||||||
|
60 * 60,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "Image cannot be found", "imageNotFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
return req.res?.redirect(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put("{branchId}/bank-qr/{bankId}")
|
||||||
|
async setBankQRByBranchIdAndBankId(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() branchId: string,
|
||||||
|
@Path() bankId: string,
|
||||||
|
) {
|
||||||
|
const record = await prisma.branch.findUnique({
|
||||||
|
include: {
|
||||||
|
user: { where: { userId: req.user.sub } },
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: branchId,
|
||||||
|
bank: { some: { id: bankId } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
"Branch Bank cannot be found.",
|
||||||
|
"branchBankNotFound",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!MANAGE_ROLES.some((v) => req.user.roles?.includes(v)) &&
|
||||||
|
!record?.user.find((v) => v.userId === req.user.sub)
|
||||||
|
) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.FORBIDDEN,
|
||||||
|
"You do not have permission to perform this action.",
|
||||||
|
"noPermission",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return req.res?.redirect(
|
||||||
|
await minio.presignedPutObject(
|
||||||
|
MINIO_BUCKET,
|
||||||
|
fileLocation.branch.bank(branchId, bankId),
|
||||||
|
12 * 60 * 60,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue