get ข้อมูล by keycloak
This commit is contained in:
parent
f6bcd35e14
commit
ff0be7af48
22 changed files with 633 additions and 137 deletions
|
|
@ -36,6 +36,31 @@ export class ProfileFamilyHistoryController extends Controller {
|
|||
private childrenRepo = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getFamilyHistoryUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { id: profile.id },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { id: profile.id },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
family.length > 0
|
||||
? {
|
||||
...family[0],
|
||||
children,
|
||||
}
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue