Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-01-30 15:18:28 +07:00
commit 024549ef3e
92 changed files with 4156 additions and 503 deletions

View file

@ -18,7 +18,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { Brackets, IsNull, Not } from "typeorm";
import { Brackets, In, IsNull, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@ -26,6 +26,7 @@ import { Position } from "../entities/Position";
import { Insignia } from "../entities/Insignia";
import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia";
import { PosMaster } from "../entities/PosMaster";
import { EmployeePosDict } from "../entities/EmployeePosDict";
@Route("api/v1/org/dotnet")
@Tags("Dotnet")
@ -43,6 +44,7 @@ export class OrganizationDotnetController extends Controller {
private positionRepository = AppDataSource.getRepository(Position);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
/**
* 1. API Search Profile
@ -294,6 +296,9 @@ export class OrganizationDotnetController extends Controller {
},
},
});
let fullname = "";
let commanderId = "";
let commanderKeycloak = "";
if (!profile) {
const profile = await this.profileEmpRepo.findOne({
@ -354,7 +359,6 @@ export class OrganizationDotnetController extends Controller {
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
@ -377,6 +381,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -399,6 +405,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -421,6 +429,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -443,6 +453,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -465,8 +477,12 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
fullname = "";
commanderId = "";
commanderKeycloak = "";
}
}
}
@ -579,6 +595,8 @@ export class OrganizationDotnetController extends Controller {
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
commanderId,
commanderKeycloak,
posLevel: profile.posLevel?.posLevelName ?? null,
posType: profile.posType?.posTypeName ?? null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
@ -622,7 +640,6 @@ export class OrganizationDotnetController extends Controller {
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
@ -646,6 +663,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -669,6 +688,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -692,6 +713,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -715,6 +738,8 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
@ -738,8 +763,12 @@ export class OrganizationDotnetController extends Controller {
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
commanderId = pos.current_holder.id;
commanderKeycloak = pos.current_holder.keycloak;
} else {
fullname = "";
commanderId = "";
commanderKeycloak = "";
}
}
}
@ -852,13 +881,14 @@ export class OrganizationDotnetController extends Controller {
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
commanderId,
commanderKeycloak,
posLevel: profile.posLevel?.posLevelName ?? null,
posType: profile.posType?.posTypeName ?? null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
profileType: "OFFICER",
};
console.log("11111111111111131");
return new HttpSuccess(mapProfile);
}
@ -2325,6 +2355,158 @@ export class OrganizationDotnetController extends Controller {
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} keycloakId Id keycloak
*/
@Post("find/employee/position")
async GetProfileByPositionEmpAsync(
@Request() req: RequestWithUser,
@Body()
body: {
empPosId: string[];
rootId: string;
},
) {
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const employeePosDict = await this.employeePosDictRepository.find({
where: { id: In(body.empPosId) },
});
const profiles = await this.profileEmpRepo.find({
relations: [
"posLevel",
"posType",
"profileSalary",
"profileInsignias",
"profileInsignias.insignia",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: employeePosDict.map((entry) => ({
posLevelId: entry.posLevelId,
posTypeId: entry.posTypeId,
position: entry.posDictName,
current_holders: { orgRootId: body.rootId },
})),
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
const mapProfile = profiles.map((profile) => {
const shortName =
profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
null
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: null;
return {
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank ?? "",
prefix: profile.prefix ?? "",
firstName: profile.firstName ?? "",
lastName: profile.lastName ?? "",
citizenId: profile.citizenId ?? "",
position: profile.position ?? "",
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender ?? "",
relationship: profile.relationship ?? "",
religion: profile.religion ?? "",
bloodGroup: profile.bloodGroup ?? "",
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
// dutyTimeId: profile.dutyTimeId,
// dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
posLevel: profile.posLevel?.posLevelName ?? "",
posType: profile.posType?.posTypeName ?? "",
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias.map((x) => {
return { ...x, insignia: x.insignia.name };
}),
amount: profile.amount,
positionSalaryAmount: profile.positionSalaryAmount,
mouthSalaryAmount: profile.mouthSalaryAmount,
profileType: "EMPLOYEE",
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.orgRootName ?? null,
rootId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRootId ?? null,
posNo: shortName ?? "",
};
});
return new HttpSuccess(mapProfile);
}
/**
* 7.1 Get GetUserFullName
*