fix update prefix and profileId
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m45s

This commit is contained in:
Warunee Tamkoo 2026-02-27 15:24:51 +07:00
parent e4f46a1762
commit 2951630b7b
10 changed files with 201 additions and 69 deletions

View file

@ -5092,7 +5092,12 @@ export class ProfileController extends Controller {
// setLogDataDiff(request, { before, after: record });
if (record != null && record.keycloak != null) {
const result = await updateName(record.keycloak, record.firstName, record.lastName);
const result = await updateName(
record.keycloak,
record.firstName,
record.lastName,
record.prefix,
);
if (!result) {
throw new Error(result.errorMessage);
}
@ -5406,7 +5411,12 @@ export class ProfileController extends Controller {
setLogDataDiff(request, { before, after: record });
if (record != null && record.keycloak != null) {
const result = await updateName(record.keycloak, record.firstName, record.lastName);
const result = await updateName(
record.keycloak,
record.firstName,
record.lastName,
record.prefix,
);
if (!result) {
throw new Error(result.errorMessage);
}
@ -5507,27 +5517,27 @@ export class ProfileController extends Controller {
@Get("history/user")
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }
where: { keycloak: request.user.sub },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profileHistory = await this.profileHistoryRepo.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" }
order: { createdAt: "ASC" },
});
if (profileHistory.length == 0) {
await this.profileHistoryRepo.save(
Object.assign(new ProfileHistory(), {
...profile,
birthDateOld: profile?.birthDate,
profileId: profile.id,
id: undefined
id: undefined,
}),
);
const firstRecord = await this.profileHistoryRepo.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" }
order: { createdAt: "ASC" },
});
return new HttpSuccess(firstRecord);
}
@ -6482,27 +6492,27 @@ export class ProfileController extends Controller {
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
//await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id); //ไม่แน่ใจOFFปิดไว้ก่อน
const profile = await this.profileRepo.findOne({
where: { id: id }
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profileHistory = await this.profileHistoryRepo.find({
where: { profileId: id },
order: { createdAt: "ASC" }
order: { createdAt: "ASC" },
});
if (profileHistory.length == 0) {
await this.profileHistoryRepo.save(
Object.assign(new ProfileHistory(), {
...profile,
birthDateOld: profile?.birthDate,
profileId: id,
id: undefined
id: undefined,
}),
);
const firstRecord = await this.profileHistoryRepo.find({
where: { profileId: id },
order: { createdAt: "ASC" }
order: { createdAt: "ASC" },
});
return new HttpSuccess(firstRecord);
}