From 3e6212657076d745cac867b3bb19a74d712e57f0 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 16 May 2024 11:12:17 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20family?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileFamilyCoupleController.ts | 13 +++++++++---- .../ProfileFamilyCoupleEmployeeController.ts | 7 ++++++- src/controllers/ProfileFamilyFatherController.ts | 1 + .../ProfileFamilyFatherEmployeeController.ts | 1 + src/controllers/ProfileFamilyMotherController.ts | 1 + .../ProfileFamilyMotherEmployeeController.ts | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index c2d3d2e9..69a0efc2 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -33,7 +33,7 @@ export class ProfileFamilyCoupleController extends Controller { @Example({ status: 200, message: "สำเร็จ", - result: [{ + result: { id: "6207ae29-05ef-4abb-9a37-a887265d671e", couple: true, couplePrefix: "string", @@ -45,7 +45,7 @@ export class ProfileFamilyCoupleController extends Controller { coupleLive: true, relationship: "string", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - }], + }, }) public async getFamilyCouple(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ @@ -55,12 +55,13 @@ export class ProfileFamilyCoupleController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - const familyCouple = await this.ProfileFamilyCouple.find({ + const familyCouple = await this.ProfileFamilyCouple.findOne({ select: [ "id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld", "coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId", ], where: { profileId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyCouple); @@ -150,6 +151,7 @@ export class ProfileFamilyCoupleController extends Controller { await this.ProfileFamilyCouple.save(familyCouple); if (familyCouple) { + profile.relationship = familyCouple.relationship //update profile.relationship const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { profileFamilyCoupleId: familyCouple.id, couple: familyCouple.couple, @@ -165,7 +167,10 @@ export class ProfileFamilyCoupleController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await this.ProfileFamilyCoupleHistory.save(history); + await Promise.all([ + this.profileRepo.save(profile), + this.ProfileFamilyCoupleHistory.save(history) + ]); } return new HttpSuccess(familyCouple.id); } diff --git a/src/controllers/ProfileFamilyCoupleEmployeeController.ts b/src/controllers/ProfileFamilyCoupleEmployeeController.ts index 8102a6fd..adc4252f 100644 --- a/src/controllers/ProfileFamilyCoupleEmployeeController.ts +++ b/src/controllers/ProfileFamilyCoupleEmployeeController.ts @@ -61,6 +61,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { "coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileEmployeeId", ], where: { profileEmployeeId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyCouple); @@ -150,6 +151,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { await this.ProfileFamilyCouple.save(familyCouple); if (familyCouple) { + profile.relationship = familyCouple.relationship //update profileEmployee.relationship const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { profileFamilyCoupleId: familyCouple.id, couple: familyCouple.couple, @@ -165,7 +167,10 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await this.ProfileFamilyCoupleHistory.save(history); + await Promise.all([ + this.profileRepo.save(profile), + this.ProfileFamilyCoupleHistory.save(history) + ]); } return new HttpSuccess(familyCouple.id); } diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index 4a55103a..4334df05 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -58,6 +58,7 @@ export class ProfileFamilyFatherController extends Controller { "fatherCareer", "fatherCitizenId", "fatherLive", "profileId", ], where: { profileId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyFather); diff --git a/src/controllers/ProfileFamilyFatherEmployeeController.ts b/src/controllers/ProfileFamilyFatherEmployeeController.ts index d494974a..0ab6e963 100644 --- a/src/controllers/ProfileFamilyFatherEmployeeController.ts +++ b/src/controllers/ProfileFamilyFatherEmployeeController.ts @@ -58,6 +58,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller { "fatherCareer", "fatherCitizenId", "fatherLive", "profileEmployeeId", ], where: { profileEmployeeId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyFather); diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index c2e60642..923331d7 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -58,6 +58,7 @@ export class ProfileFamilyMotherController extends Controller { "motherCareer", "motherCitizenId", "motherLive", "profileId", ], where: { profileId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyMother); diff --git a/src/controllers/ProfileFamilyMotherEmployeeController.ts b/src/controllers/ProfileFamilyMotherEmployeeController.ts index 28889e7e..9569937f 100644 --- a/src/controllers/ProfileFamilyMotherEmployeeController.ts +++ b/src/controllers/ProfileFamilyMotherEmployeeController.ts @@ -58,6 +58,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller { "motherCareer", "motherCitizenId", "motherLive", "profileEmployeeId", ], where: { profileEmployeeId }, + order: { lastUpdatedAt: "DESC" }, }); return new HttpSuccess(familyMother);