เพิ่้มและลบ 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

@ -98,6 +98,47 @@ export class ProfileFamilyFatherController extends Controller {
return new HttpSuccess(familyFather);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyFatherHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profile.id },
});
const mapData = familyFather
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileId}")
@Example({
status: 200,