เพิ่้มและลบ api history/user

This commit is contained in:
AdisakKanthawilang 2024-05-28 09:30:14 +07:00
parent abc4aee8a4
commit 8d1de6365a
22 changed files with 512 additions and 466 deletions

View file

@ -134,6 +134,38 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const family = await this.familyHistoryRepo.find({
order: { lastUpdatedAt: "DESC" },
where: {
profileEmployeeId: profile.id,
},
});
family.shift();
const record = await Promise.all(
family.map(async (v) => ({
...v,
children: await this.childrenHistoryRepo.find({
order: { createdAt: "ASC" },
}),
})),
);
return new HttpSuccess(record);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,