feat: add set image endpoints for employee
This commit is contained in:
parent
75359a8d4e
commit
d11fb007b3
1 changed files with 28 additions and 0 deletions
|
|
@ -783,7 +783,35 @@ export class EmployeeController extends Controller {
|
|||
where: { masterId: employeeId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("{employeeId}/image")
|
||||
async getImageByEmployeeId(@Request() req: RequestWithUser, @Path() employeeId: string) {
|
||||
const url = await presignedGetObjectIfExist(MINIO_BUCKET, imageLocation(employeeId), 60 * 60);
|
||||
|
||||
if (!url) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Image cannot be found", "imageNotFound");
|
||||
}
|
||||
|
||||
return req.res?.redirect(url);
|
||||
}
|
||||
|
||||
@Put("{employeeId}/image")
|
||||
@Security("keycloak", MANAGE_ROLES)
|
||||
async setImageByEmployeeId(@Request() req: RequestWithUser, @Path() employeeId: string) {
|
||||
const record = await prisma.employee.findFirst({
|
||||
where: { id: employeeId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "employeeNotFound");
|
||||
}
|
||||
|
||||
return req.res?.redirect(
|
||||
await minio.presignedPutObject(MINIO_BUCKET, imageLocation(employeeId), 12 * 60 * 60),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Route("api/v1/employee/{employeeId}/attachment")
|
||||
@Tags("Employee")
|
||||
@Security("keycloak")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue