fix: error when update record not found

This commit is contained in:
Methapon2001 2024-04-18 13:09:53 +07:00
parent 208aa77efd
commit cb5d7ae208

View file

@ -134,6 +134,10 @@ export class CustomerController extends Controller {
@Request() req: RequestWithUser,
@Body() body: CustomerUpdate,
) {
if (!(await prisma.customer.findUnique({ where: { id: customerId } }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
}
const record = await prisma.customer.update({
where: { id: customerId },
data: {
@ -143,10 +147,6 @@ export class CustomerController extends Controller {
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.");
}
return Object.assign(record, {
imageUrl: await minio.presignedGetObject(
MINIO_BUCKET,