feat(customer): image endpoint get or upload
This commit is contained in:
parent
b2c31774f2
commit
0e411ad5d0
1 changed files with 29 additions and 0 deletions
|
|
@ -573,4 +573,33 @@ export class CustomerController extends Controller {
|
|||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
@Get("{customerId}/image")
|
||||
async getCustomerImageById(@Request() req: RequestWithUser, @Path() customerId: string) {
|
||||
const url = await presignedGetObjectIfExist(MINIO_BUCKET, imageLocation(customerId), 60 * 60);
|
||||
|
||||
if (!url) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Image cannot be found", "imageNotFound");
|
||||
}
|
||||
|
||||
return req.res?.redirect(url);
|
||||
}
|
||||
|
||||
@Put("{customerId}/image")
|
||||
@Security("keycloak", MANAGE_ROLES)
|
||||
async setCustomerImageById(@Request() req: RequestWithUser, @Path() customerId: string) {
|
||||
const record = await prisma.customer.findFirst({
|
||||
where: {
|
||||
id: customerId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound");
|
||||
}
|
||||
|
||||
return req.res?.redirect(
|
||||
await minio.presignedPutObject(MINIO_BUCKET, imageLocation(customerId), 12 * 60 * 60),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue