diff --git a/src/controllers/branch-controller.ts b/src/controllers/branch-controller.ts index d755ea8..97196d1 100644 --- a/src/controllers/branch-controller.ts +++ b/src/controllers/branch-controller.ts @@ -36,6 +36,7 @@ type BranchCreate = { zipCode: string; email: string; telephoneNo: string; + lineId: string; longitude: string; latitude: string; @@ -55,6 +56,7 @@ type BranchUpdate = { zipCode?: string; email?: string; telephoneNo?: string; + lineId?: string; longitude?: string; latitude?: string; @@ -64,6 +66,10 @@ type BranchUpdate = { headOfficeId?: string | null; }; +function lineImageLoc(id: string) { + return `branch/line-qr-${id}`; +} + @Route("api/branch") @Tags("Branch") @Security("keycloak") @@ -273,7 +279,18 @@ export class BranchController extends Controller { this.setStatus(HttpStatus.CREATED); - return record; + return Object.assign(record, { + qrCodeImageUrl: await minio.presignedGetObject( + MINIO_BUCKET, + lineImageLoc(record.id), + 12 * 60 * 60, + ), + qrCodeImageUploadUrl: await minio.presignedPutObject( + MINIO_BUCKET, + lineImageLoc(record.id), + 12 * 60 * 60, + ), + }); } @Put("{branchId}") @@ -354,7 +371,18 @@ export class BranchController extends Controller { where: { id: branchId }, }); - return record; + return Object.assign(record, { + qrCodeImageUrl: await minio.presignedGetObject( + MINIO_BUCKET, + lineImageLoc(record.id), + 12 * 60 * 60, + ), + qrCodeImageUploadUrl: await minio.presignedPutObject( + MINIO_BUCKET, + lineImageLoc(record.id), + 12 * 60 * 60, + ), + }); } @Delete("{branchId}") @@ -376,6 +404,10 @@ export class BranchController extends Controller { throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "data_in_used"); } + await minio.removeObject(MINIO_BUCKET, lineImageLoc(branchId), { + forceDelete: true, + }); + return await prisma.branch.delete({ include: { province: true,