hrms-api-org/src/controllers/ProfileController.ts

5238 lines
209 KiB
TypeScript
Raw Normal View History

2024-02-08 10:56:03 +07:00
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
2024-03-24 19:43:37 +07:00
Example,
2024-02-08 10:56:03 +07:00
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
2024-02-08 10:56:03 +07:00
import HttpError from "../interfaces/http-error";
2024-05-03 17:38:00 +07:00
import {
Profile,
CreateProfile,
UpdateProfile,
ProfileHistory,
CreateProfileAllFields,
} from "../entities/Profile";
import { Brackets, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
2024-02-08 15:40:47 +07:00
import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType";
2024-05-17 09:32:07 +07:00
import {
calculateAge,
calculateRetireDate,
calculateRetireLaw,
calculateRetireYear,
} from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
import { Position } from "../entities/Position";
2024-05-17 09:32:07 +07:00
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
2024-05-24 13:42:59 +07:00
import { ProfileCertificate } from "../entities/ProfileCertificate";
import { ProfileTraining } from "../entities/ProfileTraining";
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
import { ProfileEducation } from "../entities/ProfileEducation";
import { CreateProfileSalary, ProfileSalary } from "../entities/ProfileSalary";
2024-05-24 13:42:59 +07:00
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import CallAPI from "../interfaces/call-api";
2024-05-23 15:28:49 +07:00
import Extension from "../interfaces/extension";
2024-06-21 18:06:23 +07:00
import { Prefixe } from "../entities/Prefixe";
2024-06-27 14:28:23 +07:00
import { ProfileInsignia } from "../entities/ProfileInsignia";
2024-02-08 10:56:03 +07:00
@Route("api/v1/org/profile")
@Tags("Profile")
@Security("bearerAuth")
@Response(
HttpStatus.INTERNAL_SERVER_ERROR,
2024-02-08 10:56:03 +07:00
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
2024-02-08 10:56:03 +07:00
export class ProfileController extends Controller {
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private posMasterRepo = AppDataSource.getRepository(PosMaster);
private profileRepo = AppDataSource.getRepository(Profile);
2024-05-17 09:32:07 +07:00
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
private profileHistoryRepo = AppDataSource.getRepository(ProfileHistory);
private posLevelRepo = AppDataSource.getRepository(PosLevel);
private posTypeRepo = AppDataSource.getRepository(PosType);
private positionRepository = AppDataSource.getRepository(Position);
private provinceRepository = AppDataSource.getRepository(Province);
private districtRepository = AppDataSource.getRepository(District);
private subDistrict = AppDataSource.getRepository(SubDistrict);
2024-05-24 13:42:59 +07:00
private certificateRepository = AppDataSource.getRepository(ProfileCertificate);
private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple);
private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother);
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
2024-06-12 17:50:48 +07:00
private profileEducationRepository = AppDataSource.getRepository(ProfileEducation);
2024-06-21 18:06:23 +07:00
private prefixRepo = AppDataSource.getRepository(Prefixe);
private provinceRepo = AppDataSource.getRepository(Province);
private districtRepo = AppDataSource.getRepository(District);
private subDistrictRepo = AppDataSource.getRepository(SubDistrict);
2024-06-27 14:28:23 +07:00
private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private profileDisciplineRepo = AppDataSource.getRepository(ProfileDiscipline);
/**
* report
*
* @summary report
*
* @param {string} id Id
*/
@Get("kp7-short/{id}")
async kp7ShortById(@Path() id: string) {
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profile = await this.profileRepo.findOne({
relations: [
"profileSalary",
"profileEducations",
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const province = await this.provinceRepository.findOneBy({
id: profile.registrationProvinceId,
});
const district = await this.districtRepository.findOneBy({
id: profile.registrationDistrictId,
});
const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId });
const root =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
const child1 =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
const child2 =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
const child3 =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
const child4 =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
let _regisAddres =
profile && profile.registrationAddress != null ? profile.registrationAddress : "";
let _subDistrict =
subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "";
let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "";
let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "";
let registrationZipCode =
profile && profile.registrationZipCode != null
? ` รหัสไปรษณีย์ ${profile.registrationZipCode}`
: "";
let _root = root == null || root == undefined ? "" : `${root.orgRootName}`;
let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null || child3 == undefined ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`;
const educations = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id },
order: { lastUpdatedAt: "DESC" },
});
const Education = educations.map((item) => ({
Institute: item.institute,
Date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.endDate))}`
: "",
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "",
}));
const mapData = {
Id: profile.id,
2024-05-23 15:28:49 +07:00
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "",
Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth:
profile.birthDate != null
2024-06-06 18:06:01 +07:00
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.birthDate))
: "",
DateRetire:
profile.dateRetire != null
2024-06-06 18:06:01 +07:00
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire))
: "",
2024-05-28 12:02:41 +07:00
RegistrationAddress: Extension.ToThaiNumber(
`${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
),
SalaryAmount:
profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null
? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString())
: "",
Education: Education,
2024-05-28 12:02:41 +07:00
AppointText:
profile.dateAppoint != null
2024-06-06 18:06:01 +07:00
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
2024-05-28 12:02:41 +07:00
: "",
SalaryDate:
profile.profileSalary.length > 0 && profile.profileSalary[0].date != null
2024-06-06 16:55:58 +07:00
? Extension.ToThaiNumber(
2024-06-06 18:06:01 +07:00
Extension.ToThaiShortDate_monthYear(profile.profileSalary[0].date),
2024-06-06 16:55:58 +07:00
)
: "",
2024-05-23 15:28:49 +07:00
PositionName: profile.position != null ? profile.position : "",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
};
return new HttpSuccess(mapData);
}
2024-02-08 10:56:03 +07:00
2024-05-24 13:42:59 +07:00
@Get("kk1/{id}")
public async getKk1(@Path() id: string) {
const profiles = await this.profileRepo.findOne({
select: [
"citizenId",
"prefix",
"firstName",
"lastName",
"birthDate",
"currentAddress",
"currentDistrictId",
"currentProvinceId",
"telephoneNumber",
"avatar",
],
where: { id: id },
});
2024-05-24 15:57:29 +07:00
const profileOc = await this.profileRepo.findOne({
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: id },
2024-05-24 13:42:59 +07:00
});
2024-05-24 15:57:29 +07:00
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
2024-05-24 13:42:59 +07:00
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({
where: { profileId: id },
2024-06-06 19:33:02 +07:00
select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"],
order: { lastUpdatedAt: "DESC" },
2024-05-24 13:42:59 +07:00
});
const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({
where: { profileId: id },
2024-05-24 13:42:59 +07:00
select: ["motherPrefix", "motherFirstName", "motherLastName"],
2024-06-06 19:17:51 +07:00
order: { lastUpdatedAt: "DESC" },
2024-05-24 13:42:59 +07:00
});
const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({
where: { profileId: id },
2024-05-24 13:42:59 +07:00
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
2024-06-06 19:17:51 +07:00
order: { lastUpdatedAt: "DESC" },
2024-05-24 13:42:59 +07:00
});
const root =
2024-05-24 15:57:29 +07:00
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
2024-05-24 13:42:59 +07:00
const child1 =
2024-05-24 15:57:29 +07:00
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
2024-05-24 13:42:59 +07:00
const child2 =
2024-05-24 15:57:29 +07:00
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
2024-05-24 13:42:59 +07:00
const child3 =
2024-05-24 15:57:29 +07:00
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
2024-05-24 13:42:59 +07:00
const child4 =
2024-05-24 15:57:29 +07:00
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
2024-05-24 13:42:59 +07:00
// Construct org path
const _root = root ? `${root.orgRootName}` : "";
const _child1 = child1 ? `${child1.orgChild1Name}/` : "";
const _child2 = child2 ? `${child2.orgChild2Name}/` : "";
const _child3 = child3 ? `${child3.orgChild3Name}/` : "";
const _child4 = child4 ? `${child4.orgChild4Name}/` : "";
const Profile = {
CitizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
Prefix: profiles?.prefix != null ? profiles.prefix : "",
FirstName: profiles?.firstName != null ? profiles.firstName : "",
LastName: profiles?.lastName != null ? profiles.lastName : "",
2024-06-06 14:39:41 +07:00
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
BirthDay: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString())
: null,
BirthDayText:
profiles.birthDate != null
2024-06-06 14:39:41 +07:00
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_noPrefix(profiles.birthDate).toString(),
)
: "",
BirthMonth: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString())
: null, // Months are zero-based
BirthYear: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getFullYear().toString())
: null,
BirthYearText:
profiles.birthDate != null
2024-06-06 14:39:41 +07:00
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_noPrefix(profiles.birthDate).toString(),
)
: "",
Address: "",
District: "",
Area: "",
Province: "",
Telephone: profiles?.telephoneNumber ?? null,
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
CouplePrefix: profileFamilyCouple?.couplePrefix ?? "",
CoupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
2024-06-06 19:33:02 +07:00
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim()
2024-05-24 13:42:59 +07:00
: null,
FatherPrefix: profileFamilyFather?.fatherPrefix ?? "",
FatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
2024-06-06 14:48:23 +07:00
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
2024-05-24 13:42:59 +07:00
: null,
MotherPrefix: profileFamilyMother?.motherPrefix ?? "",
MotherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
2024-06-06 14:48:23 +07:00
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
2024-05-24 13:42:59 +07:00
: null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
StartDate: profiles?.dateStart,
AppointDate: profiles?.dateAppoint ?? "",
BirthDate: profiles?.birthDate
2024-06-06 14:39:41 +07:00
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(profiles.birthDate))
: null,
RetireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(profiles.dateRetireLaw.toString())
: "",
// AvatarId: profiles?.avatar ?? null,
};
2024-05-24 13:42:59 +07:00
const certs = await this.certificateRepository.find({
where: { profileId: id },
select: ["certificateType", "issuer", "certificateNo", "issueDate"],
});
const Cert = certs.map((item) => ({
2024-05-24 13:42:59 +07:00
CertificateType: item.certificateType ?? null,
Issuer: item.issuer ?? null,
CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
2024-06-06 14:39:41 +07:00
IssueDate: Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.issueDate)) ?? null,
2024-05-24 13:42:59 +07:00
}));
const trainings = await this.trainingRepository.find({
2024-05-29 18:04:56 +07:00
select: ["startDate", "endDate", "place", "department", "name"],
2024-05-24 13:42:59 +07:00
where: { profileId: id },
});
const Training = trainings.map((item) => ({
Institute: item.department ?? "",
Start:
item.startDate == null
? ""
2024-06-06 14:39:41 +07:00
: Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.startDate)),
End:
2024-06-06 14:39:41 +07:00
item.endDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.endDate)),
2024-05-29 18:04:56 +07:00
Date:
item.startDate && item.endDate
2024-06-06 14:39:41 +07:00
? `${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.endDate))}`
2024-05-29 18:04:56 +07:00
: "",
Level: "",
2024-05-29 18:04:56 +07:00
Degree: item.name,
Field: "",
2024-05-24 13:42:59 +07:00
}));
const disciplines = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"],
where: { profileId: id },
});
const Discipline = disciplines.map((item) => ({
DisciplineYear:
Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null,
2024-05-24 13:42:59 +07:00
DisciplineDetail: item.detail ?? null,
2024-06-06 18:06:01 +07:00
RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
2024-05-24 13:42:59 +07:00
}));
const educations = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id },
2024-06-07 10:25:41 +07:00
order: { lastUpdatedAt: "DESC" },
2024-05-24 13:42:59 +07:00
});
const Education = educations.map((item) => ({
Institute: item.institute,
Start:
item.startDate == null
? ""
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()),
End:
item.endDate == null
? ""
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
2024-05-29 18:04:56 +07:00
Date:
item.startDate && item.endDate
2024-06-06 14:39:41 +07:00
? `${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.endDate))}`
2024-05-29 18:04:56 +07:00
: "",
Level: item.educationLevel ?? "",
2024-05-29 18:04:56 +07:00
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "",
Field: item.field ?? "-",
2024-05-24 13:42:59 +07:00
}));
const salarys = await this.salaryRepository.find({
select: [
"date",
"position",
"posNo",
"positionType",
"positionLevel",
"positionSalaryAmount",
"refCommandNo",
2024-06-06 18:06:01 +07:00
"amount",
"templateDoc",
2024-05-24 13:42:59 +07:00
],
where: { profileId: id },
});
const Salary = salarys.map((item) => ({
SalaryDate: item.date
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.date))
: null,
2024-05-24 13:42:59 +07:00
Position: item.position ?? null,
PosNo: item.posNo ?? null,
2024-06-06 18:06:01 +07:00
Salary: item.amount ?? null,
Rank: item.positionLevel ?? null,
RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null,
2024-05-24 13:42:59 +07:00
PositionLevel: item.positionLevel ?? null,
2024-06-27 14:28:23 +07:00
PositionType: item.positionType ?? null,
PositionAmount:
item.positionSalaryAmount == null
? null
: Extension.ToThaiNumber(item.positionSalaryAmount.toString()),
2024-06-06 14:39:41 +07:00
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
2024-05-24 13:42:59 +07:00
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}));
return new HttpSuccess({
Profile: [Profile],
Cert,
Training,
Discipline,
Education,
Salary,
});
2024-05-24 13:42:59 +07:00
}
/**
*
*
* @param {string} id Id
*/
@Get("placement/{id}")
2024-06-27 14:28:23 +07:00
async getProfilePlacement(@Request() request: RequestWithUser, @Path() id: string) {
const profile = await this.profileRepo.findOne({
where: { id: id },
});
2024-06-27 14:28:23 +07:00
const posMaster = await this.posMasterRepo.findOne({
where: { current_holderId: profile?.id },
});
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
const orgRoot = posMaster.orgRootId;
const orgChild1 = posMaster.orgChild1Id;
const orgChild2 = posMaster.orgChild2Id;
const orgChild3 = posMaster.orgChild3Id;
const orgChild4 = posMaster.orgChild4Id;
2024-06-27 14:28:23 +07:00
const findChild4 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.getMany();
const findChild3 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild3Id = :orgChild3Id", { orgChild3Id: orgChild3 })
.andWhere("current_holders.orgChild4Id IS NULL")
.getMany();
const findChild2 = await this.profileRepo
2024-06-11 16:13:51 +07:00
.createQueryBuilder("profile")
2024-06-27 14:28:23 +07:00
.leftJoinAndSelect("profile.current_holders", "current_holders")
2024-06-11 16:13:51 +07:00
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
2024-06-12 15:16:55 +07:00
.andWhere({ keycloak: Not(IsNull()) })
2024-06-27 14:28:23 +07:00
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild2Id = :orgChild2Id", { orgChild2Id: orgChild2 })
.andWhere("current_holders.orgChild3Id IS NULL")
2024-06-11 16:13:51 +07:00
.getMany();
2024-06-27 14:28:23 +07:00
const findChild1 = await this.profileRepo
2024-06-11 16:13:51 +07:00
.createQueryBuilder("profile")
2024-06-27 14:28:23 +07:00
.leftJoinAndSelect("profile.current_holders", "current_holders")
2024-06-11 16:13:51 +07:00
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
2024-06-12 15:16:55 +07:00
.andWhere({ keycloak: Not(IsNull()) })
2024-06-27 14:28:23 +07:00
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild1Id = :orgChild1Id", { orgChild1Id: orgChild1 })
.andWhere("current_holders.orgChild2Id IS NULL")
2024-06-11 16:13:51 +07:00
.getMany();
2024-06-27 14:28:23 +07:00
const findRoot = await this.profileRepo
2024-06-11 16:13:51 +07:00
.createQueryBuilder("profile")
2024-06-27 14:28:23 +07:00
.leftJoinAndSelect("profile.current_holders", "current_holders")
2024-06-11 16:13:51 +07:00
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
2024-06-12 15:16:55 +07:00
.andWhere({ keycloak: Not(IsNull()) })
2024-06-27 14:28:23 +07:00
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild1Id IS NULL")
2024-06-11 16:13:51 +07:00
.getMany();
2024-06-27 14:28:23 +07:00
let _caregiver: any;
let caregiver: any;
let _commander: any;
let commander: any;
let _chairman: any;
let chairman: any;
if (posMaster) {
if (orgChild4) {
if (findChild4) {
_caregiver = findChild4;
_commander = findChild3;
_chairman = findChild2;
} else if (findChild3) {
_caregiver = findChild3;
_commander = findChild2;
_chairman = findChild1;
} else if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
}
} else if (orgChild3) {
if (findChild3) {
_caregiver = findChild3;
_commander = findChild2;
_chairman = findChild1;
} else if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
}
} else if (orgChild2) {
if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
}
} else if (orgChild1) {
if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
}
} else if (orgRoot) {
if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
}
}
caregiver = _caregiver.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
}));
commander = _commander.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
}));
chairman = _chairman.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
}));
}
return new HttpSuccess({ caregiver, commander, chairman });
}
/**
*
*
*/
@Get("commander")
async getProfileCommander(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
});
2024-06-25 18:41:08 +07:00
const posMaster = await this.posMasterRepo.findOne({
where: { current_holderId: profile?.id },
});
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
const orgRoot = posMaster.orgRootId;
const orgChild1 = posMaster.orgChild1Id;
const orgChild2 = posMaster.orgChild2Id;
const orgChild3 = posMaster.orgChild3Id;
const orgChild4 = posMaster.orgChild4Id;
2024-06-27 14:28:23 +07:00
const findChild4 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.getMany();
const findChild3 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild3Id = :orgChild3Id", { orgChild3Id: orgChild3 })
.andWhere("current_holders.orgChild4Id IS NULL")
.getMany();
const findChild2 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild2Id = :orgChild2Id", { orgChild2Id: orgChild2 })
.andWhere("current_holders.orgChild3Id IS NULL")
.getMany();
const findChild1 = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild1Id = :orgChild1Id", { orgChild1Id: orgChild1 })
.andWhere("current_holders.orgChild2Id IS NULL")
.getMany();
const findRoot = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.andWhere({ keycloak: Not(IsNull()) })
.where("current_holders.current_holderId IS NOT NULL")
.andWhere("current_holders.orgRootId = :orgRootId", { orgRootId: orgRoot })
.andWhere("current_holders.current_holderId <> :current_holderId", {
current_holderId: posMaster.current_holderId,
})
.andWhere("current_holders.orgChild1Id IS NULL")
.getMany();
2024-06-26 15:10:07 +07:00
let _caregiver: any;
let caregiver: any;
let _commander: any;
let commander: any;
let _chairman: any;
let chairman: any;
if (posMaster) {
if (orgChild4) {
if (findChild4) {
_caregiver = findChild4;
_commander = findChild3;
_chairman = findChild2;
} else if (findChild3) {
_caregiver = findChild3;
_commander = findChild2;
_chairman = findChild1;
} else if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
2024-06-25 18:41:08 +07:00
}
2024-06-26 15:10:07 +07:00
} else if (orgChild3) {
if (findChild3) {
_caregiver = findChild3;
_commander = findChild2;
_chairman = findChild1;
} else if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
2024-06-25 18:41:08 +07:00
}
2024-06-26 15:10:07 +07:00
} else if (orgChild2) {
if (findChild2) {
_caregiver = findChild2;
_commander = findChild1;
_chairman = findRoot;
} else if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
2024-06-25 18:41:08 +07:00
}
2024-06-26 15:10:07 +07:00
} else if (orgChild1) {
if (findChild1) {
_caregiver = findChild1;
_commander = findRoot;
_chairman = findRoot;
} else if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
2024-06-25 18:41:08 +07:00
}
2024-06-27 14:28:23 +07:00
} else if (orgRoot) {
2024-06-26 15:10:07 +07:00
if (findRoot) {
_caregiver = findRoot;
_commander = findRoot;
_chairman = findRoot;
2024-06-25 18:41:08 +07:00
}
2024-06-26 15:10:07 +07:00
}
2024-06-27 14:28:23 +07:00
caregiver = _caregiver.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
2024-06-26 15:10:07 +07:00
}));
2024-06-27 14:28:23 +07:00
commander = _commander.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
2024-06-26 15:10:07 +07:00
}));
2024-06-27 14:28:23 +07:00
chairman = _chairman.map((_data: any) => ({
id: _data.id,
prefix: _data.prefix,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
position: _data.position,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
isDirector: true,
2024-06-26 15:10:07 +07:00
}));
2024-06-25 18:41:08 +07:00
}
2024-06-27 14:28:23 +07:00
return new HttpSuccess({ caregiver, commander, chairman });
}
2024-02-08 10:56:03 +07:00
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
*/
@Post()
async createProfile(@Request() request: RequestWithUser, @Body() body: CreateProfile) {
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR,
2024-05-15 13:38:00 +07:00
"รหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
);
2024-02-21 13:53:02 +07:00
}
2024-02-08 15:40:47 +07:00
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
2024-02-08 10:56:03 +07:00
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
2024-05-15 13:38:00 +07:00
if (body.citizenId.length !== 13) {
2024-05-16 13:39:25 +07:00
throw new HttpError(
HttpStatus.NOT_FOUND,
"กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก",
);
2024-05-15 13:38:00 +07:00
}
if (body.citizenId) {
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
const cal =
citizenIdDigits[0] * 13 +
citizenIdDigits[1] * 12 +
citizenIdDigits[2] * 11 +
citizenIdDigits[3] * 10 +
citizenIdDigits[4] * 9 +
citizenIdDigits[5] * 8 +
citizenIdDigits[6] * 7 +
citizenIdDigits[7] * 6 +
citizenIdDigits[8] * 5 +
citizenIdDigits[9] * 4 +
citizenIdDigits[10] * 3 +
citizenIdDigits[11] * 2;
const calStp2 = cal % 11;
let chkDigit = 11 - calStp2;
2024-05-16 13:39:25 +07:00
if (chkDigit === 10) {
chkDigit = 1;
2024-05-16 13:39:25 +07:00
} else if (chkDigit === 11) {
2024-05-15 13:38:00 +07:00
chkDigit = chkDigit % 10;
}
2024-05-15 13:38:00 +07:00
// else if(chkDigit === 11){
// chkDigit = cal % 10;
// }
2024-05-16 13:39:25 +07:00
if (citizenIdDigits[12] !== chkDigit) {
2024-05-15 13:38:00 +07:00
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
2024-05-15 13:38:00 +07:00
// if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
// }
const profile = Object.assign(new Profile(), body);
profile.isProbation = false;
profile.isLeave = false;
2024-02-28 14:47:28 +07:00
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
2024-05-15 18:06:28 +07:00
profile.dateRetire = calculateRetireDate(profile.birthDate);
2024-05-16 15:22:30 +07:00
profile.dateRetireLaw = calculateRetireLaw(profile.birthDate);
await this.profileRepo.save(profile);
2024-02-28 14:47:28 +07:00
return new HttpSuccess();
2024-02-08 10:56:03 +07:00
}
/**
* API
*
* @summary ORG_065 - (ADMIN) #XXX
*
*/
@Post("all")
2024-05-03 17:38:00 +07:00
async createProfileAll(
@Request() request: RequestWithUser,
@Body() body: CreateProfileAllFields,
) {
2024-05-14 17:24:38 +07:00
const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId });
if (profileExist) {
return new HttpSuccess(profileExist.id);
}
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
const profile: Profile = Object.assign(new Profile(), body);
2024-06-25 10:21:30 +07:00
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;
profile.lastUpdateFullName = request.user.name;
await this.profileRepo.save(profile);
return new HttpSuccess(profile.id);
}
2024-06-19 23:03:54 +07:00
/**
* API
*
* @summary ORG_065 - (ADMIN) #XXX
*
*/
@Post("allv2")
async createProfileAllV2(
@Request() request: RequestWithUser,
@Body() body: CreateProfileAllFields,
) {
const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId });
if (profileExist) {
return new HttpSuccess(profileExist.id);
}
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
const profile: Profile = Object.assign(new Profile(), body);
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
await this.profileRepo.save(profile);
return new HttpSuccess(profile.id);
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command11/{profileId}")
async ExecuteCommand11Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
// const posType = await this.posTypeRepo.findOneBy({ id: String(profile.posTypeId) })
// const posLevel = await this.posLevelRepo.findOneBy({ id: String(profile.posLevelId) })
if (profile.isProbation != false) {
profile.isProbation = false;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
//profile.position,
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([
this.profileRepo.save(profile),
this.salaryRepository.save(profileSalary),
]);
}
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command12/{profileId}")
async ExecuteCommand12Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
profile.leaveReason =
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command19/{profileId}")
async ExecuteCommand19Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command20/{profileId}")
async ExecuteCommand20Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command25/{profileId}")
async ExecuteCommand25Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command26/{profileId}")
async ExecuteCommand26Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command27/{profileId}")
async ExecuteCommand27Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command28/{profileId}")
async ExecuteCommand28Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command29/{profileId}")
async ExecuteCommand29Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command30/{profileId}")
async ExecuteCommand30Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command32/{profileId}")
async ExecuteCommand32Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
* @summary API (ADMIN)
*
*/
@Post("command31/{profileId}")
async ExecuteCommand31Async(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date;
profile.isLeave = true;
2024-06-19 23:03:54 +07:00
profile.leaveReason = "ได้รับโทษทางวินัย งดโทษ";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: body.profileId,
date: body.date,
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
2024-06-19 23:03:54 +07:00
position:
profile.profileSalary.length > 0
2024-06-19 23:03:54 +07:00
? profile.profileSalary[profile.profileSalary.length - 1].position
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
/**
* API
*
*
*/
@Post("cal/retire")
async calDateRetire(@Body() birthDate: Date) {
const retireDate = await calculateRetireDate(birthDate);
const age = calculateAge(birthDate);
return new HttpSuccess({ retireDate, age });
}
2024-02-08 10:56:03 +07:00
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
* @param {string} id Id
*/
@Put("{id}")
async updateProfile(
@Request() request: RequestWithUser,
2024-02-08 10:56:03 +07:00
@Path() id: string,
@Body() body: UpdateProfile,
2024-02-08 10:56:03 +07:00
) {
const exists =
!!body.citizenId &&
(await this.profileRepo.findOne({
where: { id: Not(id), citizenId: body.citizenId },
}));
2024-02-08 10:56:03 +07:00
if (exists) {
2024-05-15 13:38:00 +07:00
throw new HttpError(HttpStatus.CONFLICT, "รหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
2024-02-21 13:53:02 +07:00
}
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
2024-02-08 15:40:47 +07:00
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
2024-02-08 15:40:47 +07:00
}
2024-05-16 13:39:25 +07:00
2024-05-15 13:38:00 +07:00
if (body.citizenId && body.citizenId.length !== 13) {
2024-05-16 13:39:25 +07:00
throw new HttpError(
HttpStatus.NOT_FOUND,
"กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก",
);
2024-05-15 13:38:00 +07:00
}
if (body.citizenId) {
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
const cal =
citizenIdDigits[0] * 13 +
citizenIdDigits[1] * 12 +
citizenIdDigits[2] * 11 +
citizenIdDigits[3] * 10 +
citizenIdDigits[4] * 9 +
citizenIdDigits[5] * 8 +
citizenIdDigits[6] * 7 +
citizenIdDigits[7] * 6 +
citizenIdDigits[8] * 5 +
citizenIdDigits[9] * 4 +
citizenIdDigits[10] * 3 +
citizenIdDigits[11] * 2;
const calStp2 = cal % 11;
let chkDigit = 11 - calStp2;
2024-05-16 13:39:25 +07:00
if (chkDigit === 10) {
2024-05-15 13:38:00 +07:00
chkDigit = 1;
2024-05-16 13:39:25 +07:00
} else if (chkDigit === 11) {
2024-05-15 13:38:00 +07:00
chkDigit = chkDigit % 10;
}
// else if(chkDigit === 11){
// chkDigit = cal % 10;
// }
2024-05-16 13:39:25 +07:00
if (citizenIdDigits[12] !== chkDigit) {
2024-05-15 13:38:00 +07:00
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
2024-02-08 15:40:47 +07:00
const record = await this.profileRepo.findOneBy({ id });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
await this.profileHistoryRepo.save(
Object.assign(new ProfileHistory(), {
...record,
profileId: id,
id: undefined,
}),
);
Object.assign(record, body);
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
2024-05-15 18:06:28 +07:00
record.dateRetire = calculateRetireDate(record.birthDate);
2024-05-16 15:22:30 +07:00
record.dateRetireLaw = calculateRetireLaw(record.birthDate);
await this.profileRepo.save(record);
2024-02-28 14:47:28 +07:00
return new HttpSuccess();
2024-02-08 10:56:03 +07:00
}
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
* @param {string} id Id
*/
@Delete("{id}")
async deleteProfile(@Path() id: string) {
const result = await this.profileRepo.delete({ id });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
2024-02-08 10:56:03 +07:00
}
2024-02-28 14:47:28 +07:00
return new HttpSuccess();
2024-02-08 10:56:03 +07:00
}
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
2024-05-24 01:11:47 +07:00
*
* @param {string} id Id
*/
@Get("user")
async getProfileByUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
},
where: { keycloak: request.user.sub },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(profile);
}
2024-05-27 11:36:55 +07:00
@Get("type")
async checkRole(@Request() request: RequestWithUser) {
let role: any;
const checkProfile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
});
role = "OFFICER";
if (!checkProfile) {
const checkEmployee = await this.profileEmpRepo.findOne({
where: { keycloak: request.user.sub },
select: ["employeeClass"],
});
if (checkEmployee?.employeeClass === "PERM" || checkEmployee?.employeeClass === "TEMP") {
role = checkEmployee.employeeClass.toUpperCase();
} else {
role = "EMPLOYEE";
}
if (!checkProfile && !checkEmployee)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
}
return new HttpSuccess(role);
}
2024-05-24 13:13:52 +07:00
/**
* API
*
2024-05-24 13:42:59 +07:00
* @summary
2024-05-24 13:13:52 +07:00
*
* @param {string} id Id
*/
@Get("history/user")
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
const historyProfile = await this.profileHistoryRepo.find({
relations: {
posLevel: true,
posType: true,
},
where: { keycloak: request.user.sub },
order: {
2024-05-24 13:42:59 +07:00
createdAt: "ASC",
},
2024-05-24 13:13:52 +07:00
});
if (!historyProfile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(historyProfile);
}
2024-02-08 10:56:03 +07:00
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
* @param {string} id Id
*/
@Get("{id}")
async getProfile(@Path() id: string) {
const profile = await this.profileRepo.findOne({
2024-03-20 15:35:18 +07:00
relations: {
posLevel: true,
posType: true,
},
2024-02-08 10:56:03 +07:00
where: { id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
2024-02-28 14:47:28 +07:00
return new HttpSuccess(profile);
2024-02-08 10:56:03 +07:00
}
2024-05-27 17:57:16 +07:00
// @Get("keycloak/{id}")
// async getProfileByKeycloakId(@Path() id: string) {
// const profile = await this.profileRepo.findOne({
// relations: {
// posLevel: true,
// posType: true,
// },
// where: { keycloak: id },
// });
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// return new HttpSuccess(profile);
// }
2024-05-27 16:48:50 +07:00
@Get("history/{id}")
async getProfileHistory(@Path() id: string) {
const profile = await this.profileHistoryRepo.find({
relations: {
posLevel: true,
posType: true,
},
where: { profileId: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(profile);
}
2024-02-08 10:56:03 +07:00
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
*/
@Get()
2024-03-24 19:43:37 +07:00
@Example({
status: 200,
message: "สำเร็จ",
result: {
data: [
{
id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae",
createdAt: "2024-03-24T12:39:12.105Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-24T12:41:43.164Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "string",
rank: null,
2024-03-24 19:43:37 +07:00
prefix: null,
firstName: "Methapon",
lastName: "Metanipat",
citizenId: null,
position: null,
posLevelId: null,
posTypeId: null,
email: null,
phone: null,
keycloak: null,
isProbation: false,
dateRetire: null,
birthDate: null,
ethnicity: null,
telephoneNumber: null,
gender: null,
2024-03-24 19:43:37 +07:00
relationship: null,
bloodGroup: null,
posLevel: null,
posType: null,
2024-04-23 13:59:45 +07:00
org: null,
2024-03-24 19:43:37 +07:00
},
],
total: 1,
},
})
2024-02-27 17:30:37 +07:00
async listProfile(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
2024-03-24 19:43:37 +07:00
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
2024-03-22 16:04:09 +07:00
@Query() searchKeyword: string = "",
2024-03-26 09:47:17 +07:00
@Query() posType?: string,
@Query() posLevel?: string,
@Query() yearLeave?: number,
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
) {
2024-03-26 09:47:17 +07:00
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "citizenId") {
queryLike = "profile.citizenId LIKE :keyword";
} else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword";
2024-03-24 19:43:37 +07:00
}
2024-03-26 09:47:17 +07:00
const [record, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
2024-03-26 09:47:17 +07:00
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
: "1=1",
{
keyword1: `${posType}`,
},
)
.andWhere(
posLevel != undefined && posLevel != null && posLevel != ""
? "posLevel.posLevelName LIKE :keyword2"
: "1=1",
{
keyword2: `${posLevel}`,
},
)
.andWhere(
isProbation != undefined && isProbation != null
? `profile.isProbation = ${isProbation}`
: "1=1",
)
.andWhere(
isRetire != undefined && isRetire != null
? isRetire == true
? `profile.dateRetire IS null`
: `profile.dateRetire IS NOT NULL`
: "1=1",
)
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
2024-03-26 09:47:17 +07:00
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all(
record.map((_data) => {
const posExecutive =
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true) == null ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
? null
: _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
?.posExecutiveName;
const shortName =
_data.current_holders.length == 0
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild3 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
_data.current_holders.length == 0 ||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
2024-04-18 12:49:02 +07:00
const child1 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
2024-04-23 13:59:45 +07:00
2024-04-18 12:49:02 +07:00
const child2 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
2024-04-23 13:59:45 +07:00
2024-04-18 12:49:02 +07:00
const child3 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
2024-04-23 13:59:45 +07:00
2024-04-18 12:49:02 +07:00
const child4 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
2024-04-23 13:59:45 +07:00
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
2024-04-18 12:49:02 +07:00
return {
id: _data.id,
2024-05-16 13:39:25 +07:00
avatar: _data.avatar,
avatarName: _data.avatarName,
prefix: _data.prefix,
rank: _data.rank,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
posTypeId: _data.posType == null ? null : _data.posType.id,
position: _data.position,
posExecutive: posExecutive,
posNo: shortName,
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: root == null ? null : root.orgRevisionId,
2024-06-25 10:21:30 +07:00
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
};
}),
);
2024-03-24 19:43:37 +07:00
return new HttpSuccess({ data: data, total });
2024-02-08 10:56:03 +07:00
}
/**
* API
*
* @summary ORG_063 - (ADMIN) #68
*/
@Post("search")
async searchProfileOrg(
@Body()
requestBody: {
2024-05-02 17:39:07 +07:00
position?: string | null;
posLevelId?: string | null;
posTypeId?: string | null;
page: number;
pageSize: number;
keyword?: string;
},
) {
const orgRevision = await this.orgRevisionRepo.findOne({
2024-02-28 14:47:28 +07:00
where: {
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
},
relations: ["posMasters"],
});
if (!orgRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
2024-02-28 14:47:28 +07:00
}
const [profiles, total] = await this.profileRepo
2024-02-28 14:47:28 +07:00
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.next_holders", "next_holders")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.where(
requestBody.position != null && requestBody.position != ""
? "profile.position LIKE :position"
: "1=1",
{
position: `%${requestBody.position}%`,
},
2024-02-28 14:47:28 +07:00
)
.andWhere(
new Brackets((qb) => {
qb.where(
requestBody.keyword != null && requestBody.keyword != ""
? "profile.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${requestBody.keyword}%`,
},
)
.orWhere(
requestBody.keyword != null && requestBody.keyword != ""
2024-02-28 14:47:28 +07:00
? "profile.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${requestBody.keyword}%`,
},
)
2024-02-28 14:47:28 +07:00
.orWhere(
requestBody.keyword != null && requestBody.keyword != ""
? "profile.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${requestBody.keyword}%`,
},
)
.orWhere(
requestBody.keyword != null && requestBody.keyword != ""
? "profile.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${requestBody.keyword}%`,
},
);
}),
)
.andWhere(
requestBody.posTypeId != null && requestBody.posTypeId != ""
? "profile.posTypeId LIKE :posTypeId"
: "1=1",
{
posTypeId: `%${requestBody.posTypeId}%`,
},
)
.andWhere(
requestBody.posLevelId != null && requestBody.posLevelId != ""
? "profile.posLevelId LIKE :posLevelId"
: "1=1",
{
posLevelId: `%${requestBody.posLevelId}%`,
},
)
.andWhere(
new Brackets((qb) => {
qb.where("profile.id NOT IN (:...ids)", {
ids:
orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId).length == 0
? ["zxc"]
: orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId),
2024-02-28 14:47:28 +07:00
});
}),
)
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
2024-02-28 14:47:28 +07:00
const data = profiles.map((_data) => ({
id: _data.id,
prefix: _data.prefix,
rank: _data.rank,
2024-02-28 14:47:28 +07:00
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName,
position: _data.position,
}));
2024-02-28 14:47:28 +07:00
return new HttpSuccess({ data: data, total });
}
/**
* API
*
* @summary
*
*/
@Post("search/history/oc")
async searchHistoryOC(
@Body()
requestBody: {
posNo?: string;
position?: string;
},
) {
const profiles = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
.select([
"profile.id",
"profile.prefix",
"profile.firstName",
"profile.lastName",
"profile.citizenId",
"profileSalary.position",
"profileSalary.posNo",
"profileSalary.date",
])
.andWhere(
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
? "profileSalary.position LIKE :position"
: "1=2",
{
position: `%${requestBody.position}%`,
},
)
.orWhere(
requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined
? "profileSalary.posNo LIKE :posNo"
: "1=2",
{
posNo: `%${requestBody.posNo}%`,
},
)
.getMany();
const mapData = profiles.map((profile) => {
let profileSalary;
if (profile.profileSalary && profile.profileSalary.length > 0) {
profileSalary = profile.profileSalary.reduce((latest, current) => {
return new Date(current.date) > new Date(latest.date) ? current : latest;
});
}
return {
id: profile.id,
// prefix: profile.prefix,
// firstName: profile.firstName,
// lastName: profile.lastName,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
citizenId: profile.citizenId,
position: profileSalary ? profileSalary.position : null,
posNo: profileSalary ? profileSalary.posNo : null,
date: profileSalary ? profileSalary.date : null,
};
});
return new HttpSuccess(mapData);
}
/**
* API keycloak
*
* @summary ORG_065 - keycloak (ADMIN) #70
*
*/
@Get("keycloak/position")
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
2024-02-27 17:30:37 +07:00
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
2024-02-27 17:30:37 +07:00
}
const orgRevisionPublish = await this.orgRevisionRepo
2024-02-27 17:30:37 +07:00
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
if (!orgRevisionPublish) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
}
2024-02-27 17:30:37 +07:00
2024-05-01 11:08:44 +07:00
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);
2024-05-17 17:14:41 +07:00
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;
2024-05-14 17:24:38 +07:00
const position = await this.positionRepository.findOne({
relations: ["posExecutive"],
2024-05-14 17:24:38 +07:00
where: {
posMasterId: posMaster?.id,
},
});
2024-04-23 13:59:45 +07:00
const _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
avatar: profile.avatar,
2024-06-12 17:44:19 +07:00
isProbation: profile.isProbation,
avatarName: profile.avatarName,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
2024-05-17 17:14:41 +07:00
birthDate: profile.birthDate,
position: profile.position,
leaveDate: profile.dateLeave,
2024-05-01 11:08:44 +07:00
posMaster: posMaster == null ? null : posMaster.posMasterNo,
2024-05-17 17:14:41 +07:00
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,
2024-05-14 17:24:38 +07:00
posExecutiveName:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName,
posExecutivePriority:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutivePriority,
posExecutiveId:
position == null || position.posExecutive == null ? null : position.posExecutive.id,
2024-05-17 17:14:41 +07:00
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,
2024-04-23 13:59:45 +07:00
node: null,
nodeId: null,
};
2024-04-23 13:59:45 +07:00
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;
}
2024-02-28 14:47:28 +07:00
return new HttpSuccess(_profile);
}
/**
* API profileid
*
* @summary ORG_065 - profileid (ADMIN) #70
*
*/
@Get("profileid/position/{id}")
async getProfileByProfileid(
@Request() request: { user: Record<string, any> },
@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, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
2024-05-02 17:39:07 +07:00
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;
2024-06-07 10:25:41 +07:00
const position = await this.positionRepository.findOne({
relations: ["posExecutive"],
where: {
posMasterId: posMaster?.id,
},
});
2024-05-02 17:39:07 +07:00
const _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
2024-06-17 13:27:11 +07:00
isProbation: profile.isProbation,
2024-05-02 17:39:07 +07:00
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
2024-05-03 17:38:00 +07:00
birthDate: profile.birthDate,
2024-05-02 17:39:07 +07:00
position: profile.position,
leaveDate: profile.dateLeave,
2024-05-02 17:39:07 +07:00
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,
2024-06-07 10:25:41 +07:00
posExecutiveName:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName,
2024-05-02 17:39:07 +07:00
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;
2024-06-25 10:21:30 +07:00
_profile.nodeShortName = _profile.child4ShortName;
2024-05-02 17:39:07 +07:00
} else if (_profile.child3Id != null) {
_profile.node = 3;
_profile.nodeId = _profile.child3Id;
2024-06-25 10:21:30 +07:00
_profile.nodeShortName = _profile.child3ShortName;
2024-05-02 17:39:07 +07:00
} else if (_profile.child2Id != null) {
_profile.node = 2;
_profile.nodeId = _profile.child2Id;
2024-06-25 10:21:30 +07:00
_profile.nodeShortName = _profile.child2ShortName;
2024-05-02 17:39:07 +07:00
} else if (_profile.child1Id != null) {
_profile.node = 1;
_profile.nodeId = _profile.child1Id;
2024-06-25 10:21:30 +07:00
_profile.nodeShortName = _profile.child1ShortName;
2024-05-02 17:39:07 +07:00
} else if (_profile.rootId != null) {
_profile.node = 0;
_profile.nodeId = _profile.rootId;
2024-06-25 10:21:30 +07:00
_profile.nodeShortName = _profile.rootShortName;
2024-05-02 17:39:07 +07:00
}
return new HttpSuccess(_profile);
}
/**
2024-05-02 17:54:01 +07:00
* API citizenId
2024-05-02 17:39:07 +07:00
*
2024-05-02 17:54:01 +07:00
* @summary ORG_065 - citizenId (ADMIN) #70
*
* @param id (citizenId)
2024-05-02 17:54:01 +07:00
*/
@Get("citizenid/position/{id}")
async getProfileByCitizenId(
@Request() request: { user: Record<string, any> },
@Path() id: string,
) {
const profile = await this.profileRepo.findOne({
where: { citizenId: 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 _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
leaveDate: profile.dateLeave,
2024-05-02 17:54:01 +07:00
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,
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;
_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);
}
/**
* API profileempid
*
* @summary ORG_065 - profileempid (ADMIN) #70
2024-05-02 17:39:07 +07:00
*
*/
@Get("profileempid/position/{id}")
2024-05-02 17:54:01 +07:00
async getProfileByProfileempid(
2024-05-02 17:39:07 +07:00
@Request() request: { user: Record<string, any> },
@Path() id: string,
) {
2024-05-17 09:32:07 +07:00
const profile = await this.profileEmpRepo.findOne({
2024-05-02 17:39:07 +07:00
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 _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
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,
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);
}
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
*/
@Post("search-personal")
async getProfileBySearchKeyword(
2024-06-13 17:38:01 +07:00
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Body()
body: {
fieldName: string;
2024-02-16 12:16:47 +07:00
keyword?: string;
},
) {
2024-02-28 14:47:28 +07:00
let findProfile: any;
2024-06-13 17:38:01 +07:00
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
2024-02-28 14:47:28 +07:00
switch (body.fieldName) {
2024-06-13 17:38:01 +07:00
case "citizenId":
2024-06-14 10:49:53 +07:00
[findProfile, total] = await this.profileRepo.findAndCount({
2024-02-28 14:47:28 +07:00
where: { citizenId: Like(`%${body.keyword}%`) },
relations: [
"posType",
"posLevel",
"current_holders",
"profileSalary",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
2024-06-13 17:38:01 +07:00
skip,
take,
2024-02-28 14:47:28 +07:00
});
break;
2024-02-28 14:47:28 +07:00
case "firstname":
2024-06-14 10:49:53 +07:00
[findProfile, total] = await this.profileRepo.findAndCount({
2024-02-28 14:47:28 +07:00
where: { firstName: Like(`%${body.keyword}%`) },
relations: [
"posType",
"posLevel",
"current_holders",
"profileSalary",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
2024-06-13 17:38:01 +07:00
skip,
take,
2024-02-28 14:47:28 +07:00
});
break;
2024-02-28 14:47:28 +07:00
case "lastname":
2024-06-14 10:49:53 +07:00
[findProfile, total] = await this.profileRepo.findAndCount({
2024-02-28 14:47:28 +07:00
where: { lastName: Like(`%${body.keyword}%`) },
relations: [
"posType",
"posLevel",
"current_holders",
"profileSalary",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
2024-06-13 17:38:01 +07:00
skip,
take,
2024-02-28 14:47:28 +07:00
});
break;
2024-02-28 14:47:28 +07:00
default:
2024-06-14 10:49:53 +07:00
[findProfile, total] = await this.profileRepo.findAndCount({
relations: [
"posType",
"posLevel",
"current_holders",
"profileSalary",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
2024-06-13 17:38:01 +07:00
skip,
take,
2024-02-28 14:47:28 +07:00
});
break;
}
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
2024-02-28 14:47:28 +07:00
const mapDataProfile = await Promise.all(
findProfile.map(async (item: Profile) => {
const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
item.current_holders.length == 0 ||
(item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
let salary: any = "";
if (item != null && item.profileSalary != null && item.profileSalary.length > 0) {
let _salary: any = item.profileSalary.sort(
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) - (a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
}
}
const rootHolder = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgRoot;
const child1Holder = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgChild1;
const child2Holder = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgChild2;
const child3Holder = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgChild3;
const child4Holder = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgChild4;
2024-05-28 13:35:01 +07:00
const posMasterNo = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
2024-06-12 17:50:48 +07:00
const latestProfileEducation = await this.profileEducationRepository.findOne({
where: { profileId: item.id },
2024-06-13 11:59:09 +07:00
order: { endDate: "DESC" },
2024-06-12 17:50:48 +07:00
});
2024-02-28 14:47:28 +07:00
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
2024-02-28 14:47:28 +07:00
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
2024-06-13 17:38:01 +07:00
citizenId: item.citizenId,
2024-02-28 14:47:28 +07:00
email: item.email,
phone: item.phone,
name: fullName,
2024-06-12 17:50:48 +07:00
birthDate: item.birthDate,
positionLevel: item.posLevelId,
positionLevelName: item.posLevel?.posLevelName,
positionType: item.posTypeId,
positionTypeName: item.posType?.posTypeName,
posNo: shortName,
organization: root == null ? null : root.orgRootShortName,
salary: salary == "" ? "" : salary.amount,
root: rootHolder?.orgRootName ?? null,
rootId: rootHolder?.id ?? null,
rootShortName: rootHolder?.orgRootShortName ?? null,
child1: child1Holder?.orgChild1Name ?? null,
child1Id: child1Holder?.id ?? null,
child1ShortName: child1Holder?.orgChild1ShortName ?? null,
child2: child2Holder?.orgChild2Name ?? null,
child2Id: child2Holder?.id ?? null,
child2ShortName: child2Holder?.orgChild2ShortName ?? null,
child3: child3Holder?.orgChild3Name ?? null,
child3Id: child3Holder?.id ?? null,
child3ShortName: child3Holder?.orgChild3ShortName ?? null,
child4: child4Holder?.orgChild4Name ?? null,
child4Id: child4Holder?.id ?? null,
2024-06-12 14:17:55 +07:00
child4ShortName: child4Holder?.orgChild4ShortName ?? null,
2024-05-28 15:01:15 +07:00
posMasterNo: posMasterNo ?? null,
posTypeId: item.posTypeId,
posTypeName: item.posType?.posTypeName,
posLevelId: item.posLevelId,
posLevelName: item.posLevel?.posLevelName,
educationDegree:
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
2024-06-13 11:59:09 +07:00
// ? {
// id: latestProfileEducation.id,
// degree: latestProfileEducation.degree,
// country: latestProfileEducation.country,
// duration: latestProfileEducation.duration,
// durationYear: latestProfileEducation.durationYear,
// field: latestProfileEducation.field,
// finishDate: latestProfileEducation.finishDate,
// fundName: latestProfileEducation.fundName,
// gpa: latestProfileEducation.gpa,
// institute: latestProfileEducation.institute,
// other: latestProfileEducation.other,
// startDate: latestProfileEducation.startDate,
// endDate: latestProfileEducation.endDate,
// educationLevel: latestProfileEducation.educationLevel,
// positionPath: latestProfileEducation.positionPath,
// positionPathId: latestProfileEducation.positionPathId,
// isDate: latestProfileEducation.isDate,
// isEducation: latestProfileEducation.isEducation,
// note: latestProfileEducation.note,
// }
// : null,
2024-02-28 14:47:28 +07:00
};
}),
);
2024-06-13 17:38:01 +07:00
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
* API
*
* @summary ORG_069 - (ADMIN) #75
*
*/
@Get("search/commander")
async searchCommander(@Request() request: { user: Record<string, any> }) {
let fullName_: any = {};
let position_: any = {};
let commanderAboveFullname_: any = {};
let commanderAbovePosition_: any = {};
let commanderFullname_: any = {};
let commanderPosition_: any = {};
const findProfile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
});
const findRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsCurrent: true,
},
});
const findPosMaster = await this.posMasterRepo.findOne({
where: {
current_holderId: findProfile?.id,
orgRevisionId: findRevision?.id,
},
});
let node = 4;
let childId = findPosMaster?.orgChild4Id;
let condition: any = { orgChild4Id: childId };
if (findPosMaster?.orgChild4Id == null && findPosMaster?.orgChild3Id != null) {
node = 3;
childId = findPosMaster?.orgChild3Id;
condition = { orgChild3Id: childId, orgChild4Id: IsNull() };
} else if (findPosMaster?.orgChild3Id == null && findPosMaster?.orgChild2Id != null) {
node = 2;
childId = findPosMaster?.orgChild2Id;
condition = { orgChild2Id: childId, orgChild3Id: IsNull() };
} else if (findPosMaster?.orgChild2Id == null && findPosMaster?.orgChild1Id != null) {
node = 1;
childId = findPosMaster?.orgChild1Id;
condition = { orgChild1Id: childId, orgChild2Id: IsNull() };
} else if (findPosMaster?.orgChild1Id == null) {
node = 0;
childId = findPosMaster?.orgRootId;
condition = { orgRootId: childId, orgChild1Id: IsNull() };
}
const findCmd = await this.posMasterRepo.findOne({
where: {
current_holderId: Not(IsNull()) || Not(""),
orgRevisionId: findRevision?.id,
...condition,
},
relations: ["current_holder"],
order: { posMasterOrder: "ASC" },
});
let findOSAB: PosMaster | null = null;
let findTSAB: PosMaster | null = null;
//หาผู้บังคับบัญชาที่เหนือขึ้นไปอีก 1 ขั้น
if (node !== 0) {
findOSAB = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.where("posMaster.current_holderId IS NOT NULL")
.andWhere("posMaster.orgRevisionId = :revisionId", { revisionId: findRevision?.id })
.andWhere(
new Brackets((qb) => {
if (node === 4) {
qb.andWhere("posMaster.orgChild4Id IS NULL");
qb.andWhere("posMaster.orgChild3Id = :childId", {
childId: findPosMaster?.orgChild3Id,
});
} else if (node === 3) {
qb.andWhere("posMaster.orgChild3Id IS NULL");
qb.andWhere("posMaster.orgChild2Id = :childId", {
childId: findPosMaster?.orgChild2Id,
});
} else if (node === 2) {
qb.andWhere("posMaster.orgChild2Id IS NULL");
qb.andWhere("posMaster.orgChild1Id = :childId", {
childId: findPosMaster?.orgChild1Id,
});
} else if (node === 1) {
qb.andWhere("posMaster.orgChild1Id IS NULL");
qb.andWhere("posMaster.orgRootId = :childId", { childId: findPosMaster?.orgRootId });
}
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.getOne();
}
//หาผู้บังคับบัญชาที่เหนือขึ้นไปอีก 2 ขั้น
if (node !== 0 && node !== 1) {
findTSAB = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.where("posMaster.current_holderId IS NOT NULL")
.andWhere("posMaster.orgRevisionId = :revisionId", { revisionId: findRevision?.id })
.andWhere(
new Brackets((qb) => {
if (node === 4) {
qb.andWhere("posMaster.orgChild3Id IS NULL");
qb.andWhere("posMaster.orgChild2Id = :childId", {
childId: findPosMaster?.orgChild2Id,
});
} else if (node === 3) {
qb.andWhere("posMaster.orgChild2Id IS NULL");
qb.andWhere("posMaster.orgChild1Id = :childId", {
childId: findPosMaster?.orgChild1Id,
});
} else if (node === 2) {
qb.andWhere("posMaster.orgChild1Id IS NULL");
qb.andWhere("posMaster.orgRootId = :childId", {
childId: findPosMaster?.orgRootId,
});
}
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.getOne();
}
2024-02-21 13:53:02 +07:00
fullName_ =
(findProfile?.prefix ?? "") +
(findProfile?.firstName ?? "") +
" " +
(findProfile?.lastName ?? "");
position_ = findProfile?.position ?? "";
2024-02-21 13:53:02 +07:00
commanderFullname_ =
(findCmd?.current_holder?.prefix ?? "") +
(findCmd?.current_holder?.firstName ?? "") +
" " +
(findCmd?.current_holder?.lastName ?? "");
commanderPosition_ = findCmd?.current_holder?.position ?? "";
2024-02-21 13:53:02 +07:00
commanderAboveFullname_ =
(findOSAB?.current_holder?.prefix ?? "") +
(findOSAB?.current_holder?.firstName ?? "") +
" " +
(findOSAB?.current_holder?.lastName ?? "");
commanderAbovePosition_ = findOSAB?.current_holder?.position ?? "";
if (findCmd?.current_holderId == findProfile?.id) {
2024-02-21 13:53:02 +07:00
commanderFullname_ =
(findOSAB?.current_holder?.prefix ?? "") +
(findOSAB?.current_holder?.firstName ?? "") +
" " +
(findOSAB?.current_holder?.lastName ?? "");
commanderPosition_ = findOSAB?.current_holder?.position ?? "";
2024-02-21 13:53:02 +07:00
commanderAboveFullname_ =
(findTSAB?.current_holder?.prefix ?? "") +
(findTSAB?.current_holder?.firstName ?? "") +
" " +
(findTSAB?.current_holder?.lastName ?? "");
commanderAbovePosition_ = findTSAB?.current_holder?.position ?? "";
const formattedDataTSAB = {
fullname: fullName_,
position: position_,
commanderAboveFullname: commanderAboveFullname_,
commanderAbovePosition: commanderAbovePosition_,
commanderFullname: commanderFullname_,
commanderPosition: commanderPosition_,
};
return new HttpSuccess(formattedDataTSAB);
}
const formattedData = {
fullname: fullName_,
position: position_,
commanderAboveFullname: commanderAboveFullname_,
commanderAbovePosition: commanderAbovePosition_,
commanderFullname: commanderFullname_,
commanderPosition: commanderPosition_,
};
return new HttpSuccess(formattedData);
}
2024-02-21 13:53:02 +07:00
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id Id
*/
@Put("citizenId/{id}")
async checkCitizenIdProfile(
@Path() id: string,
@Body()
requestBody: { citizenId: string },
) {
const profile = await this.profileRepo.findOne({
2024-02-21 13:53:02 +07:00
where: { id: Not(id), citizenId: requestBody.citizenId },
});
if (profile) {
throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR,
"เลขประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว",
);
2024-02-21 13:53:02 +07:00
}
2024-02-28 14:47:28 +07:00
return new HttpSuccess();
2024-02-21 13:53:02 +07:00
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("probation")
async getProfileBySearchKeywordProbation(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
},
) {
2024-06-25 10:21:30 +07:00
const isProbation: boolean = true;
2024-02-28 14:47:28 +07:00
const [findProfile, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
2024-02-28 14:47:28 +07:00
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
2024-06-25 10:21:30 +07:00
.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}%`,
})
2024-02-28 14:47:28 +07:00
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
const orgRevisionActive = await this.orgRevisionRepo.findOne({
2024-02-28 14:47:28 +07:00
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
2024-06-29 21:06:01 +07:00
});
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const mapDataProfile = await Promise.all(
findProfile.map(async (item: Profile) => {
const posMaster =
item.current_holders == null ||
item.current_holders.length == 0 ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
const position =
posMaster == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions == null ||
item.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true);
const posExecutive =
position == null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
idcard: item.citizenId,
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
posTypeName: item.posType == null ? null : item.posType.posTypeName,
posNo: `${posMaster == null ? null : posMaster.posMasterNo}${shortName}`,
positionField: position == null ? null : position.positionField,
positionArea: position == null ? null : position.positionArea,
posExecutiveName: posExecutive,
positionExecutiveField: position == null ? null : position.positionExecutiveField,
isProbation: item.isProbation,
orgRootName:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.orgRootName == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.orgRootName,
orgChild1Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1
?.orgChild1Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild1?.orgChild1Name,
orgChild2Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2
?.orgChild2Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2?.orgChild2Name,
orgChild3Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3
?.orgChild3Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3?.orgChild3Name,
orgChild4Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4
?.orgChild4Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4?.orgChild4Name,
};
}),
);
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("retire")
async getProfileBySearchKeywordRetire(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
},
) {
const [findProfile, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.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}%`,
})
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
2024-02-28 14:47:28 +07:00
.take(body.pageSize)
.getManyAndCount();
const orgRevisionActive = await this.orgRevisionRepo.findOne({
2024-02-28 14:47:28 +07:00
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
2024-02-28 14:47:28 +07:00
const mapDataProfile = await Promise.all(
findProfile.map(async (item: Profile) => {
const posMaster =
item.current_holders == null ||
item.current_holders.length == 0 ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
const position =
posMaster == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions == null ||
item.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true);
const posExecutive =
position == null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
2024-02-28 14:47:28 +07:00
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
2024-02-28 14:47:28 +07:00
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
idcard: item.citizenId,
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
posTypeName: item.posType == null ? null : item.posType.posTypeName,
posNo: `${posMaster == null ? null : posMaster.posMasterNo}${shortName}`,
positionField: position == null ? null : position.positionField,
positionArea: position == null ? null : position.positionArea,
posExecutiveName: posExecutive,
positionExecutiveField: position == null ? null : position.positionExecutiveField,
2024-02-28 14:47:28 +07:00
isProbation: item.isProbation,
orgRootName:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.orgRootName == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.orgRootName,
orgChild1Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1
?.orgChild1Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild1?.orgChild1Name,
orgChild2Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2
?.orgChild2Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2?.orgChild2Name,
orgChild3Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3
?.orgChild3Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3?.orgChild3Name,
orgChild4Name:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4
?.orgChild4Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4?.orgChild4Name,
};
}),
);
2024-02-28 14:47:28 +07:00
return new HttpSuccess({ data: mapDataProfile, total });
}
2024-02-27 17:20:48 +07:00
/**
* API
*
* @summary ORG_072 - #76
*
*/
2024-02-28 13:38:08 +07:00
@Post("salary/gen")
async salaryGen(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
2024-03-06 18:28:22 +07:00
rootId?: string;
year: number;
period: string;
2024-02-28 13:38:08 +07:00
},
) {
const findRevision = await this.orgRevisionRepo.findOne({
2024-02-27 17:20:48 +07:00
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
2024-02-27 17:20:48 +07:00
}
2024-02-28 14:47:28 +07:00
2024-02-28 14:12:59 +07:00
const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster)
2024-02-27 17:20:48 +07:00
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
2024-05-14 17:24:38 +07:00
.leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines")
2024-02-28 13:38:08 +07:00
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.leftJoinAndSelect("current_holder.posType", "posType")
2024-03-07 11:00:22 +07:00
.where((qb) => {
if (body.rootId) {
qb.andWhere("posMaster.orgRootId = :rootId", { rootId: body.rootId });
}
qb.andWhere("posMaster.current_holderId IS NOT NULL");
qb.andWhere("posMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
2024-02-27 17:20:48 +07:00
})
2024-02-28 13:38:08 +07:00
.andWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "current_holder.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
2024-02-28 14:47:28 +07:00
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
2024-02-28 13:38:08 +07:00
}),
)
.orderBy("current_holder.citizenId", "ASC")
2024-02-28 14:12:59 +07:00
.skip((body.page - 1) * body.pageSize)
2024-02-28 13:38:08 +07:00
.take(body.pageSize)
2024-02-28 14:12:59 +07:00
.getManyAndCount();
2024-02-27 17:20:48 +07:00
if (!findPosMaster) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. PosMaster");
2024-02-27 17:20:48 +07:00
}
2024-02-28 14:47:28 +07:00
2024-02-27 17:20:48 +07:00
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
if (item.orgChild1Id === null) {
orgShortName = item.orgRoot?.orgRootShortName;
} else if (item.orgChild2Id === null) {
orgShortName = item.orgChild1?.orgChild1ShortName;
} else if (item.orgChild3Id === null) {
orgShortName = item.orgChild2?.orgChild2ShortName;
} else if (item.orgChild4Id === null) {
orgShortName = item.orgChild3?.orgChild3ShortName;
} else {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const posExecutive =
item.positions == null ||
item.positions?.find((position) => position.positionIsSelected == true) == null ||
item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
2024-02-27 17:20:48 +07:00
? null
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
2024-02-27 17:20:48 +07:00
.posExecutiveName;
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
let datePeriodEnd = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
if (body.period.toLocaleUpperCase() == "APR") {
datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`);
}
if (body.period.toLocaleUpperCase() == "OCT") {
datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`);
}
datePeriodStart = new Date(
new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth(
datePeriodStart.getMonth() - 6,
),
);
2024-05-28 14:17:45 +07:00
const specialPosition = item.positions.find(
(position) => position.positionIsSelected === true,
);
const isSpecial = specialPosition ? specialPosition.isSpecial : null;
2024-02-27 17:20:48 +07:00
return {
2024-05-28 14:17:45 +07:00
profileId: item.current_holder.id,
2024-02-27 17:20:48 +07:00
prefix: item.current_holder.prefix,
rank: item.current_holder.rank,
2024-02-27 17:20:48 +07:00
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
citizenId: item.current_holder.citizenId,
posMasterNoPrefix: item.posMasterNoPrefix,
posMasterNo: item.posMasterNo,
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.current_holder.position,
2024-03-19 11:30:49 +07:00
posType:
item.current_holder.posType == null ? null : item.current_holder.posType.posTypeName,
posLevel:
item.current_holder.posLevel == null ? null : item.current_holder.posLevel.posLevelName,
2024-02-27 17:20:48 +07:00
posExecutive: posExecutive,
amount: amount ? amount : null,
2024-02-28 13:38:08 +07:00
// revisionId: item.orgRevisionId,
2024-02-27 17:20:48 +07:00
rootId: item.orgRootId,
2024-02-28 14:47:28 +07:00
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
2024-02-27 17:20:48 +07:00
child1Id: item.orgChild1Id,
2024-02-28 14:47:28 +07:00
child1: item.orgChild1?.orgChild1Name ? item.orgChild1.orgChild1Name : null,
2024-02-27 17:20:48 +07:00
child2Id: item.orgChild2Id,
2024-02-28 14:47:28 +07:00
child2: item.orgChild2?.orgChild2Name ? item.orgChild2.orgChild2Name : null,
2024-02-27 17:20:48 +07:00
child3Id: item.orgChild3Id,
2024-02-28 14:47:28 +07:00
child3: item.orgChild3?.orgChild3Name ? item.orgChild3.orgChild3Name : null,
2024-02-27 17:20:48 +07:00
child4Id: item.orgChild4Id,
2024-02-28 14:47:28 +07:00
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
2024-02-28 18:11:56 +07:00
result: null,
duration: null,
isPunish:
2024-05-14 17:24:38 +07:00
item.current_holder.profileDisciplines.filter(
(x: any) =>
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) >= datePeriodStart &&
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) <= datePeriodEnd,
).length > 0
? true
: false,
isSuspension: item.current_holder.dateRetire == null ? false : true,
isAbsent: false,
isLeave: false,
isRetired:
item.current_holder.birthDate == null ||
calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year
? false
: true,
2024-05-28 15:22:14 +07:00
isSpecial: isSpecial,
2024-02-27 17:20:48 +07:00
};
});
2024-02-28 14:47:28 +07:00
return new HttpSuccess({ data: formattedData, total: total });
2024-02-27 17:20:48 +07:00
}
/**
* API keycloak by revisionId
*
* @summary keycloak by revisionId (ADMIN)
*
*/
@Get("keycloak/position/{revisionId}")
async getProfileByKeycloakByRevision(
@Path() revisionId: string,
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
const posMaster = await this.posMasterRepo.findOne({
where: {
current_holderId: profile.id,
2024-05-14 17:24:38 +07:00
orgRevisionId: revisionId,
},
});
2024-05-14 17:24:38 +07:00
const position = await this.positionRepository.findOne({
relations: ["posExecutive"],
2024-05-14 17:24:38 +07:00
where: {
posMasterId: posMaster?.id,
},
});
const _profile = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
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,
2024-05-14 17:24:38 +07:00
posExecutiveName:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName,
posExecutivePriority:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutivePriority,
posExecutiveId:
position == null || position.posExecutive == null ? null : position.posExecutive.id,
rootId:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRootId,
root:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot.orgRootName,
child1Id:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1Id,
child1:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1
.orgChild1Name,
child2Id:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2Id,
child2:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2
.orgChild2Name,
child3Id:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3Id,
child3:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3
.orgChild3Name,
child4Id:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4Id,
child4:
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||
profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4
.orgChild4Name,
};
2024-02-28 14:47:28 +07:00
return new HttpSuccess(_profile);
}
2024-05-29 15:38:56 +07:00
/**
* API
*
* @summary
*
*/
@Get("profileid/retire/{year}")
async getProfileByRetireYear(@Path() year: number) {
const profiles = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where("YEAR(profile.dateRetire) = :year", { year })
.getMany();
if (!profiles || profiles.length === 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลที่มีอายุเกษียณราชการในปีนี้");
}
// const orgRevisionActive = await this.orgRevisionRepo.findOne({
// where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
// });
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const formattedData = profiles.map((item) => {
const posMaster =
item.current_holders == null ||
item.current_holders.length == 0 ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
const position =
posMaster == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions == null ||
item.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true);
const posExecutive =
position == null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: item.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const posExecutiveId =
position == null || position.posExecutive == null ? null : position.posExecutive.id;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
const child1 =
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1 == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 =
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2 == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 =
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
const child4 =
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let node = null;
let nodeId = null;
let nodeShortName = null;
if (root) {
node = 0;
nodeId = root.id;
nodeShortName = root.orgRootShortName;
}
if (child1) {
node = 1;
nodeId = child1.id;
nodeShortName = child1.orgChild1ShortName;
}
if (child2) {
node = 2;
nodeId = child2.id;
nodeShortName = child2.orgChild2ShortName;
}
if (child3) {
node = 3;
nodeId = child3.id;
nodeShortName = child3.orgChild3ShortName;
}
if (child4) {
node = 4;
nodeId = child4.id;
nodeShortName = child4.orgChild4ShortName;
}
return {
profileId: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
root: root == null ? null : root.orgRootName,
rootId: root == null ? null : root.id,
rootShortName: root == null ? null : root.orgRootShortName,
child1: child1 == null ? null : child1.orgChild1Name,
child1Id: child1 == null ? null : child1.id,
child1ShortName: child1 == null ? null : child1.orgChild1ShortName,
child2: child2 == null ? null : child2.orgChild2Name,
child2Id: child2 == null ? null : child2.id,
child2ShortName: child2 == null ? null : child2.orgChild2ShortName,
child3: child3 == null ? null : child3.orgChild3Name,
child3Id: child3 == null ? null : child3.id,
child3ShortName: child3 == null ? null : child3.orgChild3ShortName,
child4: child4 == null ? null : child4.orgChild4Name,
child4Id: child4 == null ? null : child4.id,
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
dateRetire: item.dateRetire,
posLevelId: item.posLevel == null ? null : item.posLevel.id,
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
posLevelRank: item.posLevel == null ? null : item.posLevel.posLevelRank,
posTypeId: item.posType == null ? null : item.posType.id,
posTypeName: item.posType == null ? null : item.posType.posTypeName,
posTypeRank: item.posType == null ? null : item.posType.posTypeRank,
2024-05-30 16:05:00 +07:00
posNo: shortName,
2024-05-29 15:38:56 +07:00
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
position: item.position,
posExecutiveId: posExecutiveId,
posExecutiveName: posExecutive,
node: node,
nodeId: nodeId,
nodeShortName: nodeShortName,
};
});
return new HttpSuccess(formattedData);
}
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id Id
*/
2024-06-07 03:05:57 +07:00
@Post("leave/{id}")
async updateLeaveUser(
@Path() id: string,
@Body()
2024-06-24 10:52:40 +07:00
requestBody: { isLeave: boolean; leaveReason?: any; dateLeave?: any },
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepo.findOne({
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
2024-06-24 10:52:40 +07:00
const _null: any = null;
profile.isLeave = requestBody.isLeave;
2024-06-25 10:21:30 +07:00
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
2024-06-24 10:52:40 +07:00
profile.leaveReason = requestBody.leaveReason;
} else {
profile.leaveReason = _null;
}
2024-06-25 10:21:30 +07:00
if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) {
2024-06-24 10:52:40 +07:00
profile.dateLeave = requestBody.dateLeave;
} else {
profile.dateLeave = _null;
}
await this.profileRepo.save(profile);
const profileSalary = await this.salaryRepository.findOne({
where: { profileId: id },
order: { createdAt: "DESC" },
});
await new CallAPI().PostData(request, "org/profile/salary", {
profileId: profile.id,
date: requestBody.dateLeave,
2024-06-18 17:42:47 +07:00
amount: profileSalary?.amount ?? null,
positionSalaryAmount: profileSalary?.positionSalaryAmount ?? null,
2024-06-19 23:03:54 +07:00
mouthSalaryAmount: profileSalary?.mouthSalaryAmount ?? null,
2024-06-18 17:42:47 +07:00
posNo: profileSalary?.posNo ?? null,
position: profileSalary?.position ?? null,
positionLine: profileSalary?.positionLine ?? null,
positionPathSide: profileSalary?.positionPathSide ?? null,
positionExecutive: profileSalary?.positionExecutive ?? null,
positionType: profileSalary?.positionType ?? null,
positionLevel: profileSalary?.positionLevel ?? null,
refCommandNo: null,
templateDoc: requestBody.leaveReason,
});
return new HttpSuccess();
}
/**
* API keycloak
*
* @summary keycloak
*
*/
@Post("search-personal-no-keycloak")
async getProfileBySearchKeywordNoKeyCloak(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Body()
body: {
fieldName: string;
keyword?: string;
},
) {
let findProfile: any;
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
switch (body.fieldName) {
2024-06-13 15:16:16 +07:00
case "citizenId":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
2024-06-13 16:15:56 +07:00
keycloak: IsNull(),
citizenId: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalary"],
skip,
take,
});
break;
case "firstname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
firstName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalary"],
skip,
take,
});
break;
case "lastname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
lastName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalary"],
skip,
take,
});
break;
default:
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
},
relations: ["posType", "posLevel", "current_holders", "profileSalary"],
skip,
take,
});
break;
}
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const mapDataProfile = await Promise.all(
findProfile.map(async (item: Profile) => {
const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
item.current_holders.length == 0 ||
(item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
let salary: any = "";
if (item != null && item.profileSalary != null && item.profileSalary.length > 0) {
let _salary: any = item.profileSalary.sort(
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) - (a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
}
}
const posMasterNo = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
where: { profileId: item.id },
order: { endDate: "DESC" },
});
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
2024-06-13 15:16:16 +07:00
citizenId: item.citizenId,
email: item.email,
phone: item.phone,
name: fullName,
birthDate: item.birthDate,
positionLevel: item.posLevelId,
positionLevelName: item.posLevel?.posLevelName,
positionType: item.posTypeId,
positionTypeName: item.posType?.posTypeName,
posNo: shortName,
organization: root == null ? null : root.orgRootShortName,
salary: salary == "" ? "" : salary.amount,
posMasterNo: posMasterNo ?? null,
posTypeId: item.posTypeId,
posTypeName: item.posType?.posTypeName,
posLevelId: item.posLevelId,
posLevelName: item.posLevel?.posLevelName,
educationDegree:
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
};
}),
);
2024-06-13 16:15:56 +07:00
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
*
* @summary (ADMIN)
*
*/
@Get("probation/{id}")
async getProbationProfile(@Path() id: string) {
const profile = await this.profileRepo.findOne({
where: { id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
profile.isProbation = true;
await this.profileRepo.save(profile);
return new HttpSuccess(profile);
}
2024-06-21 18:06:23 +07:00
2024-06-24 10:52:40 +07:00
/**
2024-06-21 18:06:23 +07:00
* API
*
* @summary ORG_065 - (ADMIN) #XXX
*
*/
@Post("all/dump-db")
async createProfileAllDump(
@Request() request: RequestWithUser,
@Body() body: CreateProfileAllFields,
) {
2024-06-24 10:52:40 +07:00
const citizen = await this.profileRepo.findOne({
where: { citizenId: body.citizenId },
select: ["id"],
});
if (citizen) return new HttpSuccess(citizen.id);
2024-06-25 10:21:30 +07:00
const _null: any = null;
2024-06-21 18:06:23 +07:00
const profile: Profile = Object.assign(new Profile(), body);
if (body && body.posLevelId) {
const findPosLevel = await this.posLevelRepo.findOne({
where: { posLevelName: body.posLevelId },
2024-06-24 10:52:40 +07:00
select: ["id", "posLevelName"],
2024-06-21 18:06:23 +07:00
});
if (findPosLevel) {
profile.posLevelId = findPosLevel.id;
2024-06-25 10:21:30 +07:00
} else {
profile.posLevelId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.posLevelId = _null;
2024-06-21 18:06:23 +07:00
}
if (body && body.posTypeId) {
const findPosType = await this.posTypeRepo.findOne({
where: { posTypeName: body.posTypeId },
2024-06-24 10:52:40 +07:00
select: ["id", "posTypeName"],
2024-06-21 18:06:23 +07:00
});
if (findPosType) {
profile.posTypeId = findPosType.id;
2024-06-25 10:21:30 +07:00
} else {
profile.posTypeId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.posTypeId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
// 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;
// }
2024-06-21 18:06:23 +07:00
//current
if (body && body.currentProvinceId) {
const findProvince = await this.provinceRepo.findOne({
where: { name: body.currentProvinceId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
2024-06-24 10:52:40 +07:00
if (findProvince) {
profile.currentProvinceId = findProvince.id;
2024-06-25 10:21:30 +07:00
} else {
profile.currentProvinceId = _null;
2024-06-24 10:52:40 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.currentProvinceId = _null;
2024-06-21 18:06:23 +07:00
}
if (body && body.currentDistrictId) {
const findDistrict = await this.districtRepo.findOne({
where: { name: body.currentDistrictId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
2024-06-24 10:52:40 +07:00
if (findDistrict) {
profile.currentDistrictId = findDistrict.id;
2024-06-25 10:21:30 +07:00
} else {
profile.currentDistrictId = _null;
2024-06-24 10:52:40 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.currentDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
if (body && body.currentSubDistrictId) {
const findSubDistrict = await this.subDistrictRepo.findOne({
where: { name: body.currentSubDistrictId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
if (findSubDistrict) {
profile.currentSubDistrictId = findSubDistrict.id;
2024-06-25 10:21:30 +07:00
} else {
profile.currentSubDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.currentSubDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
//register
if (body && body.registrationProvinceId) {
const findProvince_regis = await this.provinceRepo.findOne({
where: { name: body.registrationProvinceId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
if (findProvince_regis) {
profile.registrationProvinceId = findProvince_regis.id;
2024-06-25 10:21:30 +07:00
} else {
profile.registrationProvinceId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.registrationProvinceId = _null;
2024-06-21 18:06:23 +07:00
}
if (body && body.registrationDistrictId) {
const findDistrict_regis = await this.districtRepo.findOne({
where: { name: body.registrationDistrictId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
if (findDistrict_regis) {
profile.registrationDistrictId = findDistrict_regis.id;
2024-06-25 10:21:30 +07:00
} else {
profile.registrationDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.registrationDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
if (body && body.registrationSubDistrictId) {
const findSubDistrict_regis = await this.subDistrictRepo.findOne({
where: { name: body.registrationSubDistrictId },
2024-06-24 10:52:40 +07:00
select: ["id", "name"],
2024-06-21 18:06:23 +07:00
});
2024-06-24 10:52:40 +07:00
if (findSubDistrict_regis) {
profile.registrationSubDistrictId = findSubDistrict_regis.id;
2024-06-25 10:21:30 +07:00
} else {
profile.registrationSubDistrictId = _null;
2024-06-24 10:52:40 +07:00
}
2024-06-25 10:21:30 +07:00
} else {
profile.registrationSubDistrictId = _null;
2024-06-21 18:06:23 +07:00
}
2024-06-24 10:52:40 +07:00
2024-06-21 18:06:23 +07:00
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
2024-06-25 10:21:30 +07:00
// return new HttpSuccess(profile);
2024-06-21 18:06:23 +07:00
await this.profileRepo.save(profile);
return new HttpSuccess(profile.id);
}
2024-06-25 10:21:30 +07:00
/**
*
* @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");
}
2024-06-27 14:28:23 +07:00
/**
*
* @summary (ADMIN)
*
*/
@Get("salarym/zxczxcsa")
async zxczxczxczxczxc() {
const [profile, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("profile.next_holders", "next_holders")
.skip(1)
.take(50)
.getManyAndCount();
2024-06-27 14:28:23 +07:00
const profiles = await Promise.all(
profile.map(async (_data) => {
if (_data.current_holders.length == 0 && _data.next_holders.length == 0) {
const salary = await this.salaryRepository.find({
where: {
profileId: _data.id,
},
});
const insignia = await this.profileInsigniaRepo.find({
where: {
profileId: _data.id,
},
});
const discipline = await this.profileDisciplineRepo.find({
where: {
profileId: _data.id,
},
});
await this.salaryRepository.remove(salary);
await this.profileInsigniaRepo.remove(insignia);
await this.profileDisciplineRepo.remove(discipline);
await this.profileRepo.remove(_data);
}
}),
);
return new HttpSuccess("zxczx");
}
2024-02-08 10:56:03 +07:00
}