From 85c60939706f0d26768c268e375fe66635baf402 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 19 Jul 2024 11:08:47 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=84=E0=B8=B3=E0=B8=82=E0=B8=AD?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 18 +- src/controllers/ProfileEditController.ts | 190 +++++++++++++++++ .../ProfileEditEmployeeController.ts | 197 ++++++++++++++++++ src/controllers/ProfileEmployeeController.ts | 29 +-- src/entities/Profile.ts | 4 + src/entities/ProfileEdit.ts | 90 ++++++++ src/entities/ProfileEmployee.ts | 30 +-- .../1721360319146-add_table_profileedit.ts | 18 ++ 8 files changed, 546 insertions(+), 30 deletions(-) create mode 100644 src/controllers/ProfileEditController.ts create mode 100644 src/controllers/ProfileEditEmployeeController.ts create mode 100644 src/entities/ProfileEdit.ts create mode 100644 src/migration/1721360319146-add_table_profileedit.ts diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index fb1a01c6..d2255fa0 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -36,6 +36,7 @@ import { calculateRetireDate, calculateRetireLaw, calculateRetireYear, + removeProfileInOrganize, } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import { Position } from "../entities/Position"; @@ -1451,6 +1452,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } let dateLeave_: any = body.date; + await removeProfileInOrganize(profile.id); profile.isLeave = true; profile.leaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; @@ -1523,6 +1525,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } let dateLeave_: any = body.date; + await removeProfileInOrganize(profile.id); profile.isLeave = true; profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; profile.dateLeave = dateLeave_; @@ -1594,6 +1597,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } let dateLeave_: any = body.date; + await removeProfileInOrganize(profile.id); profile.isLeave = true; profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; profile.dateLeave = dateLeave_; @@ -1679,6 +1683,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } let dateLeave_: any = body.date; + await removeProfileInOrganize(profile.id); profile.isLeave = true; profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; profile.dateLeave = dateLeave_; @@ -1750,6 +1755,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } let dateLeave_: any = body.date; + await removeProfileInOrganize(profile.id); profile.isLeave = true; profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; profile.dateLeave = dateLeave_; @@ -4879,6 +4885,9 @@ export class ProfileController extends Controller { if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const _null: any = null; profile.isLeave = requestBody.isLeave; + if (requestBody.isLeave == true) { + await removeProfileInOrganize(profile.id); + } if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) { profile.leaveReason = requestBody.leaveReason; } else { @@ -4890,11 +4899,10 @@ export class ProfileController extends Controller { profile.dateLeave = _null; } await this.profileRepo.save(profile); - - const profileSalary = await this.salaryRepository.findOne({ - where: { profileId: id }, - order: { createdAt: "DESC" }, - }); + // const profileSalary = await this.salaryRepository.findOne({ + // where: { profileId: id }, + // order: { createdAt: "DESC" }, + // }); return new HttpSuccess(); } diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts new file mode 100644 index 00000000..1e9d8753 --- /dev/null +++ b/src/controllers/ProfileEditController.ts @@ -0,0 +1,190 @@ +import { + Body, + Controller, + Delete, + Get, + Patch, + Path, + Post, + Query, + Request, + Route, + Security, + Tags, +} from "tsoa"; +import HttpError from "../interfaces/http-error"; +import HttpStatus from "../interfaces/http-status"; +import HttpSuccess from "../interfaces/http-success"; +import { AppDataSource } from "../database/data-source"; +import { Profile } from "../entities/Profile"; +import { CreateProfileEdit, EditProfileEdit, ProfileEdit } from "../entities/ProfileEdit"; +import { RequestWithUser } from "../middlewares/user"; +import { IsNull, Not } from "typeorm"; + +@Route("api/v1/org/profile/edit") +@Tags("ProfileEdit") +@Security("bearerAuth") +export class ProfileEditController extends Controller { + private profileRepo = AppDataSource.getRepository(Profile); + private profileEditRepo = AppDataSource.getRepository(ProfileEdit); + + @Get("user") + public async detailProfileEditUser( + @Request() request: { user: Record }, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword: string = "", + ) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + .createQueryBuilder("ProfileEdit") + .leftJoinAndSelect("ProfileEdit.profile", "profile") + .where({ + profileId: profile.id, + }) + .orderBy("ProfileEdit.createdAt", "ASC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const _data = getProfileEdit.map((item) => ({ + id: item.id, + topic: item.topic, + detail: item.detail, + status: item.status, + remark: item.remark, + createdAt: item.createdAt, + createdFullName: item.createdFullName, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateFullName: item.lastUpdateFullName, + fullname: + (item?.profile?.prefix ?? "") + + "" + + (item?.profile?.firstName ?? "") + + " " + + (item?.profile?.lastName ?? ""), + })); + return new HttpSuccess({ data: _data, total: total }); + } + + @Get("admin") + public async detailProfileEditAdmin( + @Request() request: { user: Record }, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword: string = "", + ) { + let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + .createQueryBuilder("ProfileEdit") + .leftJoinAndSelect("ProfileEdit.profile", "profile") + .where({ + profileId: Not(IsNull()), + }) + .orderBy("ProfileEdit.createdAt", "ASC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const _data = getProfileEdit.map((item) => ({ + id: item.id, + topic: item.topic, + detail: item.detail, + status: item.status, + remark: item.remark, + createdAt: item.createdAt, + createdFullName: item.createdFullName, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateFullName: item.lastUpdateFullName, + fullname: + (item?.profile?.prefix ?? "") + + "" + + (item?.profile?.firstName ?? "") + + " " + + (item?.profile?.lastName ?? ""), + })); + return new HttpSuccess({ data: _data, total: total }); + } + + @Get("{profileId}") + public async detailProfileEdit(@Path() profileId: string) { + const getProfileEdit = await this.profileEditRepo.findOne({ + where: { profileId: profileId }, + relations: ["profile"], + }); + if (!getProfileEdit) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + const _data = { + id: getProfileEdit.id, + topic: getProfileEdit.topic, + detail: getProfileEdit.detail, + status: getProfileEdit.status, + remark: getProfileEdit.remark, + createdAt: getProfileEdit.createdAt, + createdFullName: getProfileEdit.createdFullName, + lastUpdatedAt: getProfileEdit.lastUpdatedAt, + lastUpdateFullName: getProfileEdit.lastUpdateFullName, + fullname: + (getProfileEdit?.profile?.prefix ?? "") + + "" + + (getProfileEdit?.profile?.firstName ?? "") + + " " + + (getProfileEdit?.profile?.lastName ?? ""), + }; + return new HttpSuccess(_data); + } + + @Post() + public async newProfileEdit(@Request() req: RequestWithUser, @Body() body: CreateProfileEdit) { + const profile = await this.profileRepo.findOneBy({ keycloak: req.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileEdit(); + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + data.status = "PENDING"; + await this.profileEditRepo.save(data); + + return new HttpSuccess(data.id); + } + + @Patch("{editId}") + public async editProfileEdit( + @Body() requestBody: EditProfileEdit, + @Request() req: RequestWithUser, + @Path() editId: string, + ) { + const record = await this.profileEditRepo.findOneBy({ id: editId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + Object.assign(record, requestBody); + + record.lastUpdateFullName = req.user.name; + record.lastUpdateUserId = req.user.sub; + record.lastUpdatedAt = new Date(); + await Promise.all([this.profileEditRepo.save(record)]); + + return new HttpSuccess(); + } + + @Delete("{editId}") + public async deleteProfileEdit(@Path() editId: string) { + const result = await this.profileEditRepo.delete({ id: editId }); + + if (result.affected == undefined || result.affected <= 0) + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + return new HttpSuccess(); + } +} diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts new file mode 100644 index 00000000..8a1e010e --- /dev/null +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -0,0 +1,197 @@ +import { + Controller, + Post, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Get, + Patch, + Query, +} from "tsoa"; +import HttpError from "../interfaces/http-error"; +import HttpStatus from "../interfaces/http-status"; +import HttpSuccess from "../interfaces/http-success"; +import { AppDataSource } from "../database/data-source"; +import { + CreateProfileEmployeeEdit, + EditProfileEmployeeEdit, + ProfileEdit, +} from "../entities/ProfileEdit"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { RequestWithUser } from "../middlewares/user"; +import { IsNull, Not } from "typeorm"; + +@Route("api/v1/org/profile-employee/edit") +@Tags("ProfileEmployeeEdit") +@Security("bearerAuth") +export class ProfileEditEmployeeController extends Controller { + private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); + private profileEditRepository = AppDataSource.getRepository(ProfileEdit); + + @Get("user") + public async detailProfileEditUser( + @Request() request: { user: Record }, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword: string = "", + ) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + .createQueryBuilder("ProfileEdit") + .leftJoinAndSelect("ProfileEdit.profileEmployeeId", "profileEmployeeId") + .where({ + profileEmployeeId: profile.id, + }) + .orderBy("ProfileEdit.createdAt", "ASC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const _data = getProfileEdit.map((item) => ({ + id: item.id, + topic: item.topic, + detail: item.detail, + status: item.status, + remark: item.remark, + createdAt: item.createdAt, + createdFullName: item.createdFullName, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateFullName: item.lastUpdateFullName, + fullname: + (item?.profileEmployee?.prefix ?? "") + + "" + + (item?.profileEmployee?.firstName ?? "") + + " " + + (item?.profileEmployee?.lastName ?? ""), + })); + return new HttpSuccess({ data: _data, total: total }); + } + + @Get("admin") + public async detailProfileEditAdmin( + @Request() request: { user: Record }, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword: string = "", + ) { + let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + .createQueryBuilder("ProfileEdit") + .leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee") + .where({ + profileEmployeeId: Not(IsNull()), + }) + .orderBy("ProfileEdit.createdAt", "ASC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const _data = getProfileEdit.map((item) => ({ + id: item.id, + topic: item.topic, + detail: item.detail, + status: item.status, + remark: item.remark, + createdAt: item.createdAt, + createdFullName: item.createdFullName, + lastUpdatedAt: item.lastUpdatedAt, + lastUpdateFullName: item.lastUpdateFullName, + fullname: + (item?.profileEmployee?.prefix ?? "") + + "" + + (item?.profileEmployee?.firstName ?? "") + + " " + + (item?.profileEmployee?.lastName ?? ""), + })); + return new HttpSuccess({ data: _data, total: total }); + } + + @Get("{profileEmployeeId}") + public async detailProfileEdit(@Path() profileEmployeeId: string) { + const getProfileEdit = await this.profileEditRepository.findOne({ + where: { profileEmployeeId: profileEmployeeId }, + relations: ["profileEmployee"], + }); + if (!getProfileEdit) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + const _data = { + id: getProfileEdit.id, + topic: getProfileEdit.topic, + detail: getProfileEdit.detail, + status: getProfileEdit.status, + remark: getProfileEdit.remark, + createdAt: getProfileEdit.createdAt, + createdFullName: getProfileEdit.createdFullName, + lastUpdatedAt: getProfileEdit.lastUpdatedAt, + lastUpdateFullName: getProfileEdit.lastUpdateFullName, + fullname: + (getProfileEdit?.profileEmployee?.prefix ?? "") + + "" + + (getProfileEdit?.profileEmployee?.firstName ?? "") + + " " + + (getProfileEdit?.profileEmployee?.lastName ?? ""), + }; + return new HttpSuccess(_data); + } + + @Post() + public async profileEdit( + @Request() req: RequestWithUser, + @Body() body: CreateProfileEmployeeEdit, + ) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: req.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileEdit(); + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + Object.assign(data, { ...body, ...meta }); + data.status = "PENDING"; + await this.profileEditRepository.save(data); + + return new HttpSuccess(data.id); + } + + @Patch("{editId}") + public async editProfileEdit( + @Body() requestBody: EditProfileEmployeeEdit, + @Request() req: RequestWithUser, + @Path() editId: string, + ) { + const record = await this.profileEditRepository.findOneBy({ id: editId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + Object.assign(record, requestBody); + + record.lastUpdateFullName = req.user.name; + record.lastUpdateUserId = req.user.sub; + record.lastUpdatedAt = new Date(); + + await Promise.all([this.profileEditRepository.save(record)]); + return new HttpSuccess(); + } + + @Delete("{editId}") + public async deleteProfileEdit(@Path() editId: string) { + const result = await this.profileEditRepository.delete({ id: editId }); + + if (result.affected == undefined || result.affected <= 0) + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + return new HttpSuccess(); + } +} diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a5e65b86..5b914e16 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -20,7 +20,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Brackets, Double, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; -import { calculateRetireDate, calculateRetireLaw } from "../interfaces/utils"; +import { + calculateRetireDate, + calculateRetireLaw, + removeProfileInOrganize, +} from "../interfaces/utils"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { ProfileEmployee, @@ -360,7 +364,7 @@ export class ProfileEmployeeController extends Controller { District: "", Area: "", Province: "", - Telephone: + Telephone: profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null, CouplePrefix: profileFamilyCouple?.couplePrefix ?? "", @@ -400,8 +404,8 @@ export class ProfileEmployeeController extends Controller { profiles.dateRetireLaw != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw)) : "", - CurrentAddress: - profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "", + CurrentAddress: + profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "", CurrentSubDistrict: profiles.currentSubDistrict != null ? Extension.ToThaiNumber(profiles.currentSubDistrict.name) @@ -438,9 +442,7 @@ export class ProfileEmployeeController extends Controller { ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), End: - item.endDate == null - ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), + item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), Date: item.startDate && item.endDate ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` @@ -455,7 +457,7 @@ export class ProfileEmployeeController extends Controller { where: { profileEmployeeId: id }, }); const Discipline = disciplines.map((item) => ({ - DisciplineYear: + DisciplineYear: Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null, DisciplineDetail: item.detail ?? null, RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, @@ -468,11 +470,11 @@ export class ProfileEmployeeController extends Controller { }); const Education = educations.map((item) => ({ Institute: item.institute ?? null, - Start: + Start: item.startDate == null ? "" : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), - End: + End: item.endDate == null ? "" : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), @@ -1329,8 +1331,8 @@ export class ProfileEmployeeController extends Controller { .map((x) => x.next_holderId), }); }), - ) - .andWhere("profileEmployee.employeeClass = :employeeClass", {employeeClass:"PERM"}) + ) + .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "PERM" }) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount(); @@ -2757,6 +2759,9 @@ export class ProfileEmployeeController extends Controller { profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; + if (requestBody.isLeave == true) { + await removeProfileInOrganize(profile.id); + } await this.profileRepo.save(profile); const profileSalary = await this.salaryRepository.findOne({ diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 72e57e2b..b4fc6a92 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -27,6 +27,7 @@ import { ProfileFamilyCouple } from "./ProfileFamilyCouple"; import { ProfileChildren } from "./ProfileChildren"; import { ProfileDiscipline } from "./ProfileDiscipline"; import { ProfileEmployee } from "./ProfileEmployee"; +import { ProfileEdit } from "./ProfileEdit"; @Entity("profile") export class Profile extends EntityBase { @@ -340,6 +341,9 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileAvatar, (profileAvatar) => profileAvatar.profile) profileAvatars: ProfileAvatar[]; + @OneToMany(() => ProfileEdit, (profileEdit) => profileEdit.profile) + profileEdits: ProfileEdit[]; + @OneToMany(() => ProfileFamilyHistory, (profileFamily) => profileFamily.profile) profileFamily: ProfileFamilyHistory[]; diff --git a/src/entities/ProfileEdit.ts b/src/entities/ProfileEdit.ts new file mode 100644 index 00000000..b3980a2c --- /dev/null +++ b/src/entities/ProfileEdit.ts @@ -0,0 +1,90 @@ +import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; + +@Entity("profileEdit") +export class ProfileEdit extends EntityBase { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง Profile", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", + default: null, + }) + profileEmployeeId: string; + + @Column({ + nullable: true, + comment: "สถานะคำร้อง", //PENDING = รอดำเนินการ, COMPLETE = ดำเนินการแก้ไขแล้ว, REJECT = ไม่อนุมัตการแก้ไข + default: null, + }) + status: string; + + @Column({ + nullable: true, + comment: "ชื่อเรื่อง", + default: null, + }) + topic: string; + + @Column({ + nullable: true, + comment: "รายละเอียด", + type: "text", + default: null, + }) + detail: string; + + @Column({ + nullable: true, + comment: "หมายเหตุ", + type: "text", + default: null, + }) + remark: string; + + @ManyToOne(() => Profile, (profile) => profile.profileEdits) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileEdits) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; +} + +export class CreateProfileEdit { + topic: string | null; + detail: string | null; +} + +export class EditProfileEdit { + topic?: string | null; + detail?: string | null; + remark?: string | null; + status?: string | null; +} + +export class CreateProfileEmployeeEdit { + topic: string | null; + detail: string | null; +} + +export class EditProfileEmployeeEdit { + topic?: string | null; + detail?: string | null; + remark?: string | null; + status?: string | null; +} + +export type UpdateProfileEdit = { + detail?: string | null; + date?: Date | null; +}; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 73b4e4a6..c1d93e24 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -28,8 +28,9 @@ import { Profile, ProfileAddressHistory } from "./Profile"; import { Province } from "./Province"; import { District } from "./District"; import { SubDistrict } from "./SubDistrict"; -import { ProfileEmployeeInformationHistory } from "./ProfileEmployeeInformationHistory" -import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment" +import { ProfileEmployeeInformationHistory } from "./ProfileEmployeeInformationHistory"; +import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment"; +import { ProfileEdit } from "./ProfileEdit"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @@ -501,70 +502,70 @@ export class ProfileEmployee extends EntityBase { default: null, }) positionEmployeeGroupId: string; - + @Column({ nullable: true, comment: "สายงาน", default: null, }) positionEmployeeLineId: string; - + @Column({ nullable: true, comment: "ชื่อตำแหน่งทางสายงาน", default: null, }) positionEmployeePositionId: string; - + @Column({ nullable: true, comment: "สังกัด", default: null, }) employeeOc: string; - + @Column({ nullable: true, comment: "ประเภทบุคคล", default: null, }) employeeTypeIndividual: string; - + @Column({ nullable: true, comment: "ค่าจ้าง", default: null, }) employeeWage: string; - + @Column({ nullable: true, comment: "เงินเพิ่มการครองชีพชั่วคราว", default: null, }) employeeMoneyIncrease: string; - + @Column({ nullable: true, comment: "เงินช่วยเหลือการครองชีพชั่วคราว", default: null, }) employeeMoneyAllowance: string; - + @Column({ nullable: true, comment: "เงินสมทบประกันสังคม(ลูกจ้าง)", default: null, }) employeeMoneyEmployee: string; - + @Column({ nullable: true, comment: "เงินสมทบประกันสังคม(นายจ้าง)", default: null, }) employeeMoneyEmployer: string; - + @OneToMany(() => ProfileEmployeeInformationHistory, (v) => v.profileEmployeeInformation) information_histories: ProfileEmployeeInformationHistory[]; @@ -582,7 +583,7 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) profileCertificates: ProfileCertificate[]; - + @OneToMany(() => ProfileTraining, (v) => v.profileEmployee) profileTrainings: ProfileTraining[]; @@ -628,6 +629,9 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileAvatar, (v) => v.profileEmployee) profileAvatars: ProfileAvatar[]; + @OneToMany(() => ProfileEdit, (v) => v.profileEmployee) + profileEdits: ProfileEdit[]; + @ManyToOne(() => EmployeePosLevel, (v) => v.profiles) posLevel: EmployeePosLevel; diff --git a/src/migration/1721360319146-add_table_profileedit.ts b/src/migration/1721360319146-add_table_profileedit.ts new file mode 100644 index 00000000..6296b858 --- /dev/null +++ b/src/migration/1721360319146-add_table_profileedit.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableProfileedit1721360319146 implements MigrationInterface { + name = 'AddTableProfileedit1721360319146' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`profileEdit\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`status\` varchar(255) NULL COMMENT 'สถานะคำร้อง', \`topic\` varchar(255) NULL COMMENT 'ชื่อเรื่อง', \`detail\` text NULL COMMENT 'รายละเอียด', \`remark\` text NULL COMMENT 'หมายเหตุ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`profileEdit\` ADD CONSTRAINT \`FK_2b0d0e34814f699c610b4643612\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileEdit\` ADD CONSTRAINT \`FK_d0f0021e6c8ba05a7b0b3e552e6\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEdit\` DROP FOREIGN KEY \`FK_d0f0021e6c8ba05a7b0b3e552e6\``); + await queryRunner.query(`ALTER TABLE \`profileEdit\` DROP FOREIGN KEY \`FK_2b0d0e34814f699c610b4643612\``); + await queryRunner.query(`DROP TABLE \`profileEdit\``); + } + +}