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 af7831fa..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(); } @@ -3363,6 +3427,15 @@ export class OrganizationController extends Controller { */ @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 }, }); @@ -3374,9 +3447,9 @@ export class OrganizationController extends Controller { 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, + 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 0d823a0a..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 @@ -169,12 +175,16 @@ export class OrganizationDotnetController extends Controller { posLevel: true, posType: true, profileSalary: true, + profileInsignias: true, }, where: { keycloak: keycloakId }, order: { profileSalary: { date: "DESC", }, + profileInsignias: { + receiveDate: "DESC", + }, }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -224,10 +234,247 @@ export class OrganizationDotnetController extends Controller { 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); + } /** * 7.1 Get ข้อมูล GetUserFullName @@ -506,4 +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/ProfileController.ts b/src/controllers/ProfileController.ts index acfed8de..2dceef4b 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -744,6 +744,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; @@ -2359,7 +2362,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 ?? ""}`, }; }), ); @@ -2811,18 +2814,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); } @@ -3538,6 +3546,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") @@ -3551,12 +3560,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) @@ -4275,12 +4296,12 @@ export class ProfileController extends Controller { if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const _null: any = null; profile.isLeave = requestBody.isLeave; - if (profile.leaveReason != undefined && profile.leaveReason != null) { + if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) { profile.leaveReason = requestBody.leaveReason; } else { profile.leaveReason = _null; } - if (profile.dateLeave != undefined && profile.dateLeave != null) { + if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) { profile.dateLeave = requestBody.dateLeave; } else { profile.dateLeave = _null; @@ -4512,6 +4533,7 @@ export class ProfileController extends Controller { 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({ @@ -4520,7 +4542,11 @@ export class ProfileController extends Controller { }); if (findPosLevel) { profile.posLevelId = findPosLevel.id; + } else { + profile.posLevelId = _null; } + } else { + profile.posLevelId = _null; } if (body && body.posTypeId) { const findPosType = await this.posTypeRepo.findOne({ @@ -4529,17 +4555,25 @@ export class ProfileController extends Controller { }); 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({ @@ -4548,7 +4582,11 @@ export class ProfileController extends Controller { }); if (findProvince) { profile.currentProvinceId = findProvince.id; + } else { + profile.currentProvinceId = _null; } + } else { + profile.currentProvinceId = _null; } if (body && body.currentDistrictId) { const findDistrict = await this.districtRepo.findOne({ @@ -4557,7 +4595,11 @@ export class ProfileController extends Controller { }); if (findDistrict) { profile.currentDistrictId = findDistrict.id; + } else { + profile.currentDistrictId = _null; } + } else { + profile.currentDistrictId = _null; } if (body && body.currentSubDistrictId) { const findSubDistrict = await this.subDistrictRepo.findOne({ @@ -4566,7 +4608,11 @@ export class ProfileController extends Controller { }); if (findSubDistrict) { profile.currentSubDistrictId = findSubDistrict.id; + } else { + profile.currentSubDistrictId = _null; } + } else { + profile.currentSubDistrictId = _null; } //register if (body && body.registrationProvinceId) { @@ -4576,7 +4622,11 @@ export class ProfileController extends Controller { }); 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({ @@ -4585,7 +4635,11 @@ export class ProfileController extends Controller { }); 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({ @@ -4594,14 +4648,74 @@ export class ProfileController extends Controller { }); 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 c2741e34..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); @@ -3210,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/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;