Insert ประวัติแก้ไขข้อมูลส่วนตัว กรณีแก้ไขครั้งแรก Task #2314
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m25s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m25s
This commit is contained in:
parent
4e396b454d
commit
673da9940d
3 changed files with 144 additions and 66 deletions
|
|
@ -2289,20 +2289,33 @@ export class ProfileEmployeeController extends Controller {
|
|||
*/
|
||||
@Get("history/user")
|
||||
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
|
||||
const historyProfile = await this.profileHistoryRepo.find({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
},
|
||||
where: { keycloak: request.user.sub },
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
},
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub }
|
||||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
if (!historyProfile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const profileHistory = await this.profileHistoryRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
order: { createdAt: "ASC" }
|
||||
});
|
||||
|
||||
if (profileHistory.length == 0) {
|
||||
await this.profileHistoryRepo.save(
|
||||
Object.assign(new ProfileEmployeeHistory(), {
|
||||
...profile,
|
||||
birthDateOld: profile?.birthDate,
|
||||
profileEmployeeId: profile.id,
|
||||
id: undefined
|
||||
}),
|
||||
);
|
||||
const firstRecord = await this.profileHistoryRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
order: { createdAt: "ASC" }
|
||||
});
|
||||
return new HttpSuccess(firstRecord);
|
||||
}
|
||||
|
||||
return new HttpSuccess(historyProfile);
|
||||
return new HttpSuccess(profileHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3193,20 +3206,33 @@ export class ProfileEmployeeController extends Controller {
|
|||
@Get("history/{id}")
|
||||
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
//await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id); ไม่แน่ใจEMPปิดไว้ก่อน;
|
||||
const profile = await this.profileHistoryRepo.find({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
},
|
||||
where: { profileEmployeeId: id },
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
},
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: id }
|
||||
});
|
||||
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return new HttpSuccess(profile);
|
||||
const profileHistory = await this.profileHistoryRepo.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" }
|
||||
});
|
||||
|
||||
if (profileHistory.length == 0) {
|
||||
await this.profileHistoryRepo.save(
|
||||
Object.assign(new ProfileEmployeeHistory(), {
|
||||
...profile,
|
||||
birthDateOld: profile?.birthDate,
|
||||
profileEmployeeId: id,
|
||||
id: undefined
|
||||
}),
|
||||
);
|
||||
const firstRecord = await this.profileHistoryRepo.find({
|
||||
where: { profileEmployeeId: id },
|
||||
order: { createdAt: "ASC" }
|
||||
});
|
||||
return new HttpSuccess(firstRecord);
|
||||
}
|
||||
|
||||
return new HttpSuccess(profileHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue