fix and add profile by key cloak

This commit is contained in:
AdisakKanthawilang 2024-05-24 18:06:54 +07:00
parent 7b480b1247
commit eb85bdcb45
5 changed files with 143 additions and 19 deletions

View file

@ -91,6 +91,48 @@ export class ProfileAddressController extends Controller {
return new HttpSuccess(getProfileAddress);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAddressHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAddressHistoryRepo.find({
where: { profileId: profile.id },
relations: {
registrationProvince: true,
registrationDistrict: true,
registrationSubDistrict: true,
currentProvince: true,
currentDistrict: true,
currentSubDistrict: true,
},
select: [
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"lastUpdateFullName",
"lastUpdatedAt",
],
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
/**
*
* @summary