From 950612884204222ff4e11c58b2706cad605fa9d5 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 14 May 2024 17:24:33 +0700 Subject: [PATCH 1/4] changName update and validate citizenId --- .../ProfileChangeNameController.ts | 24 +++++++++++++++++ .../ProfileChangeNameEmployeeController.ts | 26 ++++++++++++++++++- src/controllers/ProfileController.ts | 4 +++ src/controllers/ProfileEmployeeController.ts | 2 +- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index b7785d20..9d995cde 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -126,6 +126,11 @@ export class ProfileChangeNameController extends Controller { await this.changeNameRepository.save(data); + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileRepository.save(profile); + return new HttpSuccess(data.id); } @@ -152,6 +157,25 @@ export class ProfileChangeNameController extends Controller { this.changeNameHistoryRepository.save(history), ]); + const chkLastRecord = await this.changeNameRepository.findOne({ + where:{ + profileEmployeeId: record.profileEmployeeId + }, + order:{ + createdAt: "DESC" + } + }) + if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const profile = await this.profileRepository.findOneBy({ id: record.profileId }); + + if (profile && chkLastRecord.id === record.id) { + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileRepository.save(profile); + } + return new HttpSuccess(); } diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 9ccefb2c..fcdcfbaf 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -128,6 +128,11 @@ export class ProfileChangeNameEmployeeController extends Controller { await this.changeNameRepository.save(data); + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileEmployeeRepo.save(profile); + return new HttpSuccess(data.id); } @@ -154,7 +159,26 @@ export class ProfileChangeNameEmployeeController extends Controller { this.changeNameHistoryRepository.save(history), ]); - return new HttpSuccess(); + const chkLastRecord = await this.changeNameRepository.findOne({ + where:{ + profileEmployeeId: record.profileEmployeeId + }, + 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; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileEmployeeRepo.save(profile); + } + + return new HttpSuccess([chkLastRecord.id,record.id]); } @Delete("{changeNameId}") diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e1d76c73..1e470911 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -195,6 +195,10 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } + if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) { + throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); + } + const profile = Object.assign(new Profile(), body); profile.isProbation = false; profile.isLeave = false; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a553539b..98aa197f 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -33,7 +33,7 @@ import { EmployeePosType } from "../entities/EmployeePosType"; import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/org/profile-employee") -@Tags("Profile") +@Tags("ProfileEmployee") @Security("bearerAuth") @Response( HttpStatus.INTERNAL_SERVER_ERROR, From fcbbdbf4d1fe4bf836bd22230d7dc6fdc6b2362f Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 14 May 2024 17:24:38 +0700 Subject: [PATCH 2/4] =?UTF-8?q?fix=20bug=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationUnauthorizeController.ts | 8 +- src/controllers/ProfileController.ts | 64 ++++++----- .../ProfileDisciplineController.ts | 2 +- .../ProfileDisciplineEmployeeController.ts | 2 +- src/controllers/ProfileDutyController.ts | 2 +- .../ProfileDutyEmployeeController.ts | 2 +- src/controllers/ProfileEmployeeController.ts | 4 +- src/controllers/ProfileLeaveController.ts | 2 +- .../ProfileLeaveEmployeeController.ts | 2 +- src/controllers/ProfileOtherController.ts | 2 +- .../ProfileOtherEmployeeController.ts | 2 +- src/entities/Profile.ts | 4 +- src/entities/ProfileDiscipline.ts | 2 +- src/entities/ProfileDisciplineEmployee.ts | 106 ------------------ .../ProfileDisciplineEmployeeHistory.ts | 74 ------------ src/entities/ProfileEmployee.ts | 4 - 16 files changed, 50 insertions(+), 232 deletions(-) delete mode 100644 src/entities/ProfileDisciplineEmployee.ts delete mode 100644 src/entities/ProfileDisciplineEmployeeHistory.ts diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 6be5ae66..eb232e63 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -60,7 +60,7 @@ export class OrganizationUnauthorizeController extends Controller { .leftJoinAndSelect("posMaster.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where({ @@ -219,7 +219,7 @@ export class OrganizationUnauthorizeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, @@ -278,7 +278,7 @@ export class OrganizationUnauthorizeController extends Controller { .leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4") .leftJoinAndSelect("employeePosMaster.positions", "positions") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where({ @@ -426,7 +426,7 @@ export class OrganizationUnauthorizeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e1d76c73..3e91d89d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -218,7 +218,7 @@ export class ProfileController extends Controller { @Request() request: RequestWithUser, @Body() body: CreateProfileAllFields, ) { - const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId }) + const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId }); if (profileExist) { return new HttpSuccess(profileExist.id); } @@ -755,11 +755,11 @@ export class ProfileController extends Controller { ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id); - const position = await this.positionRepository.findOne({ + const position = await this.positionRepository.findOne({ relations: ["posExecutive"], - where: { - posMasterId: posMaster?.id - } + where: { + posMasterId: posMaster?.id, + }, }); const _profile: any = { @@ -777,15 +777,16 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, - posExecutiveName: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutiveName, - posExecutivePriority: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutivePriority, - posExecutiveId: position == null || position.posExecutive == null - ? null - : position.posExecutive.id, + posExecutiveName: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: + position == null || position.posExecutive == null ? null : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == @@ -1725,7 +1726,7 @@ export class ProfileController extends Controller { .leftJoinAndSelect("posMaster.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where((qb) => { @@ -1886,7 +1887,7 @@ export class ProfileController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, @@ -1933,14 +1934,14 @@ export class ProfileController extends Controller { const posMaster = await this.posMasterRepo.findOne({ where: { current_holderId: profile.id, - orgRevisionId: revisionId - } + orgRevisionId: revisionId, + }, }); - const position = await this.positionRepository.findOne({ + const position = await this.positionRepository.findOne({ relations: ["posExecutive"], - where: { - posMasterId: posMaster?.id - } + where: { + posMasterId: posMaster?.id, + }, }); const _profile = { @@ -1957,15 +1958,16 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, - posExecutiveName: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutiveName, - posExecutivePriority: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutivePriority, - posExecutiveId: position == null || position.posExecutive == null - ? null - : position.posExecutive.id, + posExecutiveName: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: + position == null || position.posExecutive == null ? null : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 62fc4256..e7690b77 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -169,7 +169,7 @@ export class ProfileDisciplineController extends Controller { } @Delete("{disciplineId}") - public async deleteTraning(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string) { await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 9dc1ff47..9ed528c8 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -145,7 +145,7 @@ export class ProfileDisciplineEmployeeController extends Controller { } @Delete("{disciplineId}") - public async deleteTraning(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string) { await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index d2c0ba92..b88754c6 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -157,7 +157,7 @@ export class ProfileDutyController extends Controller { } @Delete("{dutyId}") - public async deleteTraning(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string) { await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 25f40f0e..70077ec3 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -118,7 +118,7 @@ export class ProfileDutyEmployeeController extends Controller { } @Delete("{dutyId}") - public async deleteTraning(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string) { await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a553539b..3df03f86 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -975,7 +975,7 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4") .leftJoinAndSelect("employeePosMaster.positions", "positions") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where((qb) => { @@ -1128,7 +1128,7 @@ export class ProfileEmployeeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 54fb5d8e..6510dff1 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -221,7 +221,7 @@ export class ProfileLeaveController extends Controller { } @Delete("{leaveId}") - public async deleteTraning(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string) { await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileLeaveEmployeeController.ts b/src/controllers/ProfileLeaveEmployeeController.ts index 2a88b9a6..6fa06140 100644 --- a/src/controllers/ProfileLeaveEmployeeController.ts +++ b/src/controllers/ProfileLeaveEmployeeController.ts @@ -119,7 +119,7 @@ export class ProfileLeaveEmployeeController extends Controller { } @Delete("{leaveId}") - public async deleteTraning(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string) { await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index f5e1f81e..1a4eeeed 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -134,7 +134,7 @@ export class ProfileOtherController extends Controller { } @Delete("{otherId}") - public async deleteTraning(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string) { await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/controllers/ProfileOtherEmployeeController.ts b/src/controllers/ProfileOtherEmployeeController.ts index c6312bba..c71ed332 100644 --- a/src/controllers/ProfileOtherEmployeeController.ts +++ b/src/controllers/ProfileOtherEmployeeController.ts @@ -105,7 +105,7 @@ export class ProfileOtherEmployeeController extends Controller { } @Delete("{otherId}") - public async deleteTraning(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string) { await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 1d7b8d04..28e0763d 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -4,7 +4,6 @@ import { PosMaster } from "./PosMaster"; import { PosLevel } from "./PosLevel"; import { PosType } from "./PosType"; import { ProfileSalary } from "./ProfileSalary"; -import { ProfileDiscipline } from "./ProfileDiscipline"; import { ProfileCertificate } from "./ProfileCertificate"; import { ProfileEducation } from "./ProfileEducation"; import { ProfileTraining } from "./ProfileTraining"; @@ -22,6 +21,7 @@ import { Province } from "./Province"; import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileDiscipline } from "./ProfileDiscipline"; @Entity("profile") export class Profile extends EntityBase { @@ -267,7 +267,7 @@ export class Profile extends EntityBase { profileSalary: ProfileSalary[]; @OneToMany(() => ProfileDiscipline, (profileDiscipline) => profileDiscipline.profile) - profileDiscipline: ProfileDiscipline[]; + profileDisciplines: ProfileDiscipline[]; @OneToMany(() => ProfileCertificate, (profileCertificate) => profileCertificate.profile) profileCertificates: ProfileCertificate[]; diff --git a/src/entities/ProfileDiscipline.ts b/src/entities/ProfileDiscipline.ts index 0c93adf2..ca698a75 100644 --- a/src/entities/ProfileDiscipline.ts +++ b/src/entities/ProfileDiscipline.ts @@ -75,7 +75,7 @@ export class ProfileDiscipline extends EntityBase { ) profileDisciplineHistories: ProfileDisciplineHistory[]; - @ManyToOne(() => Profile, (profile) => profile.profileDiscipline) + @ManyToOne(() => Profile, (profile) => profile.profileDisciplines) @JoinColumn({ name: "profileId" }) profile: Profile; diff --git a/src/entities/ProfileDisciplineEmployee.ts b/src/entities/ProfileDisciplineEmployee.ts deleted file mode 100644 index 70cb6207..00000000 --- a/src/entities/ProfileDisciplineEmployee.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; -import { EntityBase } from "./base/Base"; -import { ProfileEmployee } from "./ProfileEmployee"; -import { ProfileDisciplineEmployeeHistory } from "./ProfileDisciplineEmployeeHistory"; - -@Entity("profileDisciplineEmployee") -export class ProfileDisciplineEmployee extends EntityBase { - @Column({ - nullable: true, - type: "datetime", - comment: "วันที่", - default: null, - }) - date: Date; - - @Column({ - length: 40, - comment: "ไอดีโปรไฟล์", - type: "uuid", - }) - profileId: string; - - @Column({ - comment: "สถานะการใช้งาน", - default: false, - }) - isActive: boolean; - - @Column({ - nullable: true, - comment: "ระดับความผิด", - type: "text", - default: null, - }) - level: string; - - @Column({ - nullable: true, - comment: "รายละเอียด", - type: "text", - default: null, - }) - detail: string; - - @Column({ - nullable: true, - type: "datetime", - comment: "เอกสารอ้างอิง (ลงวันที่)", - default: null, - }) - refCommandDate: Date; - - @Column({ - nullable: true, - comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - nullable: true, - comment: "ล้างมลทิน", - type: "text", - default: null, - }) - unStigma: string; - - @OneToMany( - () => ProfileDisciplineEmployeeHistory, - (profileDisciplineHistory) => profileDisciplineHistory.histories, - ) - profileDisciplineHistories: ProfileDisciplineEmployeeHistory[]; - - @ManyToOne(() => ProfileEmployee, (profile) => profile.profileDiscipline) - @JoinColumn({ name: "profileId" }) - profile: ProfileEmployee; -} - -export class CreateProfileDisciplineEmployee { - @Column() - date: Date | null; - - @Column() - profileId: string; - - @Column() - isActive: boolean | null; - - @Column() - level: string | null; - - @Column() - detail: string | null; - - @Column() - refCommandDate: Date | null; - - @Column() - refCommandNo: string | null; - - @Column() - unStigma: string | null; -} - -export type UpdateProfileDisciplineEmployee = Partial; diff --git a/src/entities/ProfileDisciplineEmployeeHistory.ts b/src/entities/ProfileDisciplineEmployeeHistory.ts deleted file mode 100644 index 2b8089c4..00000000 --- a/src/entities/ProfileDisciplineEmployeeHistory.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; -import { EntityBase } from "./base/Base"; -import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee"; - -@Entity("profileDisciplineEmployeeHistory") -export class ProfileDisciplineEmployeeHistory extends EntityBase { - @Column({ - nullable: true, - type: "datetime", - comment: "วันที่", - default: null, - }) - date: Date; - - @Column({ - length: 40, - comment: "ล้างมลทิน", - type: "uuid", - }) - profileDisciplineId: string; - - @Column({ - comment: "สถานะการใช้งาน", - default: false, - }) - isActive: boolean; - - @Column({ - nullable: true, - comment: "ระดับความผิด", - type: "text", - default: null, - }) - level: string; - - @Column({ - nullable: true, - comment: "รายละเอียด", - type: "text", - default: null, - }) - detail: string; - - @Column({ - nullable: true, - type: "datetime", - comment: "เอกสารอ้างอิง (ลงวันที่)", - default: null, - }) - refCommandDate: Date; - - @Column({ - nullable: true, - comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - nullable: true, - comment: "ล้างมลทิน", - type: "text", - default: null, - }) - unStigma: string; - - @ManyToOne( - () => ProfileDisciplineEmployee, - (profileDiscipline) => profileDiscipline.profileDisciplineHistories, - ) - @JoinColumn({ name: "profileDisciplineId" }) - histories: ProfileDisciplineEmployee; -} diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 53d5b1cd..db38a05c 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -4,7 +4,6 @@ import { EmployeePosLevel } from "./EmployeePosLevel"; import { EmployeePosType } from "./EmployeePosType"; import { EmployeePosMaster } from "./EmployeePosMaster"; import { ProfileSalaryEmployee } from "./ProfileSalaryEmployee"; -import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee"; import { ProfileCertificate } from "./ProfileCertificate"; import { ProfileTraining } from "./ProfileTraining"; import { ProfileInsignia } from "./ProfileInsignia"; @@ -216,9 +215,6 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileSalaryEmployee, (v) => v.profile) profileSalary: ProfileSalaryEmployee[]; - @OneToMany(() => ProfileDisciplineEmployee, (v) => v.profile) - profileDiscipline: ProfileDisciplineEmployee[]; - @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) profileCertificates: ProfileCertificate[]; From 0114e41c3acf4dc4ba647a10ee113aea21ebc2b9 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 17:26:06 +0700 Subject: [PATCH 3/4] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=9A=E0=B8=B8=E0=B8=95=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileChildrenController.ts | 117 +++++++++++++ .../ProfileChildrenEmployeeController.ts | 122 ++++++++++++++ src/entities/Profile.ts | 5 +- src/entities/ProfileChildren.ts | 112 +++++++++++++ src/entities/ProfileChildrenHistory.ts | 155 ++++++++++++++++++ src/entities/ProfileEmployee.ts | 3 +- src/entities/ProfileFamily.ts | 103 ------------ 7 files changed, 511 insertions(+), 106 deletions(-) create mode 100644 src/controllers/ProfileChildrenController.ts create mode 100644 src/controllers/ProfileChildrenEmployeeController.ts create mode 100644 src/entities/ProfileChildren.ts create mode 100644 src/entities/ProfileChildrenHistory.ts diff --git a/src/controllers/ProfileChildrenController.ts b/src/controllers/ProfileChildrenController.ts new file mode 100644 index 00000000..32c0be05 --- /dev/null +++ b/src/controllers/ProfileChildrenController.ts @@ -0,0 +1,117 @@ +import { + Body, + Controller, + Delete, + Example, + Get, + Patch, + Path, + Post, + Request, + Route, + Security, + Tags, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatus from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory"; +import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; +import { + CreateProfileChildren, + ProfileChildren, + UpdateProfileChildren, +} from "../entities/ProfileChildren"; + +@Route("api/v1/org/profile/children") +@Tags("ProfileChildren") +@Security("bearerAuth") +export class ProfileChildrenController extends Controller { + private profileRepository = AppDataSource.getRepository(Profile); + private childrenRepository = AppDataSource.getRepository(ProfileChildren); + private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); + + @Get("{profileId}") + public async getChildren(@Path() profileId: string) { + const lists = await this.childrenRepository.find({ + where: { profileId: profileId }, + }); + return new HttpSuccess(lists); + } + + @Get("history/{childrenId}") + public async childrenHistory(@Path() childrenId: string) { + const record = await this.childrenHistoryRepository.find({ + where: { profileChildrenId: childrenId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + + @Post() + public async newChildren(@Request() req: RequestWithUser, @Body() body: CreateProfileChildren) { + const profile = await this.profileRepository.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileChildren(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + + await this.childrenRepository.save(data); + + return new HttpSuccess(); + } + + @Patch("{childrenId}") + public async editChildren( + @Request() req: RequestWithUser, + @Body() body: UpdateProfileChildren, + @Path() childrenId: string, + ) { + const record = await this.childrenRepository.findOneBy({ id: childrenId }); + + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const history = new ProfileChildrenHistory(); + + Object.assign(history, { ...record, id: undefined }); + Object.assign(record, body); + history.profileChildrenId = childrenId; + record.lastUpdateFullName = req.user.name; + history.lastUpdateFullName = req.user.name; + + await Promise.all([ + this.childrenRepository.save(record), + this.childrenHistoryRepository.save(history), + ]); + + return new HttpSuccess(); + } + + @Delete("{childrenId}") + public async deleteTraning(@Path() childrenId: string) { + await this.childrenHistoryRepository.delete({ + profileChildrenId: childrenId, + }); + + const result = await this.childrenRepository.delete({ id: childrenId }); + + if (result.affected && result.affected <= 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + return new HttpSuccess(); + } +} diff --git a/src/controllers/ProfileChildrenEmployeeController.ts b/src/controllers/ProfileChildrenEmployeeController.ts new file mode 100644 index 00000000..bb71274a --- /dev/null +++ b/src/controllers/ProfileChildrenEmployeeController.ts @@ -0,0 +1,122 @@ +import { + Body, + Controller, + Delete, + Example, + Get, + Patch, + Path, + Post, + Request, + Route, + Security, + Tags, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatus from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory"; +import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; +import { + CreateProfileChildren, + CreateProfileChildrenEmployee, + ProfileChildren, + UpdateProfileChildren, +} from "../entities/ProfileChildren"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; + +@Route("api/v1/org/profile-employee/children") +@Tags("ProfileChildren") +@Security("bearerAuth") +export class ProfileChildrenEmployeeController extends Controller { + private profileRepository = AppDataSource.getRepository(ProfileEmployee); + private childrenRepository = AppDataSource.getRepository(ProfileChildren); + private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); + + @Get("{profileId}") + public async getChildren(@Path() profileId: string) { + const lists = await this.childrenRepository.find({ + where: { profileEmployeeId: profileId }, + }); + return new HttpSuccess(lists); + } + + @Get("history/{childrenId}") + public async childrenHistory(@Path() childrenId: string) { + const record = await this.childrenHistoryRepository.find({ + where: { profileChildrenId: childrenId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + + @Post() + public async newChildren( + @Request() req: RequestWithUser, + @Body() body: CreateProfileChildrenEmployee, + ) { + const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileChildren(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + + await this.childrenRepository.save(data); + + return new HttpSuccess(); + } + + @Patch("{childrenId}") + public async editChildren( + @Request() req: RequestWithUser, + @Body() body: UpdateProfileChildren, + @Path() childrenId: string, + ) { + const record = await this.childrenRepository.findOneBy({ id: childrenId }); + + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const history = new ProfileChildrenHistory(); + + Object.assign(history, { ...record, id: undefined }); + Object.assign(record, body); + history.profileChildrenId = childrenId; + record.lastUpdateFullName = req.user.name; + history.lastUpdateFullName = req.user.name; + + await Promise.all([ + this.childrenRepository.save(record), + this.childrenHistoryRepository.save(history), + ]); + + return new HttpSuccess(); + } + + @Delete("{childrenId}") + public async deleteTraning(@Path() childrenId: string) { + await this.childrenHistoryRepository.delete({ + profileChildrenId: childrenId, + }); + + const result = await this.childrenRepository.delete({ id: childrenId }); + + if (result.affected && result.affected <= 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + return new HttpSuccess(); + } +} diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 1d7b8d04..7608089b 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -16,12 +16,13 @@ import { ProfileAbility } from "./ProfileAbility"; import { ProfileDuty } from "./ProfileDuty"; import { ProfileNopaid } from "./ProfileNopaid"; import { ProfileOther } from "./ProfileOther"; -import { ProfileChildren, ProfileFamilyHistory } from "./ProfileFamily"; +import { ProfileFamilyHistory } from "./ProfileFamily"; import { ProfileGovernment } from "./ProfileGovernment"; import { Province } from "./Province"; import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileChildren } from "./ProfileChildren"; @Entity("profile") export class Profile extends EntityBase { @@ -309,7 +310,7 @@ export class Profile extends EntityBase { profileFamily: ProfileFamilyHistory[]; @OneToMany(() => ProfileChildren, (profileChildren) => profileChildren.profile) - profileChildren: ProfileChildren[]; + profileChildrens: ProfileChildren[]; @OneToMany(() => ProfileGovernment, (profileGovernment) => profileGovernment.profile) profileGovernment: ProfileGovernment[]; diff --git a/src/entities/ProfileChildren.ts b/src/entities/ProfileChildren.ts new file mode 100644 index 00000000..4e3c929b --- /dev/null +++ b/src/entities/ProfileChildren.ts @@ -0,0 +1,112 @@ +import { Column, Entity, ManyToOne, OneToMany, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; +import { ProfileChildrenHistory } from "./ProfileChildrenHistory"; + +@Entity("profileChildren") +export class ProfileChildren extends EntityBase { + @Column({ + nullable: true, + default: null, + comment: "อาชีพบุตร", + }) + childrenCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อบุตร", + }) + childrenFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลบุตร", + }) + childrenLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าบุตร", + }) + childrenPrefix: string; + + @Column({ + nullable: true, + default: null, + type: "boolean", + comment: "มีชีวิตบุตร", + }) + childrenLive: boolean; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนบุตร", + }) + childrenCitizenId: string; + + @Column({ + nullable: true, + length: 40, + type: "uuid", + comment: "คีย์นอก(FK) ของตาราง Profile", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", + default: null, + }) + profileEmployeeId: string; + + @ManyToOne(() => Profile, (Profile) => Profile.profileChildrens) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChildrens) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; + + @OneToMany( + () => ProfileChildrenHistory, + (profileChildrenHistory) => profileChildrenHistory.histories, + ) + profileChildrenHistories: ProfileChildrenHistory[]; +} + +export type CreateProfileChildren = { + profileId: string; + childrenCareer: string; + childrenFirstName: string; + childrenLastName: string; + childrenPrefix: string; + childrenLive: boolean; + childrenCitizenId: string; +}; + +export type CreateProfileChildrenEmployee = { + profileEmployeeId: string; + childrenCareer: string; + childrenFirstName: string; + childrenLastName: string; + childrenPrefix: string; + childrenLive: boolean; + childrenCitizenId: string; +}; + +export type UpdateProfileChildren = { + id: string; + childrenCareer?: string | null; + childrenFirstName?: string | null; + childrenLastName?: string | null; + childrenPrefix?: string | null; + childrenLive?: boolean | null; + childrenCitizenId?: string | null; +}; diff --git a/src/entities/ProfileChildrenHistory.ts b/src/entities/ProfileChildrenHistory.ts new file mode 100644 index 00000000..3c2dae6e --- /dev/null +++ b/src/entities/ProfileChildrenHistory.ts @@ -0,0 +1,155 @@ +import { Column, Entity, ManyToOne, OneToMany, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; +import { ProfileChildren } from "./ProfileChildren"; + +@Entity("profileChildrenHistory") +export class ProfileChildrenHistory extends EntityBase { + @Column({ + nullable: true, + default: null, + comment: "อาชีพบุตร", + }) + childrenCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อบุตร", + }) + childrenFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลบุตร", + }) + childrenLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าบุตร", + }) + childrenPrefix: string; + + @Column({ + nullable: true, + default: null, + type: "boolean", + comment: "มีชีวิตบุตร", + }) + childrenLive: boolean; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนบุตร", + }) + childrenCitizenId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileChildren", + default: null, + }) + profileChildrenId: string; + + @ManyToOne(() => ProfileChildren, (profileChildren) => profileChildren.profileChildrenHistories) + @JoinColumn({ name: "profileChildrenId" }) + histories: ProfileChildren; +} + +export type CreateChildren = { + childrenCareer: string; + childrenFirstName: string; + childrenLastName: string; + childrenPrefix: string; + childrenLive: boolean; + childrenCitizenId: string; +}; + +export type UpdateChildren = { + id: string; + childrenCareer?: string | null; + childrenFirstName?: string | null; + childrenLastName?: string | null; + childrenPrefix?: string | null; + childrenLive?: boolean | null; + childrenCitizenId?: string | null; +}; + +export type CreateProfileFamily = { + couple: boolean | null; + couplePrefix: string | null; + coupleFirstName: string | null; + coupleLastName: string | null; + coupleLastNameOld: string | null; + coupleCareer: string | null; + coupleCitizenId: string | null; + coupleLive: boolean | null; + fatherPrefix: string | null; + fatherFirstName: string | null; + fatherLastName: string | null; + fatherCareer: string | null; + fatherCitizenId: string | null; + fatherLive: boolean | null; + motherPrefix: string | null; + motherFirstName: string | null; + motherLastName: string | null; + motherCareer: string | null; + motherCitizenId: string | null; + motherLive: boolean | null; + profileId: string; + children: CreateChildren[]; +}; +export type CreateProfileFamilyEmployee = { + couple: boolean | null; + couplePrefix: string | null; + coupleFirstName: string | null; + coupleLastName: string | null; + coupleLastNameOld: string | null; + coupleCareer: string | null; + coupleCitizenId: string | null; + coupleLive: boolean | null; + fatherPrefix: string | null; + fatherFirstName: string | null; + fatherLastName: string | null; + fatherCareer: string | null; + fatherCitizenId: string | null; + fatherLive: boolean | null; + motherPrefix: string | null; + motherFirstName: string | null; + motherLastName: string | null; + motherCareer: string | null; + motherCitizenId: string | null; + motherLive: boolean | null; + profileEmployeeId: string | null; + children: CreateChildren[]; +}; + +export type UpdateProfileFamily = { + couple?: boolean | null; + couplePrefix?: string | null; + coupleFirstName?: string | null; + coupleLastName?: string | null; + coupleLastNameOld?: string | null; + coupleCareer?: string | null; + coupleCitizenId?: string | null; + coupleLive?: boolean | null; + fatherPrefix?: string | null; + fatherFirstName?: string | null; + fatherLastName?: string | null; + fatherCareer?: string | null; + fatherCitizenId?: string | null; + fatherLive?: boolean | null; + motherPrefix?: string | null; + motherFirstName?: string | null; + motherLastName?: string | null; + motherCareer?: string | null; + motherCitizenId?: string | null; + motherLive?: boolean | null; + children: UpdateChildren[]; +}; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 53d5b1cd..9acd9ae0 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -15,12 +15,13 @@ import { ProfileDuty } from "./ProfileDuty"; import { ProfileNopaid } from "./ProfileNopaid"; import { ProfileDiscipline } from "./ProfileDiscipline"; import { ProfileChangeName } from "./ProfileChangeName"; -import { ProfileChildren, ProfileFamilyHistory } from "./ProfileFamily"; +import { ProfileFamilyHistory } from "./ProfileFamily"; import { ProfileEducation } from "./ProfileEducation"; import { ProfileAbility } from "./ProfileAbility"; import { ProfileOther } from "./ProfileOther"; import { ProfileAvatar } from "./ProfileAvatar"; import { ProfileGovernment } from "./ProfileGovernment"; +import { ProfileChildren } from "./ProfileChildren"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @Column({ diff --git a/src/entities/ProfileFamily.ts b/src/entities/ProfileFamily.ts index eceef17d..baee34ff 100644 --- a/src/entities/ProfileFamily.ts +++ b/src/entities/ProfileFamily.ts @@ -167,114 +167,11 @@ export class ProfileFamilyHistory extends EntityBase { @ManyToOne(() => Profile, (v) => v.profileFamily) profile: Profile; - @OneToMany(() => ProfileChildrenHistory, (v) => v.profileFamilyHistory) - profileChildrenHistories: ProfileChildrenHistory[]; - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileFamilys) @JoinColumn({ name: "profileEmployeeId" }) profileEmployee: ProfileEmployee; } -@Entity("profileChildren") -export class ProfileChildren extends EntityBase { - @Column({ - nullable: true, - default: null, - comment: "อาชีพบุตร", - }) - childrenCareer: string; - - @Column({ - nullable: true, - default: null, - comment: "ชื่อบุตร", - }) - childrenFirstName: string; - - @Column({ - nullable: true, - default: null, - comment: "นามสกุลบุตร", - }) - childrenLastName: string; - - @Column({ - nullable: true, - default: null, - comment: "คำนำหน้าบุตร", - }) - childrenPrefix: string; - - @Column({ - nullable: true, - default: null, - type: "boolean", - comment: "มีชีวิตบุตร", - }) - childrenLive: boolean; - - @Column({ - nullable: true, - default: null, - comment: "เลขที่บัตรประชาชนบุตร", - }) - childrenCitizenId: string; - - @Column({ - nullable: true, - length: 40, - type: "uuid", - comment: "คีย์นอก(FK) ของตาราง Profile", - default: null, - }) - profileId: string; - - @Column({ - nullable: true, - length: 40, - comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", - default: null, - }) - profileEmployeeId: string; - - @ManyToOne(() => Profile, (v) => v.profileFamily, { onDelete: "CASCADE" }) - profile: Profile; - - @OneToMany(() => ProfileChildrenHistory, (v) => v.profileChildren) - histories: Profile; - - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChildrens) - @JoinColumn({ name: "profileEmployeeId" }) - profileEmployee: ProfileEmployee; -} - -@Entity("profileChildrenHistory") -export class ProfileChildrenHistory extends ProfileChildren { - @Column({ - nullable: true, - length: 40, - type: "uuid", - comment: "คีย์นอก(FK) ของตาราง Profile", - default: null, - }) - profileFamilyHistoryId: string; - - @ManyToOne(() => ProfileFamilyHistory, (v) => v.profileChildrenHistories, { onDelete: "CASCADE" }) - profileFamilyHistory: ProfileFamilyHistory; - - @Column({ - nullable: true, - length: 40, - type: "uuid", - comment: "คีย์นอก(FK) ของตาราง Profile", - default: null, - }) - profileChildrenId: string; - - @ManyToOne(() => ProfileChildren, (v) => v.histories, { onDelete: "CASCADE" }) - profileChildren: ProfileChildren; -} - export type CreateChildren = { childrenCareer: string; childrenFirstName: string; From 73ae98ce0e82fa912852baf8831dcaa8df209495 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 17:32:36 +0700 Subject: [PATCH 4/4] comment family --- src/controllers/ProfileFamilyHistoryController.ts | 8 ++++---- .../ProfileFamilyHistoryEmployeeController.ts | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 29424f1f..6d696560 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -16,8 +16,6 @@ import { AppDataSource } from "../database/data-source"; import { CreateChildren, CreateProfileFamily, - ProfileChildren, - ProfileChildrenHistory, ProfileFamilyHistory, UpdateProfileFamily, } from "../entities/ProfileFamily"; @@ -26,6 +24,8 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; +import { ProfileChildren } from "../entities/ProfileChildren"; +import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory"; @Route("api/v1/org/profile/family") @Tags("ProfileFamilyHistory") @@ -228,7 +228,7 @@ export class ProfileFamilyHistoryController extends Controller { ...v, children: await this.childrenHistoryRepo.find({ order: { createdAt: "ASC" }, - where: { profileFamilyHistoryId: v.id }, + // where: { profileFamilyHistoryId: v.id }, }), })), ); @@ -340,7 +340,7 @@ export class ProfileFamilyHistoryController extends Controller { return await this.childrenHistoryRepo.save( this.childrenHistoryRepo.create({ ...v, - profileFamilyHistoryId: familyRecord.id, + // profileFamilyHistoryId: familyRecord.id, profileChildrenId: v.id, id: undefined, }), diff --git a/src/controllers/ProfileFamilyHistoryEmployeeController.ts b/src/controllers/ProfileFamilyHistoryEmployeeController.ts index 98c1f0b3..ce34730d 100644 --- a/src/controllers/ProfileFamilyHistoryEmployeeController.ts +++ b/src/controllers/ProfileFamilyHistoryEmployeeController.ts @@ -15,10 +15,7 @@ import { import { AppDataSource } from "../database/data-source"; import { CreateChildren, - CreateProfileFamily, CreateProfileFamilyEmployee, - ProfileChildren, - ProfileChildrenHistory, ProfileFamilyHistory, UpdateProfileFamily, } from "../entities/ProfileFamily"; @@ -26,8 +23,9 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; -import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { ProfileChildren } from "../entities/ProfileChildren"; +import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory"; @Route("api/v1/org/profile-employee/family") @Tags("ProfileFamilyHistoryEmployee") @@ -230,7 +228,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { ...v, children: await this.childrenHistoryRepo.find({ order: { createdAt: "ASC" }, - where: { profileFamilyHistoryId: v.id }, + // where: { profileFamilyHistoryId: v.id }, }), })), ); @@ -342,7 +340,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { return await this.childrenHistoryRepo.save( this.childrenHistoryRepo.create({ ...v, - profileFamilyHistoryId: familyRecord.id, + // profileFamilyHistoryId: familyRecord.id, profileChildrenId: v.id, id: undefined, }), @@ -361,7 +359,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - + return new HttpSuccess(); } }