From 0114e41c3acf4dc4ba647a10ee113aea21ebc2b9 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 17:26:06 +0700 Subject: [PATCH 1/7] =?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 2/7] 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(); } } From 968842557a0e1a19f3c13e75c6765a812a3bd536 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 14 May 2024 17:39:32 +0700 Subject: [PATCH 3/7] family entity (father, mother, couple) --- src/entities/Profile.ts | 12 ++ src/entities/ProfileEmployee.ts | 13 ++ src/entities/ProfileFamilyCouple.ts | 145 +++++++++++++++++++++ src/entities/ProfileFamilyCoupleHistory.ts | 60 +++++++++ src/entities/ProfileFamilyFather.ts | 112 ++++++++++++++++ src/entities/ProfileFamilyFatherHistory.ts | 60 +++++++++ src/entities/ProfileFamilyMother.ts | 112 ++++++++++++++++ src/entities/ProfileFamilyMotherHistory.ts | 61 +++++++++ 8 files changed, 575 insertions(+) create mode 100644 src/entities/ProfileFamilyCouple.ts create mode 100644 src/entities/ProfileFamilyCoupleHistory.ts create mode 100644 src/entities/ProfileFamilyFather.ts create mode 100644 src/entities/ProfileFamilyFatherHistory.ts create mode 100644 src/entities/ProfileFamilyMother.ts create mode 100644 src/entities/ProfileFamilyMotherHistory.ts diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 1d7b8d04..a3f376a2 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -22,6 +22,9 @@ import { Province } from "./Province"; import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileFamilyFather } from "./ProfileFamilyFather"; +import { ProfileFamilyMother } from "./ProfileFamilyMother"; +import { ProfileFamilyCouple } from "./ProfileFamilyCouple"; @Entity("profile") export class Profile extends EntityBase { @@ -317,6 +320,15 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileHistory, (v) => v.profile) histories: ProfileHistory[]; + @OneToMany(() => ProfileFamilyFather, (v) => v.profile) + profileFamilyFather: ProfileFamilyFather[]; + + @OneToMany(() => ProfileFamilyMother, (v) => v.profile) + profileFamilyMother: ProfileFamilyMother[]; + + @OneToMany(() => ProfileFamilyCouple , (v) => v.profile) + profileFamilyCouple: ProfileFamilyCouple[]; + @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) @JoinColumn({ name: "posLevelId" }) posLevel: PosLevel; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 53d5b1cd..f9816235 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -21,6 +21,10 @@ import { ProfileAbility } from "./ProfileAbility"; import { ProfileOther } from "./ProfileOther"; import { ProfileAvatar } from "./ProfileAvatar"; import { ProfileGovernment } from "./ProfileGovernment"; +import { ProfileFamilyFather } from "./ProfileFamilyFather"; +import { ProfileFamilyMother } from "./ProfileFamilyMother"; +import { ProfileFamilyCouple } from "./ProfileFamilyCouple"; + @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @Column({ @@ -278,6 +282,15 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileGovernment, (v) => v.profileEmployee) profileGovernment: ProfileGovernment[]; + + @OneToMany(() => ProfileFamilyFather, (v) => v.profile) + profileFamilyFather: ProfileFamilyFather[]; + + @OneToMany(() => ProfileFamilyMother, (v) => v.profile) + profileFamilyMother: ProfileFamilyMother[]; + + @OneToMany(() => ProfileFamilyCouple , (v) => v.profile) + profileFamilyCouple: ProfileFamilyCouple[]; } @Entity("profileEmployeeHistory") diff --git a/src/entities/ProfileFamilyCouple.ts b/src/entities/ProfileFamilyCouple.ts new file mode 100644 index 00000000..0157177c --- /dev/null +++ b/src/entities/ProfileFamilyCouple.ts @@ -0,0 +1,145 @@ +import { Column, Entity, ManyToOne, OneToMany, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; +import { ProfileFamilyCoupleHistory } from "./ProfileFamilyCoupleHistory"; + +@Entity("profileFamilyCouple") +export class ProfileFamilyCouple extends EntityBase { + + @Column({ + nullable: true, + default: null, + type: "boolean", + }) + couple: boolean; + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าคู่สมรส", + }) + couplePrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อคู่สมรส", + }) + coupleFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลคู่สมรส", + }) + coupleLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลคู่สมรส(เดิม)", + }) + coupleLastNameOld: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพคู่สมรส", + }) + coupleCareer: string; + + @Column({ + nullable: true, + default: null, + length: 13, + comment: "เลขที่บัตรประชาชนคู่สมรส", + }) + coupleCitizenId: string; + + @Column({ + nullable: true, + default: null, + type: "boolean", + comment: "มีชีวิตคู่สมรส", + }) + coupleLive: boolean; + + @Column({ + nullable: true, + comment: "ความสัมพันธ์", + length: 40, + default: null, + }) + relationship: 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; + + @OneToMany( + () => ProfileFamilyCoupleHistory, + (v) => v.histories, + ) + profileFamilyCouple: ProfileFamilyCoupleHistory[]; + + @ManyToOne(() => Profile, (v) => v.profileFamilyCouple) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (v) => v.profileFamilyCouple) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; + +} + +export type CreateProfileFamilyCouple= { + profileId: string; + couple: boolean | null; + couplePrefix: string | null; + coupleFirstName: string | null; + coupleLastName: string | null; + coupleLastNameOld: string | null; + coupleCareer: string | null; + coupleCitizenId: string | null; + coupleLive: boolean | null; + relationship: string | null; +} + +export type CreateProfileEmployeeFamilyCouple= { + profileEmployeeId: string; + couple: boolean | null; + couplePrefix: string | null; + coupleFirstName: string | null; + coupleLastName: string | null; + coupleLastNameOld: string | null; + coupleCareer: string | null; + coupleCitizenId: string | null; + coupleLive: boolean | null; + relationship: string | null; +} + +export type UpdateProfileFamilyCouple = { + couple?: boolean | null; + couplePrefix?: string | null; + coupleFirstName?: string | null; + coupleLastName?: string | null; + coupleLastNameOld?: string | null; + coupleCareer?: string | null; + coupleCitizenId?: string | null; + coupleLive?: boolean | null; + relationship: string | null; +}; diff --git a/src/entities/ProfileFamilyCoupleHistory.ts b/src/entities/ProfileFamilyCoupleHistory.ts new file mode 100644 index 00000000..d831bf3a --- /dev/null +++ b/src/entities/ProfileFamilyCoupleHistory.ts @@ -0,0 +1,60 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { ProfileFamilyCouple } from "./ProfileFamilyCouple"; + +@Entity("profileFamilyCoupleHistory") +export class ProfileFamilyCoupleHistory extends EntityBase { + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าบิดา", + }) + fatherPrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อบิดา", + }) + fatherFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลบิดา", + }) + fatherLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพบิดา", + }) + fatherCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนบิดา", + }) + fatherCitizenId: string; + + @Column({ + nullable: true, + default: null, + comment: "มีชีวิตบิดา", + }) + fatherLive: boolean; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileFamilyFather", + default: null, + }) + profileFamilyCoupleId: string; + + @ManyToOne(() => ProfileFamilyCouple, (v) => v.profileFamilyCouple) + @JoinColumn({ name: "profileFamilyCoupleId" }) + histories: ProfileFamilyCouple; +} diff --git a/src/entities/ProfileFamilyFather.ts b/src/entities/ProfileFamilyFather.ts new file mode 100644 index 00000000..8b56d64e --- /dev/null +++ b/src/entities/ProfileFamilyFather.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 { ProfileFamilyFatherHistory } from "./ProfileFamilyFatherHistory"; + +@Entity("profileFamilyFather") +export class ProfileFamilyFather extends EntityBase { + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าบิดา", + }) + fatherPrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อบิดา", + }) + fatherFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลบิดา", + }) + fatherLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพบิดา", + }) + fatherCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนบิดา", + }) + fatherCitizenId: string; + + @Column({ + nullable: true, + default: null, + comment: "มีชีวิตบิดา", + }) + fatherLive: boolean; + + @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; + + @OneToMany( + () => ProfileFamilyFatherHistory, + (v) => v.histories, + ) + profileFamilyFather: ProfileFamilyFatherHistory[]; + + @ManyToOne(() => Profile, (v) => v.profileFamilyFather) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (v) => v.profileFamilyFather) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; + +} + +export type CreateProfileFamilyFather = { + profileId: string; + fatherPrefix: string | null; + fatherFirstName: string | null; + fatherLastName: string | null; + fatherCareer: string | null; + fatherCitizenId: string | null; + fatherLive: boolean | null; +} + +export type CreateProfileEmployeeFamilyFather = { + profileEmployeeId: string; + fatherPrefix: string | null; + fatherFirstName: string | null; + fatherLastName: string | null; + fatherCareer: string | null; + fatherCitizenId: string | null; + fatherLive: boolean | null; +} + +export type UpdateProfileFamilyFather = { + fatherPrefix?: string | null; + fatherFirstName?: string | null; + fatherLastName?: string | null; + fatherCareer?: string | null; + fatherCitizenId?: string | null; + fatherLive?: boolean | null; +}; diff --git a/src/entities/ProfileFamilyFatherHistory.ts b/src/entities/ProfileFamilyFatherHistory.ts new file mode 100644 index 00000000..dd99f6be --- /dev/null +++ b/src/entities/ProfileFamilyFatherHistory.ts @@ -0,0 +1,60 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { ProfileFamilyFather } from "./ProfileFamilyFather"; + +@Entity("profileFamilyFatherHistory") +export class ProfileFamilyFatherHistory extends EntityBase { + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้าบิดา", + }) + fatherPrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อบิดา", + }) + fatherFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลบิดา", + }) + fatherLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพบิดา", + }) + fatherCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนบิดา", + }) + fatherCitizenId: string; + + @Column({ + nullable: true, + default: null, + comment: "มีชีวิตบิดา", + }) + fatherLive: boolean; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileFamilyFather", + default: null, + }) + profileFamilyFatherId: string; + + @ManyToOne(() => ProfileFamilyFather, (v) => v.profileFamilyFather) + @JoinColumn({ name: "profileFamilyFatherId" }) + histories: ProfileFamilyFather; +} diff --git a/src/entities/ProfileFamilyMother.ts b/src/entities/ProfileFamilyMother.ts new file mode 100644 index 00000000..c143237d --- /dev/null +++ b/src/entities/ProfileFamilyMother.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 { ProfileFamilyMotherHistory } from "./ProfileFamilyMotherHistory"; + +@Entity("profileFamilyMother") +export class ProfileFamilyMother extends EntityBase { + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้ามารดา", + }) + motherPrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อมารดา", + }) + motherFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลมารดา", + }) + motherLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพบิดา", + }) + motherCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนมารดา", + }) + motherCitizenId: string; + + @Column({ + nullable: true, + default: null, + comment: "มีชีวิตมารดา", + }) + motherLive: boolean; + + @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; + + @OneToMany( + () => ProfileFamilyMotherHistory, + (v) => v.histories, + ) + profileFamilyMother: ProfileFamilyMotherHistory[]; + + @ManyToOne(() => Profile, (v) => v.profileFamilyMother) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (v) => v.profileFamilyMother) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; + +} + +export type CreateProfileFamilyMother = { + profileId: string; + motherPrefix: string | null; + motherFirstName: string | null; + motherLastName: string | null; + motherCareer: string | null; + motherCitizenId: string | null; + motherLive: boolean | null; +} + +export type CreateProfileEmployeeFamilyMother= { + profileEmployeeId: string; + motherPrefix: string | null; + motherFirstName: string | null; + motherLastName: string | null; + motherCareer: string | null; + motherCitizenId: string | null; + motherLive: boolean | null; +} + +export type UpdateProfileFamilyMother= { + motherPrefix: string | null; + motherFirstName: string | null; + motherLastName: string | null; + motherCareer: string | null; + motherCitizenId: string | null; + motherLive: boolean | null; +}; diff --git a/src/entities/ProfileFamilyMotherHistory.ts b/src/entities/ProfileFamilyMotherHistory.ts new file mode 100644 index 00000000..90fd6a90 --- /dev/null +++ b/src/entities/ProfileFamilyMotherHistory.ts @@ -0,0 +1,61 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { ProfileFamilyMother } from "./ProfileFamilyMother"; + +@Entity("profileFamilyMotherHistory") +export class ProfileFamilyMotherHistory extends EntityBase { + + @Column({ + nullable: true, + default: null, + comment: "คำนำหน้ามารดา", + }) + motherPrefix: string; + + @Column({ + nullable: true, + default: null, + comment: "ชื่อมารดา", + }) + motherFirstName: string; + + @Column({ + nullable: true, + default: null, + comment: "นามสกุลมารดา", + }) + motherLastName: string; + + @Column({ + nullable: true, + default: null, + comment: "อาชีพบิดา", + }) + motherCareer: string; + + @Column({ + nullable: true, + default: null, + comment: "เลขที่บัตรประชาชนมารดา", + }) + motherCitizenId: string; + + @Column({ + nullable: true, + default: null, + comment: "มีชีวิตมารดา", + }) + motherLive: boolean; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileFamilyMother", + default: null, + }) + profileFamilyMotherId: string; + + @ManyToOne(() => ProfileFamilyMother, (v) => v.profileFamilyMother) + @JoinColumn({ name: "profileFamilyMotherId" }) + histories: ProfileFamilyMother; +} From 27fefee8d79007eb60aa31c3e2e0a1c97ed8467f Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 17:54:17 +0700 Subject: [PATCH 4/7] =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B5=E0=B9=88=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/Profile.ts | 12 +++++- src/entities/ProfileEmployee.ts | 40 +++++++++++-------- .../1715683984766-add_table_dateRetire.ts | 24 +++++++++++ 3 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 src/migration/1715683984766-add_table_dateRetire.ts diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 23a70f3b..e5ab9173 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -154,7 +154,7 @@ export class Profile extends EntityBase { @Column({ nullable: true, type: "datetime", - comment: "วันที่พักราชการ", + comment: "วันครบเกษียณอายุ", default: null, }) dateRetire: Date; @@ -167,6 +167,14 @@ export class Profile extends EntityBase { }) dateAppoint: Date; + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่เกษียณอายุราชการตามกฏหมาย", + default: null, + }) + dateRetireLaw: Date; + @Column({ nullable: true, type: "datetime", @@ -327,7 +335,7 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileFamilyMother, (v) => v.profile) profileFamilyMother: ProfileFamilyMother[]; - @OneToMany(() => ProfileFamilyCouple , (v) => v.profile) + @OneToMany(() => ProfileFamilyCouple, (v) => v.profile) profileFamilyCouple: ProfileFamilyCouple[]; @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 1b5df5ca..6d0e334a 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -135,7 +135,7 @@ export class ProfileEmployee extends EntityBase { @Column({ nullable: true, type: "datetime", - comment: "วันที่พักราชการ", + comment: "วันครบเกษียณอายุ", default: null, }) dateRetire: Date; @@ -148,6 +148,14 @@ export class ProfileEmployee extends EntityBase { }) birthDate: Date; + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่เกษียณอายุราชการตามกฏหมาย", + default: null, + }) + dateRetireLaw: Date; + @Column({ type: "double", nullable: true, @@ -286,7 +294,7 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileFamilyMother, (v) => v.profile) profileFamilyMother: ProfileFamilyMother[]; - @OneToMany(() => ProfileFamilyCouple , (v) => v.profile) + @OneToMany(() => ProfileFamilyCouple, (v) => v.profile) profileFamilyCouple: ProfileFamilyCouple[]; } @@ -309,22 +317,22 @@ export class CreateProfileEmployee { prefix: string; firstName: string; lastName: string; - position: string; - isProbation: boolean | null; - dateRetire: Date | null; + // position: string; + // isProbation: boolean | null; + // dateRetire: Date | null; birthDate: Date | null; salaryLevel: number | null; - ethnicity: string | null; - telephoneNumber: string | null; + // ethnicity: string | null; + // telephoneNumber: string | null; citizenId: string; - religion: string | null; + // religion: string | null; posLevelId: string | null; posTypeId: string | null; - gender: string | null; - relationship: string | null; - bloodGroup: string | null; - email: string | null; - phone: string | null; + // gender: string | null; + // relationship: string | null; + // bloodGroup: string | null; + // email: string | null; + // phone: string | null; } export type UpdateProfileEmployee = { @@ -332,9 +340,9 @@ export type UpdateProfileEmployee = { prefix?: string | null; firstName?: string | null; lastName?: string | null; - position?: string | null; - isProbation?: boolean | null; - dateRetire?: Date | null; + // position?: string | null; + // isProbation?: boolean | null; + // dateRetire?: Date | null; birthDate?: Date | null; salaryLevel?: number | null; ethnicity?: string | null; diff --git a/src/migration/1715683984766-add_table_dateRetire.ts b/src/migration/1715683984766-add_table_dateRetire.ts new file mode 100644 index 00000000..5ddaf272 --- /dev/null +++ b/src/migration/1715683984766-add_table_dateRetire.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDateRetire1715683984766 implements MigrationInterface { + name = 'AddTableDateRetire1715683984766' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`dateRetireLaw\` datetime NULL COMMENT 'วันที่เกษียณอายุราชการตามกฏหมาย'`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`dateRetireLaw\` datetime NULL COMMENT 'วันที่เกษียณอายุราชการตามกฏหมาย'`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`dateRetireLaw\` datetime NULL COMMENT 'วันที่เกษียณอายุราชการตามกฏหมาย'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`dateRetireLaw\` datetime NULL COMMENT 'วันที่เกษียณอายุราชการตามกฏหมาย'`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันครบเกษียณอายุ'`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันครบเกษียณอายุ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันที่พักราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันที่พักราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`dateRetireLaw\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`dateRetireLaw\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`dateRetireLaw\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`dateRetireLaw\``); + } + +} From 20ccb3f26d96353801854f6019350f8601dca699 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 15 May 2024 10:04:19 +0700 Subject: [PATCH 5/7] Fix District/subDistrict --- src/controllers/DistrictController.ts | 17 ++++++++ src/controllers/SubDistrictController.ts | 51 ++++++++++++++++-------- src/entities/District.ts | 3 ++ src/entities/SubDistrict.ts | 3 ++ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/controllers/DistrictController.ts b/src/controllers/DistrictController.ts index 5966c185..778cc249 100644 --- a/src/controllers/DistrictController.ts +++ b/src/controllers/DistrictController.ts @@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { District, CreateDistrict, UpdateDistrict } from "../entities/District"; +import { Province } from "../entities/Province"; import { Not } from "typeorm"; @Route("api/v1/org/metadata/district") @@ -30,6 +31,7 @@ import { Not } from "typeorm"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class DistrictController extends Controller { private districtRepository = AppDataSource.getRepository(District); + private provinceRepository = AppDataSource.getRepository(Province); /** * API list รายการเขต @@ -84,6 +86,13 @@ export class DistrictController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้"); } + const chkProvince = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceId } + }) + if(!chkProvince){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้"); + } + const checkName = await this.districtRepository.findOne({ where: { name: requestBody.name }, }); @@ -118,6 +127,14 @@ export class DistrictController extends Controller { if (!_district) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้"); } + + const chkProvince = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceId } + }) + if(!chkProvince){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้"); + } + const checkName = await this.districtRepository.findOne({ where: { id: Not(id), name: requestBody.name }, }); diff --git a/src/controllers/SubDistrictController.ts b/src/controllers/SubDistrictController.ts index ced1e659..2d93445c 100644 --- a/src/controllers/SubDistrictController.ts +++ b/src/controllers/SubDistrictController.ts @@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict"; +import { District } from "../entities/District"; import { Not } from "typeorm"; @Route("api/v1/org/metadata/subDistrict") @@ -30,11 +31,12 @@ import { Not } from "typeorm"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class SubDistrictController extends Controller { private subDistrictRepository = AppDataSource.getRepository(SubDistrict); + private districtRepository = AppDataSource.getRepository(District); /** - * API list รายการเพศ + * API list รายการแขวง * - * @summary ORG_058 - CRUD เพศ (ADMIN) #62 + * @summary ORG_058 - CRUD แขวง (ADMIN) #62 * */ @Get() @@ -47,11 +49,11 @@ export class SubDistrictController extends Controller { } /** - * API รายละเอียดรายการเพศ + * API รายละเอียดรายการแขวง * - * @summary ORG_058 - CRUD เพศ (ADMIN) #62 + * @summary ORG_058 - CRUD แขวง (ADMIN) #62 * - * @param {string} id Id เพศ + * @param {string} id Id แขวง */ @Get("{id}") async GetById(@Path() id: string) { @@ -60,16 +62,16 @@ export class SubDistrictController extends Controller { select: ["id", "name"], }); if (!_subDistrict) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้"); } return new HttpSuccess(_subDistrict); } /** - * API สร้างรายการ body เพศ + * API สร้างรายการ body แขวง * - * @summary ORG_058 - CRUD เพศ (ADMIN) #62 + * @summary ORG_058 - CRUD แขวง (ADMIN) #62 * */ @Post() @@ -80,7 +82,14 @@ export class SubDistrictController extends Controller { ) { const _subDistrict = Object.assign(new SubDistrict(), requestBody); if (!_subDistrict) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้"); + } + + const chkDistrict = await this.districtRepository.findOne({ + where: { id: requestBody.districtId } + }) + if (!chkDistrict) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้"); } const checkName = await this.subDistrictRepository.findOne({ @@ -100,11 +109,11 @@ export class SubDistrictController extends Controller { } /** - * API แก้ไขรายการ body เพศ + * API แก้ไขรายการ body แขวง * - * @summary ORG_058 - CRUD เพศ (ADMIN) #62 + * @summary ORG_058 - CRUD แขวง (ADMIN) #62 * - * @param {string} id Id เพศ + * @param {string} id Id แขวง */ @Put("{id}") async Put( @@ -115,8 +124,16 @@ export class SubDistrictController extends Controller { ) { const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } }); if (!_subDistrict) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้"); } + + const chkDistrict = await this.districtRepository.findOne({ + where: { id: requestBody.districtId } + }) + if (!chkDistrict) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้"); + } + const checkName = await this.subDistrictRepository.findOne({ where: { id: Not(id), name: requestBody.name }, }); @@ -132,11 +149,11 @@ export class SubDistrictController extends Controller { } /** - * API ลบรายการเพศ + * API ลบรายการแขวง * - * @summary ORG_058 - CRUD เพศ (ADMIN) #62 + * @summary ORG_058 - CRUD แขวง (ADMIN) #62 * - * @param {string} id Id เพศ + * @param {string} id Id แขวง */ @Delete("{id}") async Delete(@Path() id: string) { @@ -144,7 +161,7 @@ export class SubDistrictController extends Controller { where: { id: id }, }); if (!_delSubDistrict) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้"); } await this.subDistrictRepository.delete(_delSubDistrict.id); return new HttpSuccess(); diff --git a/src/entities/District.ts b/src/entities/District.ts index f6c1b639..61e292cc 100644 --- a/src/entities/District.ts +++ b/src/entities/District.ts @@ -36,6 +36,9 @@ export class District extends EntityBase { export class CreateDistrict { @Column() name: string; + + @Column() + provinceId: string; } export type UpdateDistrict = Partial; diff --git a/src/entities/SubDistrict.ts b/src/entities/SubDistrict.ts index ae54c6da..a9435dff 100644 --- a/src/entities/SubDistrict.ts +++ b/src/entities/SubDistrict.ts @@ -40,6 +40,9 @@ export class SubDistrict extends EntityBase { export class CreateSubDistrict { @Column() name: string; + + @Column() + districtId: string; } export type UpdateSubDistrict = Partial; From 34d988b8a405d2679c7c56bc10febeb2c7502214 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 15 May 2024 11:29:32 +0700 Subject: [PATCH 6/7] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20zipcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/SubDistrict.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/entities/SubDistrict.ts b/src/entities/SubDistrict.ts index a9435dff..8d7a325d 100644 --- a/src/entities/SubDistrict.ts +++ b/src/entities/SubDistrict.ts @@ -43,6 +43,9 @@ export class CreateSubDistrict { @Column() districtId: string; + + @Column() + zipCode: string; } export type UpdateSubDistrict = Partial; From e4d7c034e8ea8c135e2e4c9c2bae812bf01c9344 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 15 May 2024 11:42:37 +0700 Subject: [PATCH 7/7] no message --- src/controllers/SubDistrictController.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controllers/SubDistrictController.ts b/src/controllers/SubDistrictController.ts index 2d93445c..3ea667c8 100644 --- a/src/controllers/SubDistrictController.ts +++ b/src/controllers/SubDistrictController.ts @@ -93,7 +93,10 @@ export class SubDistrictController extends Controller { } const checkName = await this.subDistrictRepository.findOne({ - where: { name: requestBody.name }, + where: { + name: requestBody.name, + districtId: requestBody.districtId + }, }); if (checkName) { @@ -135,7 +138,11 @@ export class SubDistrictController extends Controller { } const checkName = await this.subDistrictRepository.findOne({ - where: { id: Not(id), name: requestBody.name }, + where: { + id: Not(id), + name: requestBody.name, + districtId: requestBody.districtId + }, }); if (checkName) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");