เพิ่้มและลบ api history/user
This commit is contained in:
parent
abc4aee8a4
commit
8d1de6365a
22 changed files with 512 additions and 466 deletions
|
|
@ -70,16 +70,22 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
})
|
||||
public async getFamilyMother(@Path() profileEmployeeId: string) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: profileEmployeeId }
|
||||
})
|
||||
where: { id: profileEmployeeId },
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const familyMother = await this.ProfileFamilyMother.findOne({
|
||||
select: [
|
||||
"id", "motherPrefix", "motherFirstName", "motherLastName",
|
||||
"motherCareer", "motherCitizenId", "motherLive", "profileEmployeeId",
|
||||
"id",
|
||||
"motherPrefix",
|
||||
"motherFirstName",
|
||||
"motherLastName",
|
||||
"motherCareer",
|
||||
"motherCitizenId",
|
||||
"motherLive",
|
||||
"profileEmployeeId",
|
||||
],
|
||||
where: { profileEmployeeId },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
|
|
@ -88,6 +94,47 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
return new HttpSuccess(familyMother);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyMotherHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const familyMother = await this.ProfileFamilyMother.find({
|
||||
relations: ["histories"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
|
||||
const mapData = familyMother
|
||||
.flatMap((x) => x.histories)
|
||||
.map((y) => ({
|
||||
id: y.id,
|
||||
createdAt: y.createdAt,
|
||||
createdUserId: y.createdUserId,
|
||||
lastUpdatedAt: y.lastUpdatedAt,
|
||||
lastUpdateUserId: y.lastUpdateUserId,
|
||||
createdFullName: y.createdFullName,
|
||||
lastUpdateFullName: y.lastUpdateFullName,
|
||||
motherPrefix: y.motherPrefix,
|
||||
motherFirstName: y.motherFirstName,
|
||||
motherLastName: y.motherLastName,
|
||||
motherCareer: y.motherCareer,
|
||||
motherCitizenId: y.motherCitizenId,
|
||||
motherLive: y.motherLive,
|
||||
profileFamilyMotherId: y.profileFamilyMotherId,
|
||||
profileEmployeeId: profile.id,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
@Get("history/{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
|
|
@ -109,13 +156,13 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
motherLive: true,
|
||||
profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
}
|
||||
},
|
||||
],
|
||||
})
|
||||
public async familyMotherHistory(@Path() profileEmployeeId: string) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: profileEmployeeId }
|
||||
})
|
||||
where: { id: profileEmployeeId },
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
|
@ -123,26 +170,28 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
const familyMother = await this.ProfileFamilyMother.find({
|
||||
relations: ["histories"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profileEmployeeId},
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
|
||||
const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({
|
||||
id: y.id,
|
||||
createdAt: y.createdAt,
|
||||
createdUserId: y.createdUserId,
|
||||
lastUpdatedAt: y.lastUpdatedAt,
|
||||
lastUpdateUserId: y.lastUpdateUserId,
|
||||
createdFullName: y.createdFullName,
|
||||
lastUpdateFullName: y.lastUpdateFullName,
|
||||
motherPrefix: y.motherPrefix,
|
||||
motherFirstName: y.motherFirstName,
|
||||
motherLastName: y.motherLastName,
|
||||
motherCareer: y.motherCareer,
|
||||
motherCitizenId: y.motherCitizenId,
|
||||
motherLive: y.motherLive,
|
||||
profileFamilyMotherId: y.profileFamilyMotherId,
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
}));
|
||||
const mapData = familyMother
|
||||
.flatMap((x) => x.histories)
|
||||
.map((y) => ({
|
||||
id: y.id,
|
||||
createdAt: y.createdAt,
|
||||
createdUserId: y.createdUserId,
|
||||
lastUpdatedAt: y.lastUpdatedAt,
|
||||
lastUpdateUserId: y.lastUpdateUserId,
|
||||
createdFullName: y.createdFullName,
|
||||
lastUpdateFullName: y.lastUpdateFullName,
|
||||
motherPrefix: y.motherPrefix,
|
||||
motherFirstName: y.motherFirstName,
|
||||
motherLastName: y.motherLastName,
|
||||
motherCareer: y.motherCareer,
|
||||
motherCitizenId: y.motherCitizenId,
|
||||
motherLive: y.motherLive,
|
||||
profileFamilyMotherId: y.profileFamilyMotherId,
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
|
@ -160,7 +209,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
familyMother.createdUserId = req.user.sub;
|
||||
familyMother.createdFullName = req.user.name;
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
|
|
@ -192,24 +241,26 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileFamilyMother,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileEmployeeId: profileEmployeeId });
|
||||
const familyMother = await this.ProfileFamilyMother.findOneBy({
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
Object.assign(familyMother, body);
|
||||
familyMother.lastUpdateUserId = req.user.sub,
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
(familyMother.lastUpdateUserId = req.user.sub),
|
||||
(familyMother.lastUpdateFullName = req.user.name);
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
history.motherPrefix = familyMother.motherPrefix,
|
||||
history.motherFirstName = familyMother.motherFirstName,
|
||||
history.motherLastName = familyMother.motherLastName,
|
||||
history.motherCareer = familyMother.motherCareer,
|
||||
history.motherCitizenId = familyMother.motherCitizenId,
|
||||
history.motherLive = familyMother.motherLive,
|
||||
history.lastUpdateUserId = req.user.sub,
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
(history.motherPrefix = familyMother.motherPrefix),
|
||||
(history.motherFirstName = familyMother.motherFirstName),
|
||||
(history.motherLastName = familyMother.motherLastName),
|
||||
(history.motherCareer = familyMother.motherCareer),
|
||||
(history.motherCitizenId = familyMother.motherCitizenId),
|
||||
(history.motherLive = familyMother.motherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
|
|
@ -218,5 +269,4 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue