refactor: move field lineId contact field

This commit is contained in:
Methapon2001 2024-04-17 11:23:20 +07:00
parent ddb2155c44
commit 155bb19b9b

View file

@ -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,