add api history/user
This commit is contained in:
parent
3438b450ba
commit
7126d64d7e
6 changed files with 206 additions and 10 deletions
|
|
@ -72,6 +72,37 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขชื่อ by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async changeNameHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.changeNameHistoryRepository.find({
|
||||
where: {
|
||||
histories: {
|
||||
profileEmployeeId: profile.id,
|
||||
},
|
||||
},
|
||||
select: [
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"status",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{changeNameId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
|
|
@ -146,7 +177,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
@ -174,17 +205,17 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
]);
|
||||
|
||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||
where:{
|
||||
profileEmployeeId: record.profileEmployeeId
|
||||
where: {
|
||||
profileEmployeeId: record.profileEmployeeId,
|
||||
},
|
||||
order:{
|
||||
createdAt: "DESC"
|
||||
}
|
||||
})
|
||||
order: {
|
||||
createdAt: "DESC",
|
||||
},
|
||||
});
|
||||
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId });
|
||||
|
||||
|
||||
if (profile && chkLastRecord.id === record.id) {
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue