feat: edit customer endpoint
This commit is contained in:
parent
7bd3c2ebd3
commit
ef88a48d0c
1 changed files with 33 additions and 0 deletions
|
|
@ -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}")
|
@Delete("{customerId}")
|
||||||
async deleteById(@Path() customerId: string) {
|
async deleteById(@Path() customerId: string) {
|
||||||
const record = await prisma.customer.findFirst({ where: { id: customerId } });
|
const record = await prisma.customer.findFirst({ where: { id: customerId } });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue