feat: edit branch endpoint

This commit is contained in:
Methapon2001 2024-04-02 15:21:19 +07:00
parent e58141b864
commit 63de7b3e52

View file

@ -70,6 +70,35 @@ export class BranchContactController extends Controller {
});
}
@Patch("{contactId}")
async editBranchContact(
@Request() req: RequestWithUser,
@Body() body: BranchContactUpdate,
@Path() branchId: string,
@Path() contactId: string,
) {
const record = await prisma.branchContact.update({
include: { branch: true },
data: { ...body, updateBy: req.user.name },
where: { id: contactId, branchId },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.");
}
return Object.assign(record, {
qrCodeImageUrl: await minio.presignedGetObject(
MINIO_BUCKET,
imageLocation(record.id),
12 * 60 * 60,
),
qrCodeImageUploadUrl: await minio.presignedPutObject(
MINIO_BUCKET,
imageLocation(record.id),
12 * 60 * 60,
),
});
}
@Delete("{contactId}")
async deleteBranchContact(@Path() branchId: string, @Path() contactId: string) {
const result = await prisma.branchContact.deleteMany({ where: { id: contactId, branchId } });