diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 2634d406..b2714b4b 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -1056,7 +1056,7 @@ export class EmployeePositionController extends Controller { }); const authRoleName = await this.authRoleRepo.findOne({ - where: { id: String(posMaster.authRoleId) } + where: { id: String(posMaster.authRoleId) }, }); let profile: any; @@ -1149,7 +1149,8 @@ export class EmployeePositionController extends Controller { profilePoslevel: level == null || type == null ? null : `${type.posTypeShortName} ${level.posLevelName}`, authRoleId: posMaster.authRoleId, - authRoleName: authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, + authRoleName: + authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, positions: positions.map((position) => ({ id: position.id, positionName: position.positionName, @@ -2150,4 +2151,46 @@ export class EmployeePositionController extends Controller { return new HttpSuccess(); } + + /** + * API บันทึกตำแหน่งใหม่ + * + * @summary บันทึกตำแหน่งใหม่ + * + */ + @Post("report/current") + async reportApproveCurrent( + @Body() + body: { + posmasterId: string; + positionId: string; + profileId: string; + }, + ) { + const posMaster = await this.employeePosMasterRepository.findOne({ + where: { id: body.posmasterId }, + }); + if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); + + const posMasterOld = await this.employeePosMasterRepository.findOne({ + where: { + current_holderId: body.profileId, + orgRevisionId: posMaster.orgRevisionId, + }, + }); + if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) posMasterOld.next_holderId = null; + + const profile = await this.profileRepository.findOne({ + where: { id: body.profileId }, + }); + if (profile == null) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); + + posMaster.current_holderId = body.profileId; + posMaster.next_holderId = body.profileId; + if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); + await this.employeePosMasterRepository.save(posMaster); + return new HttpSuccess(); + } } diff --git a/src/controllers/InsigniaController.ts b/src/controllers/InsigniaController.ts index 25e428b2..44d20d7a 100644 --- a/src/controllers/InsigniaController.ts +++ b/src/controllers/InsigniaController.ts @@ -203,7 +203,7 @@ export class InsigniaController extends Controller { id: item.id, name: item.name, shortName: item.shortName, - insigniaTypeId: item.insigniaTypeId??null, + insigniaTypeId: item.insigniaTypeId ?? null, insigniaTypeName: item.insigniaType == null ? null : item.insigniaType.name, //ลำดับชั้นเครื่องราช createdAt: item.createdAt, lastUpdatedAt: item.lastUpdatedAt, diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index c05fcad0..85be57f5 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -30,6 +30,9 @@ import { OrgChild4 } from "../entities/OrgChild4"; import { PosMaster } from "../entities/PosMaster"; import { Position } from "../entities/Position"; import { log } from "console"; +import CallAPI from "../interfaces/call-api"; +import { ProfileSalary } from "../entities/ProfileSalary"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org") @Tags("Organization") @@ -48,6 +51,8 @@ export class OrganizationController extends Controller { private child4Repository = AppDataSource.getRepository(OrgChild4); private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); + private salaryRepository = AppDataSource.getRepository(ProfileSalary); + private profileRepo = AppDataSource.getRepository(Profile); /** * API รายการประวัติโครงสร้าง @@ -1601,7 +1606,7 @@ export class OrganizationController extends Controller { * @param {string} id Id revison */ @Get("get/publish") - async runPublish() { + async runPublish(@Request() request: { user: Record }) { const today = new Date(); today.setHours(0, 0, 0, 0); // Set time to the beginning of the day const orgRevisionPublish = await this.orgRevisionRepository @@ -1631,14 +1636,73 @@ export class OrganizationController extends Controller { const posMaster = await this.posMasterRepository.find({ where: { orgRevisionId: orgRevisionDraft.id }, + relations: [ + "orgRoot", + "orgChild4", + "orgChild3", + "orgChild2", + "orgChild1", + "positions", + "positions.posLevel", + "positions.posType", + "positions.posExecutive", + ], }); - posMaster.forEach(async (item) => { - // if(item.next_holderId != null){ - item.current_holderId = item.next_holderId; - item.next_holderId = null; - await this.posMasterRepository.save(item); - // } - }); + await Promise.all( + posMaster.map(async (item) => { + // if(item.next_holderId != null){ + if (item.next_holderId != null) { + const profile = await this.profileRepo.findOne({ + where: { id: item.next_holderId == null ? "" : item.next_holderId }, + }); + const position = await item.positions.find((x) => x.positionIsSelected == true); + const _null: any = null; + if (profile != null) { + profile.posLevelId = position?.posLevelId ?? _null; + profile.posTypeId = position?.posTypeId ?? _null; + profile.position = position?.positionName ?? _null; + await this.profileRepo.save(profile); + } + const profileSalary = await this.salaryRepository.findOne({ + where: { profileId: item.next_holderId }, + order: { createdAt: "DESC" }, + }); + + const shortName = + item != null && item.orgChild4 != null + ? `${item.orgChild4.orgChild4ShortName}${item.posMasterNo}` + : item != null && item?.orgChild3 != null + ? `${item.orgChild3.orgChild3ShortName}${item.posMasterNo}` + : item != null && item?.orgChild2 != null + ? `${item.orgChild2.orgChild2ShortName}${item.posMasterNo}` + : item != null && item?.orgChild1 != null + ? `${item.orgChild1.orgChild1ShortName}${item.posMasterNo}` + : item != null && item?.orgRoot != null + ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}` + : null; + // await new CallAPI().PostData(request, "org/profile/salary", { + // profileId: item.next_holderId, + // date: new Date(), + // amount: profileSalary?.amount ?? null, + // positionSalaryAmount: profileSalary?.positionSalaryAmount ?? null, + // mouthSalaryAmount: profileSalary?.mouthSalaryAmount ?? null, + // posNo: shortName, + // position: position?.positionName ?? _null, + // positionLine: position?.positionField ?? _null, + // positionPathSide: position?.positionArea ?? _null, + // positionExecutive: position?.posExecutive?.posExecutiveName ?? _null, + // positionType: position?.posType?.posTypeName ?? _null, + // positionLevel: position?.posLevel?.posLevelName ?? _null, + // refCommandNo: null, + // templateDoc: "ปรับโครงสร้าง", + // }); + } + item.current_holderId = item.next_holderId; + item.next_holderId = null; + await this.posMasterRepository.save(item); + // } + }), + ); return new HttpSuccess(); } @@ -3353,4 +3417,41 @@ export class OrganizationController extends Controller { return new HttpSuccess(formattedData); } + + /** + * API + * + * @summary (ADMIN) + * + * @param {string} id + */ + @Get("approver/{id}") + async getUserRootOrg(@Path() id: string, @Request() request: { user: Record }) { + if (id == "00000000-0000-0000-0000-000000000000") { + const maps = { + id: "00000000-0000-0000-0000-000000000000", + name: "", + positionName: "ปลัดกรุงเทพมหานคร", + }; + return new HttpSuccess(maps); + } + + const root = await this.orgRootRepository.findOne({ + where: { id: id }, + }); + if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); + const posMaster = await this.posMasterRepository.find({ + where: { orgRootId: root.id, orgChild1Id: IsNull() }, + relations: ["current_holder"], + }); + if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); + + const maps = posMaster.map((posMaster) => ({ + id: posMaster.current_holder.id, + name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`, + positionName: posMaster.current_holder.position, + })); + + return new HttpSuccess(maps); + } } diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index d921b77a..b745a769 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -26,6 +26,9 @@ import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Position } from "../entities/Position"; +import { CreateInsignias, Insignia } from "../entities/Insignia"; +import { InsigniaType } from "../entities/InsigniaType"; +import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia"; @Route("api/v1/org/dotnet") @Tags("Dotnet") @@ -39,7 +42,10 @@ export class OrganizationDotnetController extends Controller { private orgRootRepo = AppDataSource.getRepository(OrgRoot); private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); private profileRepo = AppDataSource.getRepository(Profile); + private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private positionRepository = AppDataSource.getRepository(Position); + private insigniaMetaRepo = AppDataSource.getRepository(Insignia); + private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); /** * 1. API Search Profile @@ -117,8 +123,8 @@ export class OrganizationDotnetController extends Controller { }), ); } - const profileEmp = await queryBuilder.getMany(); - return new HttpSuccess(profileEmp); + const profileEmp = await queryBuilder.getMany(); + return new HttpSuccess(profileEmp); } /** @@ -154,7 +160,7 @@ export class OrganizationDotnetController extends Controller { if (!orgRoot) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); return new HttpSuccess(orgRoot); } - + /** * 3. API Get Profile จาก keycloak id * @@ -168,14 +174,18 @@ export class OrganizationDotnetController extends Controller { relations: { posLevel: true, posType: true, - profileSalary: true + profileSalary: true, + profileInsignias: true, }, where: { keycloak: keycloakId }, - order:{ - profileSalary:{ - date: "DESC" - } - } + order: { + profileSalary: { + date: "DESC", + }, + profileInsignias: { + receiveDate: "DESC", + }, + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -184,26 +194,26 @@ export class OrganizationDotnetController extends Controller { avatar: profile.avatar, avatarName: profile.avatarName, rank: profile.rank, - prefix: profile.prefix, - firstName: profile.firstName, - lastName: profile.lastName, - citizenId: profile.citizenId, - position: profile.position, - posLevelId: profile.posLevelId, - email: profile.email, - phone: profile.phone, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, keycloak: profile.keycloak, isProbation: profile.isProbation, isLeave: profile.isLeave, - leaveReason: profile.leaveReason, - dateRetire: profile.dateRetire, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, dateAppoint: profile.dateAppoint, dateRetireLaw: profile.dateRetireLaw, - dateStart: profile.dateStart, - govAgeAbsent: profile.govAgeAbsent, - govAgePlus: profile.govAgePlus, - birthDate: profile.birthDate, - reasonSameDate: profile.reasonSameDate, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate, + reasonSameDate: profile.reasonSameDate, telephoneNumber: profile.telephoneNumber, nationality: profile.nationality, gender: profile.gender, @@ -215,18 +225,253 @@ export class OrganizationDotnetController extends Controller { registrationDistrictId: profile.registrationDistrictId, registrationSubDistrictId: profile.registrationSubDistrictId, registrationZipCode: profile.registrationZipCode, - currentAddress: profile.currentAddress, - currentProvinceId: profile.currentProvinceId, - currentSubDistrictId: profile.currentSubDistrictId, - currentZipCode: profile.currentZipCode, - dutyTimeId: profile.dutyTimeId, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, - posLevel: profile.posLevel? profile.posLevel : null, - posType: profile.posType? profile.posType : null, - profileSalary: profile.profileSalary.length > 0 - ? profile.profileSalary[0] - : null - } + posLevel: profile.posLevel ? profile.posLevel : null, + posType: profile.posType ? profile.posType : null, + profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null, + profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null, + }; + + return new HttpSuccess(mapProfile); + } + /** + * 3. API Get Profile จาก keycloak id + * + * @summary 3. API Get Profile จาก keycloak id + * + * @param {string} citizenId Id keycloak + */ + @Get("citizenId/{citizenId}") + async GetProfileByCitizenIdAsync(@Path() citizenId: string) { + const profile = await this.profileRepo.findOne({ + relations: { + posLevel: true, + posType: true, + profileSalary: true, + profileInsignias: true, + }, + where: { citizenId: citizenId }, + order: { + profileSalary: { + date: "DESC", + }, + profileInsignias: { + receiveDate: "DESC", + }, + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const mapProfile = { + id: profile.id, + avatar: profile.avatar, + avatarName: profile.avatarName, + rank: profile.rank, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, + keycloak: profile.keycloak, + isProbation: profile.isProbation, + isLeave: profile.isLeave, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, + dateAppoint: profile.dateAppoint, + dateRetireLaw: profile.dateRetireLaw, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate, + reasonSameDate: profile.reasonSameDate, + telephoneNumber: profile.telephoneNumber, + nationality: profile.nationality, + gender: profile.gender, + relationship: profile.relationship, + religion: profile.religion, + bloodGroup: profile.bloodGroup, + registrationAddress: profile.registrationAddress, + registrationProvinceId: profile.registrationProvinceId, + registrationDistrictId: profile.registrationDistrictId, + registrationSubDistrictId: profile.registrationSubDistrictId, + registrationZipCode: profile.registrationZipCode, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, + dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, + posLevel: profile.posLevel ? profile.posLevel : null, + posType: profile.posType ? profile.posType : null, + profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null, + profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null, + }; + + return new HttpSuccess(mapProfile); + } + + /** + * 3. API Get Profile จาก keycloak id + * + * @summary 3. API Get Profile จาก keycloak id + * + * @param {string} keycloakId Id keycloak + */ + @Get("root/officer/{rootId}") + async GetProfileByRootIdAsync(@Path() rootId: string) { + const profiles = await this.profileRepo.find({ + relations: { + posLevel: true, + posType: true, + profileSalary: true, + profileInsignias: true, + }, + where: { current_holders: { orgRootId: rootId } }, + order: { + profileSalary: { + date: "DESC", + }, + profileInsignias: { + receiveDate: "DESC", + }, + }, + }); + // if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const mapProfile = profiles.map((profile) => ({ + id: profile.id, + avatar: profile.avatar, + avatarName: profile.avatarName, + rank: profile.rank, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, + keycloak: profile.keycloak, + isProbation: profile.isProbation, + isLeave: profile.isLeave, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, + dateAppoint: profile.dateAppoint, + dateRetireLaw: profile.dateRetireLaw, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate, + reasonSameDate: profile.reasonSameDate, + telephoneNumber: profile.telephoneNumber, + nationality: profile.nationality, + gender: profile.gender, + relationship: profile.relationship, + religion: profile.religion, + bloodGroup: profile.bloodGroup, + registrationAddress: profile.registrationAddress, + registrationProvinceId: profile.registrationProvinceId, + registrationDistrictId: profile.registrationDistrictId, + registrationSubDistrictId: profile.registrationSubDistrictId, + registrationZipCode: profile.registrationZipCode, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, + dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, + posLevel: profile.posLevel ? profile.posLevel : null, + posType: profile.posType ? profile.posType : null, + profileSalary: profile.profileSalary, + profileInsignia: profile.profileInsignias, + })); + + return new HttpSuccess(mapProfile); + } + + /** + * 3. API Get Profile จาก keycloak id + * + * @summary 3. API Get Profile จาก keycloak id + * + * @param {string} keycloakId Id keycloak + */ + @Get("root/employee/{rootId}") + async GetProfileByRootIdEmpAsync(@Path() rootId: string) { + const profiles = await this.profileEmpRepo.find({ + relations: { + posLevel: true, + posType: true, + profileSalarys: true, + profileInsignias: true, + }, + where: { current_holders: { orgRootId: rootId } }, + order: { + profileSalarys: { + date: "DESC", + }, + profileInsignias: { + receiveDate: "DESC", + }, + }, + }); + // if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const mapProfile = profiles.map((profile) => ({ + id: profile.id, + avatar: profile.avatar, + avatarName: profile.avatarName, + rank: profile.rank, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, + keycloak: profile.keycloak, + isProbation: profile.isProbation, + isLeave: profile.isLeave, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, + dateAppoint: profile.dateAppoint, + dateRetireLaw: profile.dateRetireLaw, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate, + reasonSameDate: profile.reasonSameDate, + telephoneNumber: profile.telephoneNumber, + nationality: profile.nationality, + gender: profile.gender, + relationship: profile.relationship, + religion: profile.religion, + bloodGroup: profile.bloodGroup, + registrationAddress: profile.registrationAddress, + registrationProvinceId: profile.registrationProvinceId, + registrationDistrictId: profile.registrationDistrictId, + registrationSubDistrictId: profile.registrationSubDistrictId, + registrationZipCode: profile.registrationZipCode, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + // dutyTimeId: profile.dutyTimeId, + // dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, + posLevel: profile.posLevel ? profile.posLevel : null, + posType: profile.posType ? profile.posType : null, + profileSalary: profile.profileSalarys, + profileInsignia: profile.profileInsignias, + })); return new HttpSuccess(mapProfile); } @@ -242,10 +487,10 @@ export class OrganizationDotnetController extends Controller { async GetUserFullName(@Path() keycloakId: string) { const profile = await this.profileRepo.findOne({ where: { keycloak: keycloakId }, - select: ["prefix", "firstName", "lastName"] + select: ["prefix", "firstName", "lastName"], }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const fullName = profile? `${profile.prefix}${profile.firstName} ${profile.lastName}` : "-"; + const fullName = profile ? `${profile.prefix}${profile.firstName} ${profile.lastName}` : "-"; return new HttpSuccess(fullName); } @@ -296,7 +541,7 @@ export class OrganizationDotnetController extends Controller { root: root == null ? null : root.orgRootName, rootShortName: root == null ? null : root.orgRootShortName, }; - return new HttpSuccess(profile); + return new HttpSuccess(_profile); } /** @@ -380,7 +625,7 @@ export class OrganizationDotnetController extends Controller { where: { posMasterId: posMaster?.id, }, - }); + }); const _profile: any = { profileId: profile.id, @@ -462,7 +707,7 @@ export class OrganizationDotnetController extends Controller { where: { id: ocId }, }); if (!orgRoot) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const root = orgRoot? orgRoot.id : ""; + const root = orgRoot ? orgRoot.id : ""; return new HttpSuccess(root); } @@ -475,25 +720,26 @@ export class OrganizationDotnetController extends Controller { @Get("keycloak") async GetProfileWithKeycloak() { const profile = await this.profileRepo.find({ - where: { keycloak: Not(IsNull()) || Not(""), }, + where: { keycloak: Not(IsNull()) || Not("") }, }); return new HttpSuccess(profile); } /** - * 4. API Update รอบการลงเวลา ในตาราง profile + * 4. API Update รอบการลงเวลา ในตาราง profile * - * @summary 4. API Update รอบการลงเวลา ในตาราง profile + * @summary 4. API Update รอบการลงเวลา ในตาราง profile * */ @Put("update-dutytime") async UpdateDutyTimeAsync( @Request() req: RequestWithUser, - @Body() body: { + @Body() + body: { profileId: string; roundId: string; effectiveDate: Date; - } + }, ) { const profile = await this.profileRepo.findOne({ where: { id: body.profileId }, @@ -507,5 +753,55 @@ export class OrganizationDotnetController extends Controller { await this.profileRepo.save(profile); return new HttpSuccess(); } + /** + * API เพิ่มข้อมูลเครื่องราชอิสริยาภรณ์ + * + * @summary ORG_ - เพิ่มข้อมูลเครื่องราชอิสริยาภรณ์ (ADMIN) # + * + */ + @Post("insignia/Dumb") + public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) { + if (!body.profileId) { + throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); + } + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + // const insignia = await this.insigniaMetaRepo.findOne({ + // where: { name: body.insigniaId }, + // }); + // const _null: any = null; + // if (body && body.insigniaId) { + // const findPosLevel = await this.insigniaMetaRepo.findOne({ + // where: { name: body.insigniaId }, + // select: ["id", "name"], + // }); + // if (findPosLevel) { + // body.insigniaId = findPosLevel.id; + // } else { + // body.insigniaId = _null; + // } + // } else { + // body.insigniaId = _null; + // } + + const data = new ProfileInsignia(); + + 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.insigniaRepo.save(data); + + return new HttpSuccess(); + } } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 18960fbc..6bb59831 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3267,4 +3267,44 @@ export class PositionController extends Controller { ); return new HttpSuccess(data); } + + /** + * API บันทึกตำแหน่งใหม่ + * + * @summary บันทึกตำแหน่งใหม่ + * + */ + @Post("report/current") + async reportApproveCurrent( + @Body() + body: { + posmasterId: string; + positionId: string; + profileId: string; + }, + ) { + const posMaster = await this.posMasterRepository.findOne({ + where: { id: body.posmasterId }, + }); + if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); + + const posMasterOld = await this.posMasterRepository.findOne({ + where: { + current_holderId: body.profileId, + orgRevisionId: posMaster.orgRevisionId, + }, + }); + if (posMasterOld != null) posMasterOld.current_holderId = null; + + const profile = await this.profileRepository.findOne({ + where: { id: body.profileId }, + }); + if (profile == null) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); + + posMaster.current_holderId = body.profileId; + if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); + await this.posMasterRepository.save(posMaster); + return new HttpSuccess(); + } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index ad746e38..3dee70b9 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -901,6 +901,9 @@ export class ProfileController extends Controller { } const profile: Profile = Object.assign(new Profile(), body); + const _null: any = null; + profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate); + profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate); profile.createdUserId = request.user.sub; profile.createdFullName = request.user.name; profile.lastUpdateUserId = request.user.sub; @@ -2516,7 +2519,7 @@ export class ProfileController extends Controller { root: root == null ? null : root.orgRootName, orgRootShortName: root == null ? null : root.orgRootShortName, orgRevisionId: root == null ? null : root.orgRevisionId, - org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName}`, + org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, }; }), ); @@ -2968,18 +2971,23 @@ export class ProfileController extends Controller { if (_profile.child4Id != null) { _profile.node = 4; _profile.nodeId = _profile.child4Id; + _profile.nodeShortName = _profile.child4ShortName; } else if (_profile.child3Id != null) { _profile.node = 3; _profile.nodeId = _profile.child3Id; + _profile.nodeShortName = _profile.child3ShortName; } else if (_profile.child2Id != null) { _profile.node = 2; _profile.nodeId = _profile.child2Id; + _profile.nodeShortName = _profile.child2ShortName; } else if (_profile.child1Id != null) { _profile.node = 1; _profile.nodeId = _profile.child1Id; + _profile.nodeShortName = _profile.child1ShortName; } else if (_profile.rootId != null) { _profile.node = 0; _profile.nodeId = _profile.rootId; + _profile.nodeShortName = _profile.rootShortName; } return new HttpSuccess(_profile); } @@ -3695,6 +3703,7 @@ export class ProfileController extends Controller { keyword?: string; }, ) { + const isProbation: boolean = true; const [findProfile, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -3708,12 +3717,24 @@ export class ProfileController extends Controller { .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") - .where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` }) + .where(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`posLevel.posLevelName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) + .orWhere(`posType.posTypeName LIKE :keyword and profile.isProbation = ${isProbation}`, { + keyword: `%${body.keyword}%`, + }) .orderBy("profile.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) @@ -4423,17 +4444,25 @@ export class ProfileController extends Controller { async updateLeaveUser( @Path() id: string, @Body() - requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date }, + requestBody: { isLeave: boolean; leaveReason?: any; dateLeave?: any }, @Request() request: { user: Record }, ) { const profile = await this.profileRepo.findOne({ where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + const _null: any = null; profile.isLeave = requestBody.isLeave; - profile.leaveReason = requestBody.leaveReason; - profile.dateLeave = requestBody.dateLeave; + if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) { + profile.leaveReason = requestBody.leaveReason; + } else { + profile.leaveReason = _null; + } + if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) { + profile.dateLeave = requestBody.dateLeave; + } else { + profile.dateLeave = _null; + } await this.profileRepo.save(profile); const profileSalary = await this.salaryRepository.findOne({ @@ -4645,7 +4674,7 @@ export class ProfileController extends Controller { return new HttpSuccess(profile); } - /** + /** * API สร้างทะเบียนประวัติใหม่ * * @summary ORG_065 - สร้างทะเบียนประวัติใหม่ (ADMIN) #XXX @@ -4656,96 +4685,194 @@ export class ProfileController extends Controller { @Request() request: RequestWithUser, @Body() body: CreateProfileAllFields, ) { + const citizen = await this.profileRepo.findOne({ + where: { citizenId: body.citizenId }, + select: ["id"], + }); + if (citizen) return new HttpSuccess(citizen.id); + const _null: any = null; const profile: Profile = Object.assign(new Profile(), body); if (body && body.posLevelId) { const findPosLevel = await this.posLevelRepo.findOne({ where: { posLevelName: body.posLevelId }, - select:['id','posLevelName'] + select: ["id", "posLevelName"], }); if (findPosLevel) { profile.posLevelId = findPosLevel.id; + } else { + profile.posLevelId = _null; } + } else { + profile.posLevelId = _null; } if (body && body.posTypeId) { const findPosType = await this.posTypeRepo.findOne({ where: { posTypeName: body.posTypeId }, - select:['id','posTypeName'] + select: ["id", "posTypeName"], }); if (findPosType) { profile.posTypeId = findPosType.id; + } else { + profile.posTypeId = _null; } + } else { + profile.posTypeId = _null; } - if (body && body.prefix) { - const findPrefix = await this.prefixRepo.findOne({ - where: { name: body.prefix }, - select:['id','name'] - }); - if (findPrefix) { - profile.prefix = findPrefix.id; - } - } + // if (body && body.prefix) { + // const findPrefix = await this.prefixRepo.findOne({ + // where: { name: body.prefix }, + // select: ["id", "name"], + // }); + // if (findPrefix) { + // profile.prefix = findPrefix.id; + // } else { + // profile.prefix = _null; + // } + // } else { + // profile.prefix = _null; + // } //current if (body && body.currentProvinceId) { const findProvince = await this.provinceRepo.findOne({ where: { name: body.currentProvinceId }, - select:['id','name'] + select: ["id", "name"], }); - if (findProvince) { - profile.currentProvinceId = findProvince.id; - } + if (findProvince) { + profile.currentProvinceId = findProvince.id; + } else { + profile.currentProvinceId = _null; + } + } else { + profile.currentProvinceId = _null; } if (body && body.currentDistrictId) { const findDistrict = await this.districtRepo.findOne({ where: { name: body.currentDistrictId }, - select:['id','name'] + select: ["id", "name"], }); - if (findDistrict) { - profile.currentDistrictId = findDistrict.id; - } + if (findDistrict) { + profile.currentDistrictId = findDistrict.id; + } else { + profile.currentDistrictId = _null; + } + } else { + profile.currentDistrictId = _null; } if (body && body.currentSubDistrictId) { const findSubDistrict = await this.subDistrictRepo.findOne({ where: { name: body.currentSubDistrictId }, - select:['id','name'] + select: ["id", "name"], }); if (findSubDistrict) { profile.currentSubDistrictId = findSubDistrict.id; + } else { + profile.currentSubDistrictId = _null; } + } else { + profile.currentSubDistrictId = _null; } //register if (body && body.registrationProvinceId) { const findProvince_regis = await this.provinceRepo.findOne({ where: { name: body.registrationProvinceId }, - select:['id','name'] + select: ["id", "name"], }); if (findProvince_regis) { profile.registrationProvinceId = findProvince_regis.id; + } else { + profile.registrationProvinceId = _null; } + } else { + profile.registrationProvinceId = _null; } if (body && body.registrationDistrictId) { const findDistrict_regis = await this.districtRepo.findOne({ where: { name: body.registrationDistrictId }, - select:['id','name'] + select: ["id", "name"], }); if (findDistrict_regis) { profile.registrationDistrictId = findDistrict_regis.id; + } else { + profile.registrationDistrictId = _null; } + } else { + profile.registrationDistrictId = _null; } if (body && body.registrationSubDistrictId) { const findSubDistrict_regis = await this.subDistrictRepo.findOne({ where: { name: body.registrationSubDistrictId }, - select:['id','name'] + select: ["id", "name"], }); - if (findSubDistrict_regis) { - profile.registrationSubDistrictId = findSubDistrict_regis.id; - } + if (findSubDistrict_regis) { + profile.registrationSubDistrictId = findSubDistrict_regis.id; + } else { + profile.registrationSubDistrictId = _null; + } + } else { + profile.registrationSubDistrictId = _null; } - + profile.createdUserId = request.user.sub; profile.createdFullName = request.user.name; profile.lastUpdateUserId = request.user.sub; profile.lastUpdateFullName = request.user.name; + // return new HttpSuccess(profile); await this.profileRepo.save(profile); return new HttpSuccess(profile.id); } + /** + * + * @summary (ADMIN) + * + */ + @Get("retireDate/mock") + async calRetireDate() { + const profile = await this.profileRepo.find({ relations: ["profileSalary"] }); + const _null: any = null; + const profiles = profile.map((_data) => ({ + ..._data, + dateRetire: _data.birthDate == null ? _null : calculateRetireDate(_data.birthDate), + dateRetireLaw: _data.birthDate == null ? _null : calculateRetireLaw(_data.birthDate), + })); + await this.profileRepo.save(profiles); + return new HttpSuccess(); + } + /** + * + * @summary (ADMIN) + * + */ + @Get("salarym/ock") + async calSalaryDate() { + const profile = await this.profileRepo.find(); + const _null: any = null; + const profiles = await Promise.all( + profile.map(async (_data) => { + const salary = await this.salaryRepository.findOne({ + where: { + profileId: _data.id, + }, + order: { order: "DESC" }, + }); + const type = await this.posTypeRepo.findOne({ + where: { + posTypeName: salary?.positionType ?? "", + }, + }); + const level = await this.posLevelRepo.findOne({ + where: { + posLevelName: salary?.positionLevel ?? "", + }, + }); + return { + ..._data, + position: salary?.position ?? _null, + posLevelId: level?.id ?? _null, + posTypeId: type?.id ?? _null, + }; + }), + ); + await this.profileRepo.save(profiles); + return new HttpSuccess("zxczx"); + } } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 71f6d4db..375d92d0 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -60,6 +60,7 @@ import { import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; import CallAPI from "../interfaces/call-api"; import e from "cors"; +import { EmployeePosition } from "../entities/EmployeePosition"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @@ -76,6 +77,7 @@ export class ProfileEmployeeController extends Controller { private profileHistoryRepo = AppDataSource.getRepository(ProfileEmployeeHistory); private posLevelRepo = AppDataSource.getRepository(EmployeePosLevel); private posTypeRepo = AppDataSource.getRepository(EmployeePosType); + private positionRepository = AppDataSource.getRepository(EmployeePosition); private provinceRepository = AppDataSource.getRepository(Province); private districtRepository = AppDataSource.getRepository(District); private subDistrict = AppDataSource.getRepository(SubDistrict); @@ -2705,7 +2707,6 @@ export class ProfileEmployeeController extends Controller { refCommandNo: null, templateDoc: requestBody.leaveReason, }); - return new HttpSuccess(); } @@ -3032,6 +3033,13 @@ export class ProfileEmployeeController extends Controller { profile.employeeClass = "PERM"; await this.profileRepo.save(profile); }); + await new CallAPI() + .PostData(request, "org/employee/pos/report/current", { + posmasterId: profile.posmasterIdTemp, + positionId: profile.positionIdTemp, + profileId: profile.id, + }) + .then(async (x) => {}); } }), ); @@ -3204,4 +3212,129 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess({ data: mapDataProfile, total }); } + /** + * API ข้อมูลทะเบียนประวัติตาม profileid + * + * @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม profileid (ADMIN) #70 + * + */ + @Get("profileid/position/{id}") + async getProfileByProfileid( + @Request() request: { user: Record }, + @Path() id: string, + ) { + const profile = await this.profileRepo.findOne({ + where: { id: id }, + relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const orgRevisionPublish = await this.orgRevisionRepo + .createQueryBuilder("orgRevision") + .where("orgRevision.orgRevisionIsDraft = false") + .andWhere("orgRevision.orgRevisionIsCurrent = true") + .getOne(); + if (!orgRevisionPublish) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); + } + + const posMaster = + profile.current_holders == null || + profile.current_holders.length == 0 || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id); + const root = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot; + const child1 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1; + const child2 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2; + const child3 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3; + const child4 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4; + const position = await this.positionRepository.findOne({ + relations: ["posExecutive"], + where: { + posMasterId: posMaster?.id, + }, + }); + const _profile: any = { + profileId: profile.id, + prefix: profile.prefix, + rank: profile.rank, + isProbation: profile.isProbation, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + birthDate: profile.birthDate, + position: profile.position, + leaveDate: profile.dateLeave, + posMasterNo: posMaster == null ? null : posMaster.posMasterNo, + posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, + posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, + posLevelId: profile.posLevel == null ? null : profile.posLevel.id, + 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: "", + rootId: root == null ? null : root.id, + root: root == null ? null : root.orgRootName, + rootShortName: root == null ? null : root.orgRootShortName, + child1Id: child1 == null ? null : child1.id, + child1: child1 == null ? null : child1.orgChild1Name, + child1ShortName: child1 == null ? null : child1.orgChild1ShortName, + child2Id: child2 == null ? null : child2.id, + child2: child2 == null ? null : child2.orgChild2Name, + child2ShortName: child2 == null ? null : child2.orgChild2ShortName, + child3Id: child3 == null ? null : child3.id, + child3: child3 == null ? null : child3.orgChild3Name, + child3ShortName: child3 == null ? null : child3.orgChild3ShortName, + child4Id: child4 == null ? null : child4.id, + child4: child4 == null ? null : child4.orgChild4Name, + child4ShortName: child4 == null ? null : child4.orgChild4ShortName, + node: null, + nodeId: null, + }; + + if (_profile.child4Id != null) { + _profile.node = 4; + _profile.nodeId = _profile.child4Id; + } else if (_profile.child3Id != null) { + _profile.node = 3; + _profile.nodeId = _profile.child3Id; + } else if (_profile.child2Id != null) { + _profile.node = 2; + _profile.nodeId = _profile.child2Id; + } else if (_profile.child1Id != null) { + _profile.node = 1; + _profile.nodeId = _profile.child1Id; + } else if (_profile.rootId != null) { + _profile.node = 0; + _profile.nodeId = _profile.rootId; + } + return new HttpSuccess(_profile); + } } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 40c1dcee..ef54edfe 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1181,7 +1181,7 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(node.profilePosLevel.toString()), education: node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(_head); } else { @@ -1255,7 +1255,7 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(node.profilePosLevel.toString()), education: node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(head); } @@ -1552,7 +1552,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(_head); } else { @@ -1630,7 +1630,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(head); } @@ -1933,7 +1933,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(_head); } else { @@ -2015,7 +2015,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(head); } @@ -2322,7 +2322,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(_head); } else { @@ -2407,7 +2407,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(head); } @@ -2713,7 +2713,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(_head); } else { @@ -2798,7 +2798,7 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", }; data.push(head); } @@ -3139,13 +3139,13 @@ export class ReportController extends Controller { node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), education: node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; data.push(_head); @@ -3192,13 +3192,13 @@ export class ReportController extends Controller { node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), education: node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; data.push(head); @@ -3333,13 +3333,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3391,13 +3391,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3534,13 +3534,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3595,13 +3595,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3740,13 +3740,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3804,13 +3804,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), }; @@ -3951,13 +3951,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" @@ -4017,13 +4017,13 @@ export class ReportController extends Controller { node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: Extension.ToThaiNumber(node.salary.toLocaleString()), - positionSalaryAmount: Extension.ToThaiNumber( + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + positionSalaryAmount: node.positionSalaryAmount ? Extension.ToThaiNumber( node.positionSalaryAmount.toLocaleString(), - ), - mouthSalaryAmount: Extension.ToThaiNumber( + ) : "", + mouthSalaryAmount: node.mouthSalaryAmount ? Extension.ToThaiNumber( node.mouthSalaryAmount.toLocaleString(), - ), + ) : "", reason: node.reason == null ? "" diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 5148f88c..72e57e2b 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -649,6 +649,7 @@ export class CreateProfile { } export class CreateProfileAllFields { + id?: string | null; rank: string | null; prefix: string; firstName: string; @@ -688,7 +689,6 @@ export class CreateProfileAllFields { currentZipCode: string | null; } - export type UpdateProfile = { rank?: string | null; prefix?: string | null; diff --git a/src/migration/1718866177977-update_table_org2006.ts b/src/migration/1718866177977-update_table_org2006.ts deleted file mode 100644 index a8471cfc..00000000 --- a/src/migration/1718866177977-update_table_org2006.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableOrg20061718866177977 implements MigrationInterface { - name = 'UpdateTableOrg20061718866177977' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`authRoleAttr\` (\`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', \`attrOwnership\` varchar(255) NULL, \`attrIsCreate\` tinyint NOT NULL DEFAULT 0, \`attrIsList\` tinyint NOT NULL DEFAULT 0, \`attrIsGet\` tinyint NOT NULL DEFAULT 0, \`attrIsUpdate\` tinyint NOT NULL DEFAULT 0, \`attrIsDelete\` tinyint NOT NULL DEFAULT 0, \`attrPrivilege\` varchar(255) NULL, \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง AuthRole', \`authSysId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง AuthSys', \`parentNode\` varchar(255) NULL COMMENT 'Root', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`authRole\` (\`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', \`roleName\` varchar(255) NULL COMMENT 'ชื่อบทบาท', \`roleDescription\` varchar(255) NULL COMMENT 'รายละเอียด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`posMasterAct\` (\`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', \`posMasterOrder\` int NULL COMMENT 'ลำดับที่แสดงผล', \`posMasterId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posMaster', \`posMasterChildId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posMasterChild', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`changePosition\` (\`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', \`name\` text NULL COMMENT 'ชื่อรอบการย้ายสับเปลี่ยนตำแหน่ง', \`date\` datetime NULL COMMENT 'วันที่ดำเนินการ', \`status\` text NULL COMMENT 'สถานะ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`profileChangePosition\` (\`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', \`reason\` text NULL COMMENT 'เหตุผลที่รับโอนราชการ', \`educationOld\` varchar(255) NULL COMMENT 'วุฒิ/สาขาเดิม', \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม ตำแหน่ง', \`organizationOld\` varchar(255) NULL COMMENT 'สังกัดเดิม', \`positionOld\` varchar(255) NULL COMMENT 'ตำแหน่งเดิม', \`positionTypeOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท', \`positionLevelOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม ระดับ', \`positionNumberOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม เลขที่', \`amountOld\` double NULL COMMENT 'ข้อมูลหน่วยงานเดิม เงินเดือน', \`dateCurrent\` datetime NULL COMMENT 'ดำรงตำแหน่งในระดับปัจจุบันเมื่อ', \`profileId\` varchar(255) NULL COMMENT 'profile Id', \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'นามสกุล', \`citizenId\` varchar(255) NULL COMMENT 'เลขบัตรประชาชน', \`birthDate\` datetime NULL COMMENT 'วันเกิด', \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน root', \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน root', \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน root', \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1', \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1', \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1', \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2', \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2', \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2', \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3', \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3', \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3', \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4', \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4', \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4', \`node\` int NULL COMMENT 'ระดับโครงสร้าง', \`nodeId\` varchar(255) NULL COMMENT 'id โครงสร้าง', \`posmasterId\` varchar(255) NULL COMMENT 'id อัตรากำลัง', \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision', \`positionId\` varchar(255) NULL COMMENT 'id ตำแหน่ง', \`positionField\` varchar(255) NULL COMMENT 'สายงาน', \`posMasterNo\` int NULL COMMENT 'เลขที่ตำแหน่ง', \`position\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งในสายงาน', \`posTypeId\` varchar(255) NULL COMMENT 'id ประเภทตำแหน่ง', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`posLevelId\` varchar(255) NULL COMMENT 'id ระดับตำแหน่ง', \`posLevelName\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', \`rootOld\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน root old', \`rootOldId\` varchar(255) NULL COMMENT 'id หน่วยงาน root old', \`rootShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน root old', \`child1Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1 old', \`child1OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child1 old', \`child1ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1 old', \`child2Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2 old', \`child2OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child2 old', \`child2ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2 old', \`child3Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3 old', \`child3OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child3 old', \`child3ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3 old', \`child4Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4 old', \`child4OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child4 old', \`child4ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4 old', \`posMasterNoOld\` int NULL COMMENT 'เลขที่ตำแหน่ง old', \`posTypeOldId\` varchar(255) NULL COMMENT 'id ประเภทตำแหน่ง old', \`posTypeNameOld\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง old', \`posLevelOldId\` varchar(255) NULL COMMENT 'id ระดับตำแหน่ง old', \`posLevelNameOld\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง old', \`status\` text NULL COMMENT 'สถานะ', \`changePositionId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ChangePosition', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`authSys\` (\`id\` varchar(255) NOT NULL COMMENT 'ไอดีหลักของตาราง', \`parentId\` varchar(255) NULL COMMENT 'Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null', \`icon\` varchar(100) NULL COMMENT 'ชื่อ icon', \`path\` varchar(255) NULL COMMENT 'path url ของระบบ', \`order\` int NOT NULL COMMENT 'ลำดับการแสดงผล' DEFAULT '0', \`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', \`sysName\` varchar(255) NULL COMMENT 'ชื่อระบบ', \`sysDescription\` varchar(255) NULL COMMENT 'รายละเอียด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`isDirector\` tinyint NOT NULL COMMENT 'เป็นผู้อำนวยการ' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นเจ้าหน้าที่' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`isDirector\` tinyint NOT NULL COMMENT 'เป็นผู้อำนวยการ' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นเจ้าหน้าที่' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` ADD CONSTRAINT \`FK_229d969d15790aae298399f9303\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`authRoleAttr\` ADD CONSTRAINT \`FK_c50907c64fce7ed8f2fb68a3d50\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD CONSTRAINT \`FK_388ecc9f2a9f5b5ff1e08fd6d0e\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` ADD CONSTRAINT \`FK_ef186d66137edc512471eaef51b\` FOREIGN KEY (\`posMasterId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` ADD CONSTRAINT \`FK_0f07f317c0771dadcdac1f71a6d\` FOREIGN KEY (\`posMasterChildId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_a059796d095e79ba5b20407859f\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`profileChangePosition\` ADD CONSTRAINT \`FK_91b13ee34e6af4bee74771d17e8\` FOREIGN KEY (\`changePositionId\`) REFERENCES \`changePosition\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`profileChangePosition\` DROP FOREIGN KEY \`FK_91b13ee34e6af4bee74771d17e8\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_a059796d095e79ba5b20407859f\``); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` DROP FOREIGN KEY \`FK_0f07f317c0771dadcdac1f71a6d\``); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` DROP FOREIGN KEY \`FK_ef186d66137edc512471eaef51b\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP FOREIGN KEY \`FK_388ecc9f2a9f5b5ff1e08fd6d0e\``); - await queryRunner.query(`ALTER TABLE \`authRoleAttr\` DROP FOREIGN KEY \`FK_c50907c64fce7ed8f2fb68a3d50\``); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` DROP FOREIGN KEY \`FK_229d969d15790aae298399f9303\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`authRoleId\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`isOfficer\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`isDirector\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`authRoleId\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`isOfficer\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`isDirector\``); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` DROP COLUMN \`profileEmployeeId\``); - await queryRunner.query(`DROP TABLE \`authSys\``); - await queryRunner.query(`DROP TABLE \`profileChangePosition\``); - await queryRunner.query(`DROP TABLE \`changePosition\``); - await queryRunner.query(`DROP TABLE \`posMasterAct\``); - await queryRunner.query(`DROP TABLE \`authRole\``); - await queryRunner.query(`DROP TABLE \`authRoleAttr\``); - } - -}