feat: edit customer endpoint

This commit is contained in:
Methapon2001 2024-04-05 11:18:01 +07:00
parent 7bd3c2ebd3
commit ef88a48d0c

View file

@ -121,6 +121,39 @@ export class CustomerController extends Controller {
});
}
@Put("{customerId}")
async editById(
@Path() customerId: string,
@Request() req: RequestWithUser,
@Body() body: CustomerUpdate,
) {
const record = await prisma.customer.update({
where: { id: customerId },
data: {
...body,
createdBy: req.user.name,
updateBy: req.user.name,
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.");
}
return Object.assign(record, {
imageUrl: await minio.presignedGetObject(
MINIO_BUCKET,
imageLocation(record.id),
12 * 60 * 60,
),
imageUploadUrl: await minio.presignedPutObject(
MINIO_BUCKET,
imageLocation(record.id),
12 * 60 * 60,
),
});
}
@Delete("{customerId}")
async deleteById(@Path() customerId: string) {
const record = await prisma.customer.findFirst({ where: { id: customerId } });