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

File diff suppressed because it is too large Load diff

View file

@ -144,9 +144,9 @@ export class InsigniaTypeController extends Controller {
@Get("active")
async GetInsigniaType_Active() {
const insigniaType_Active = await this.insigniaTypeRepository.find({
select: ["id", "name", "createdAt", "lastUpdatedAt", "lastUpdateFullName", "isActive"],
where: { isActive: true },
order: { name: "ASC" },
where: { isActive: true, insignias: { isActive: true } },
order: { name: "ASC", insignias: { level: "ASC" } },
relations: ["insignias"],
});
return new HttpSuccess(insigniaType_Active);
}

View file

@ -5625,6 +5625,7 @@ export class OrganizationController extends Controller {
}
return new HttpSuccess({
rootId: data.id,
rootDnaId: data.ancestorDNA,
root: data.orgRootName,
rootShortName: data.orgRootShortName,
});
@ -5641,9 +5642,11 @@ export class OrganizationController extends Controller {
}
return new HttpSuccess({
rootId: data.orgRootId,
rootDnaId: data.ancestorDNA,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.id,
child1DnaId: data.ancestorDNA,
child1: data.orgChild1Name,
child1ShortName: data.orgChild1ShortName,
});
@ -5661,12 +5664,15 @@ export class OrganizationController extends Controller {
}
return new HttpSuccess({
rootId: data.orgRootId,
rootDnaId: data.ancestorDNA,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1DnaId: data.ancestorDNA,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.id,
child2DnaId: data.ancestorDNA,
child2: data.orgChild2Name,
child2ShortName: data.orgChild2ShortName,
});
@ -5685,15 +5691,19 @@ export class OrganizationController extends Controller {
}
return new HttpSuccess({
rootId: data.orgRootId,
rootDnaId: data.ancestorDNA,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1DnaId: data.ancestorDNA,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.orgChild2Id,
child2DnaId: data.ancestorDNA,
child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name,
child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName,
child3Id: data.id,
child3DnaId: data.ancestorDNA,
child3: data.orgChild3Name,
child3ShortName: data.orgChild3ShortName,
});
@ -5713,18 +5723,23 @@ export class OrganizationController extends Controller {
}
return new HttpSuccess({
rootId: data.orgRootId,
rootDnaId: data.ancestorDNA,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1DnaId: data.ancestorDNA,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.orgChild2Id,
child2DnaId: data.ancestorDNA,
child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name,
child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName,
child3Id: data.orgChild3Id,
child3DnaId: data.ancestorDNA,
child3: data.orgChild3 == null ? null : data.orgChild3.orgChild3Name,
child3ShortName: data.orgChild3 == null ? null : data.orgChild3.orgChild3ShortName,
child4Id: data.id,
child4DnaId: data.ancestorDNA,
child4: data.orgChild4Name,
child4ShortName: data.orgChild4ShortName,
});
@ -6380,6 +6395,7 @@ export class OrganizationController extends Controller {
)
.select([
"orgRoot.id",
"orgRoot.ancestorDNA",
"orgRoot.orgRootName",
"orgRoot.orgRootShortName",
"orgRoot.orgRootCode",
@ -6412,6 +6428,7 @@ export class OrganizationController extends Controller {
)
.select([
"orgChild1.id",
"orgChild1.ancestorDNA",
"orgChild1.orgChild1Name",
"orgChild1.orgChild1ShortName",
"orgChild1.orgChild1Code",
@ -6446,6 +6463,7 @@ export class OrganizationController extends Controller {
)
.select([
"orgChild2.id",
"orgChild2.ancestorDNA",
"orgChild2.orgChild2Name",
"orgChild2.orgChild2ShortName",
"orgChild2.orgChild2Code",
@ -6481,6 +6499,7 @@ export class OrganizationController extends Controller {
)
.select([
"orgChild3.id",
"orgChild3.ancestorDNA",
"orgChild3.orgChild3Name",
"orgChild3.orgChild3ShortName",
"orgChild3.orgChild3Code",
@ -6516,6 +6535,7 @@ export class OrganizationController extends Controller {
)
.select([
"orgChild4.id",
"orgChild4.ancestorDNA",
"orgChild4.orgChild4Name",
"orgChild4.orgChild4ShortName",
"orgChild4.orgChild4Code",
@ -6538,6 +6558,7 @@ export class OrganizationController extends Controller {
orgRootData.map(async (orgRoot) => {
return {
orgTreeId: orgRoot.id,
orgTreeDnaId: orgRoot.ancestorDNA,
orgLevel: 0,
orgName: orgRoot.orgRootName,
orgTreeName: orgRoot.orgRootName,
@ -6646,7 +6667,9 @@ export class OrganizationController extends Controller {
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
.map(async (orgChild1) => ({
orgTreeId: orgChild1.id,
orgTreeDnaId: orgChild1.ancestorDNA,
orgRootId: orgRoot.id,
orgRootDnaId: orgRoot.ancestorDNA,
orgLevel: 1,
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild1.orgChild1Name,
@ -6768,7 +6791,9 @@ export class OrganizationController extends Controller {
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
.map(async (orgChild2) => ({
orgTreeId: orgChild2.id,
orgTreeDnaId: orgChild2.ancestorDNA,
orgRootId: orgChild1.id,
orgRootDnaId: orgChild1.ancestorDNA,
orgLevel: 2,
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild2.orgChild2Name,
@ -6900,7 +6925,9 @@ export class OrganizationController extends Controller {
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
.map(async (orgChild3) => ({
orgTreeId: orgChild3.id,
orgTreeDnaId: orgChild3.ancestorDNA,
orgRootId: orgChild2.id,
orgRootDnaId: orgChild2.ancestorDNA,
orgLevel: 3,
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild3.orgChild3Name,
@ -7039,7 +7066,9 @@ export class OrganizationController extends Controller {
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
orgTreeDnaId: orgChild4.ancestorDNA,
orgRootId: orgChild3.id,
orgRootDnaId: orgChild3.ancestorDNA,
orgLevel: 4,
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild4.orgChild4Name,

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
*

View file

@ -1,4 +1,4 @@
import { Controller, Get, Post, Route, Tags, Body, Path, Response } from "tsoa";
import { Controller, Get, Post, Route, Tags, Body, Path, Response, Patch } from "tsoa";
import { OrgRevision } from "../entities/OrgRevision";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
@ -1159,4 +1159,60 @@ export class OrganizationUnauthorizeController extends Controller {
await this.profileRepo.save(profile);
return new HttpSuccess("Email verified successfully.");
}
// @Patch("retirement")
// public async updateStatusRetirement(
// @Body()
// body: {
// data: {
// profileId: string;
// }[];
// },
// ) {
// let profiles: Profile[] = [];
// let _null: any = null;
// await Promise.all(
// body.data.map(async (item) => {
// const _profile = await this.profileRepo.findOneBy({ id: item.profileId });
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// _profile.isRetirement = true;
// _profile.isLeave = true;
// _profile.leaveType = "RETIRE";
// _profile.leaveDate = new Date();
// _profile.dateLeave = new Date();
// _profile.lastUpdatedAt = new Date();
// profiles.push(_profile);
// })
// );
// await this.profileRepo.save(profiles);
// return new HttpSuccess();
// }
// @Patch("retirement-employee")
// public async updateStatusRetirementEmp(
// @Body()
// body: {
// data: {
// profileId: string;
// }[];
// },
// ) {
// let profiles: ProfileEmployee[] = [];
// let _null: any = null;
// await Promise.all(
// body.data.map(async (item) => {
// const _profile = await this.profileEmpRepo.findOneBy({ id: item.profileId });
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// _profile.isRetirement = true;
// _profile.isLeave = true;
// _profile.leaveType = "RETIRE";
// _profile.leaveDate = new Date();
// _profile.dateLeave = new Date();
// _profile.lastUpdatedAt = new Date();
// profiles.push(_profile);
// })
// );
// await this.profileEmpRepo.save(profiles);
// return new HttpSuccess();
// }
}

View file

@ -300,7 +300,7 @@ export class PosMasterActController extends Controller {
];
const _organization = organization
.filter((part) => part !== undefined && part !== null)
.join("/");
.join(" ");
const organizationNew = [
posMasterAct.posMaster?.current_holder?.position ?? null,
@ -312,7 +312,7 @@ export class PosMasterActController extends Controller {
];
const _organizationNew = organizationNew
.filter((part) => part !== undefined && part !== null)
.join("/");
.join(" ");
return new HttpSuccess({
prefix: posMasterAct.posMasterChild?.current_holder?.prefix ?? null,
firstName: posMasterAct.posMasterChild?.current_holder?.firstName ?? null,

View file

@ -134,7 +134,7 @@ export class ProfileAbilityController extends Controller {
history.profileAbilityId = data.id;
await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{abilityId}")

View file

@ -139,7 +139,7 @@ export class ProfileAbilityEmployeeController extends Controller {
await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{abilityId}")

View file

@ -133,7 +133,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{abilityId}")

View file

@ -0,0 +1,204 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
import {
CreateProfileActposition,
ProfileActposition,
UpdateProfileActposition,
} from "../entities/ProfileActposition";
import { ProfileActpositionHistory } from "../entities/ProfileActpositionHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/actposition")
@Tags("ProfileActposition")
@Security("bearerAuth")
export class ProfileActpositionController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileActpositionRepo = AppDataSource.getRepository(ProfileActposition);
private profileActpositionHistoryRepo = AppDataSource.getRepository(ProfileActpositionHistory);
@Get("user")
public async detailProfileActpositionUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("{profileId}")
public async detailProfileActposition(
@Path() profileId: string,
@Request() req: RequestWithUser,
) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileId: profileId },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("admin/history/{actpositionId}")
public async getProfileActpositionAdminHistory(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
let _workflow = await new permission().Workflow(req, actpositionId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{actpositionId}")
public async getProfileActpositionHistory(@Path() actpositionId: string) {
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileActposition(
@Request() req: RequestWithUser,
@Body() body: CreateProfileActposition,
) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileActposition();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileActpositionHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileActpositionRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileActpositionId = data.id;
await this.profileActpositionHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{actpositionId}")
public async editProfileActposition(
@Body() body: UpdateProfileActposition,
@Request() req: RequestWithUser,
@Path() actpositionId: string,
) {
const record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileActpositionHistory();
const before = structuredClone(record);
// const before_null = null;
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileActpositionId = actpositionId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileActpositionRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileActpositionHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{actpositionId}")
public async deleteProfileActposition(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_OFFICER",
_record.profileId,
);
}
await this.profileActpositionHistoryRepo.delete({
profileActpositionId: actpositionId,
});
const result = await this.profileActpositionRepo.delete({ id: actpositionId });
if (result.affected == undefined || result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();
}
}

View file

@ -0,0 +1,211 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import {
CreateProfileActpositionEmployee,
ProfileActposition,
UpdateProfileActposition,
} from "../entities/ProfileActposition";
import { ProfileActpositionHistory } from "../entities/ProfileActpositionHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/actposition")
@Tags("ProfileActpositionEmployee")
@Security("bearerAuth")
export class ProfileActpositionEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileActpositionRepo = AppDataSource.getRepository(ProfileActposition);
private profileActpositionHistoryRepo = AppDataSource.getRepository(ProfileActpositionHistory);
@Get("user")
public async detailProfileActpositionUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileEmployeeId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("{profileEmployeeId}")
public async detailProfileActposition(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_EMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("admin/history/{actpositionId}")
public async getProfileAdminActpositionHistory(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
let _workflow = await new permission().Workflow(req, actpositionId, "SYS_REGISTRY_EMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{actpositionId}")
public async getProfileActpositionHistory(@Path() actpositionId: string) {
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileActposition(
@Request() req: RequestWithUser,
@Body() body: CreateProfileActpositionEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileActposition();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileActpositionHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileActpositionRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileActpositionId = data.id;
await this.profileActpositionHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{actpositionId}")
public async editProfileActposition(
@Body() body: UpdateProfileActposition,
@Request() req: RequestWithUser,
@Path() actpositionId: string,
) {
const record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(
req,
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileActpositionHistory();
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileActpositionId = actpositionId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileActpositionRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileActpositionHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{actpositionId}")
public async deleteProfileActposition(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
await this.profileActpositionHistoryRepo.delete({
profileActpositionId: actpositionId,
});
const result = await this.profileActpositionRepo.delete({ id: actpositionId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -0,0 +1,198 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import {
CreateProfileActpositionEmployee,
ProfileActposition,
UpdateProfileActposition,
} from "../entities/ProfileActposition";
import { ProfileActpositionHistory } from "../entities/ProfileActpositionHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/actposition")
@Tags("ProfileActpositionEmployee")
@Security("bearerAuth")
export class ProfileActpositionEmployeeTempController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileActpositionRepo = AppDataSource.getRepository(ProfileActposition);
private profileActpositionHistoryRepo = AppDataSource.getRepository(ProfileActpositionHistory);
@Get("user")
public async detailProfileActpositionUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileEmployeeId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("{profileEmployeeId}")
public async detailProfileActposition(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileActpositionId = await this.profileActpositionRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
});
if (!getProfileActpositionId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileActpositionId);
}
@Get("admin/history/{actpositionId}")
public async getProfileAdminActpositionHistory(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
let _workflow = await new permission().Workflow(req, actpositionId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
}
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{actpositionId}")
public async getProfileActpositionHistory(@Path() actpositionId: string) {
const record = await this.profileActpositionHistoryRepo.find({
where: { profileActpositionId: actpositionId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileActposition(
@Request() req: RequestWithUser,
@Body() body: CreateProfileActpositionEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = null;
const data = new ProfileActposition();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileActpositionHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileActpositionRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileActpositionId = data.id;
await this.profileActpositionHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{actpositionId}")
public async editProfileActposition(
@Body() body: UpdateProfileActposition,
@Request() req: RequestWithUser,
@Path() actpositionId: string,
) {
const record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileActpositionHistory();
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileActpositionId = actpositionId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileActpositionRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileActpositionHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{actpositionId}")
public async deleteProfileActposition(
@Path() actpositionId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
if (_record) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
}
await this.profileActpositionHistoryRepo.delete({
profileActpositionId: actpositionId,
});
const result = await this.profileActpositionRepo.delete({ id: actpositionId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -146,7 +146,7 @@ export class ProfileAssessmentsController extends Controller {
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{assessmentId}")

View file

@ -147,7 +147,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{assessmentId}")

View file

@ -140,7 +140,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{assessmentId}")

View file

@ -0,0 +1,201 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
import {
CreateProfileAssistance,
ProfileAssistance,
UpdateProfileAssistance,
} from "../entities/ProfileAssistance";
import { ProfileAssistanceHistory } from "../entities/ProfileAssistanceHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/assistance")
@Tags("ProfileAssistance")
@Security("bearerAuth")
export class ProfileAssistanceController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileAssistanceRepo = AppDataSource.getRepository(ProfileAssistance);
private profileAssistanceHistoryRepo = AppDataSource.getRepository(ProfileAssistanceHistory);
@Get("user")
public async detailProfileAssistanceUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("{profileId}")
public async detailProfileAssistance(@Path() profileId: string, @Request() req: RequestWithUser) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileId: profileId },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("admin/history/{assistanceId}")
public async getProfileAssistanceAdminHistory(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
let _workflow = await new permission().Workflow(req, assistanceId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assistanceId}")
public async getProfileAssistanceHistory(@Path() assistanceId: string) {
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileAssistance(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAssistance,
) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileAssistance();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileAssistanceHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileAssistanceRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAssistanceId = data.id;
await this.profileAssistanceHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{assistanceId}")
public async editProfileAssistance(
@Body() body: UpdateProfileAssistance,
@Request() req: RequestWithUser,
@Path() assistanceId: string,
) {
const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileAssistanceHistory();
const before = structuredClone(record);
// const before_null = null;
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileAssistanceId = assistanceId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileAssistanceRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileAssistanceHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{assistanceId}")
public async deleteProfileAssistance(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_OFFICER",
_record.profileId,
);
}
await this.profileAssistanceHistoryRepo.delete({
profileAssistanceId: assistanceId,
});
const result = await this.profileAssistanceRepo.delete({ id: assistanceId });
if (result.affected == undefined || result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();
}
}

View file

@ -0,0 +1,211 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import {
CreateProfileAssistanceEmployee,
ProfileAssistance,
UpdateProfileAssistance,
} from "../entities/ProfileAssistance";
import { ProfileAssistanceHistory } from "../entities/ProfileAssistanceHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/assistance")
@Tags("ProfileAssistanceEmployee")
@Security("bearerAuth")
export class ProfileAssistanceEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssistanceRepo = AppDataSource.getRepository(ProfileAssistance);
private profileAssistanceHistoryRepo = AppDataSource.getRepository(ProfileAssistanceHistory);
@Get("user")
public async detailProfileAssistanceUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("{profileEmployeeId}")
public async detailProfileAssistance(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_EMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("admin/history/{assistanceId}")
public async getProfileAdminAssistanceHistory(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
let _workflow = await new permission().Workflow(req, assistanceId, "SYS_REGISTRY_EMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assistanceId}")
public async getProfileAssistanceHistory(@Path() assistanceId: string) {
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileAssistance(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAssistanceEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileAssistance();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileAssistanceHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileAssistanceRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAssistanceId = data.id;
await this.profileAssistanceHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{assistanceId}")
public async editProfileAssistance(
@Body() body: UpdateProfileAssistance,
@Request() req: RequestWithUser,
@Path() assistanceId: string,
) {
const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(
req,
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAssistanceHistory();
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileAssistanceId = assistanceId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileAssistanceRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileAssistanceHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{assistanceId}")
public async deleteProfileAssistance(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
await this.profileAssistanceHistoryRepo.delete({
profileAssistanceId: assistanceId,
});
const result = await this.profileAssistanceRepo.delete({ id: assistanceId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -0,0 +1,198 @@
import {
Body,
Controller,
Delete,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import {
CreateProfileAssistanceEmployee,
ProfileAssistance,
UpdateProfileAssistance,
} from "../entities/ProfileAssistance";
import { ProfileAssistanceHistory } from "../entities/ProfileAssistanceHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/assistance")
@Tags("ProfileAssistanceEmployee")
@Security("bearerAuth")
export class ProfileAssistanceEmployeeTempController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssistanceRepo = AppDataSource.getRepository(ProfileAssistance);
private profileAssistanceHistoryRepo = AppDataSource.getRepository(ProfileAssistanceHistory);
@Get("user")
public async detailProfileAssistanceUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profile.id },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("{profileEmployeeId}")
public async detailProfileAssistance(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
});
if (!getProfileAssistanceId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssistanceId);
}
@Get("admin/history/{assistanceId}")
public async getProfileAdminAssistanceHistory(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
let _workflow = await new permission().Workflow(req, assistanceId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
}
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assistanceId}")
public async getProfileAssistanceHistory(@Path() assistanceId: string) {
const record = await this.profileAssistanceHistoryRepo.find({
where: { profileAssistanceId: assistanceId },
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileAssistance(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAssistanceEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = null;
const data = new ProfileAssistance();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
const history = new ProfileAssistanceHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileAssistanceRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAssistanceId = data.id;
await this.profileAssistanceHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(data.id);
}
@Patch("{assistanceId}")
public async editProfileAssistance(
@Body() body: UpdateProfileAssistance,
@Request() req: RequestWithUser,
@Path() assistanceId: string,
) {
const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAssistanceHistory();
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
history.profileAssistanceId = assistanceId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileAssistanceRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileAssistanceHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}
@Delete("{assistanceId}")
public async deleteProfileAssistance(
@Path() assistanceId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId });
if (_record) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
}
await this.profileAssistanceHistoryRepo.delete({
profileAssistanceId: assistanceId,
});
const result = await this.profileAssistanceRepo.delete({ id: assistanceId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -126,7 +126,7 @@ export class ProfileCertificateController extends Controller {
await this.certificateHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{certificateId}")

View file

@ -130,7 +130,7 @@ export class ProfileCertificateEmployeeController extends Controller {
await this.certificateHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{certificateId}")

View file

@ -121,7 +121,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
await this.certificateHistoryRepo.save(history, { data: req });
setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{certificateId}")

View file

@ -104,7 +104,7 @@ export class ProfileChildrenController extends Controller {
await this.childrenHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{childrenId}")

View file

@ -111,7 +111,8 @@ export class ProfileChildrenEmployeeController extends Controller {
history.profileChildrenId = data.id;
await this.childrenHistoryRepository.save(history, { data: req });
setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{childrenId}")

View file

@ -103,7 +103,7 @@ export class ProfileChildrenEmployeeTempController extends Controller {
await this.childrenHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{childrenId}")

View file

@ -70,6 +70,7 @@ import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHisto
import { viewDirector } from "../entities/view/viewDirector";
import { viewDirectorActing } from "../entities/view/viewDirectorActing";
import CallAPI from "../interfaces/call-api";
import { OrgRoot } from "../entities/OrgRoot";
@Route("api/v1/org/profile")
@Tags("Profile")
@Security("bearerAuth")
@ -80,6 +81,7 @@ import CallAPI from "../interfaces/call-api";
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class ProfileController extends Controller {
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private orgRootRepo = AppDataSource.getRepository(OrgRoot);
private posMasterRepo = AppDataSource.getRepository(PosMaster);
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
@ -1654,6 +1656,204 @@ export class ProfileController extends Controller {
return new HttpSuccess({ data: lists, total });
}
}
/**
*
*
*/
@Post("commander-director-position")
async getProfileCommanderDirectorPosition(
@Request() request: RequestWithUser,
@Body()
body: {
isAct: boolean;
isDirector: boolean;
keyword: string;
page: number;
pageSize: number;
profileId: string;
},
) {
let posMaster = await this.posMasterRepo.findOne({
where: {
current_holderId: body.profileId,
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
relations: ["current_holder", "current_holder.posLevel"],
});
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "DEPUTY") {
posMaster = await this.posMasterRepo.findOne({
where: {
orgRoot: { isDeputy: true },
orgChild1Id: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
});
return new HttpSuccess({ data: [], total: 0 });
} else if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "GOVERNOR") {
return new HttpSuccess({ data: [], total: 0 });
}
let condition: any = {
orgRootId: posMaster.orgRootId,
id: Not(posMaster.current_holderId || ""),
};
let conditionNow: any = {
orgRootId: posMaster.orgRootId ?? IsNull(),
orgChild1Id: posMaster.orgChild1Id ?? IsNull(),
orgChild2Id: posMaster.orgChild2Id ?? IsNull(),
orgChild3Id: posMaster.orgChild3Id ?? IsNull(),
orgChild4Id: posMaster.orgChild4Id ?? IsNull(),
id: Not(posMaster.current_holderId),
};
if (
posMaster.orgRootId == null ||
posMaster.orgChild1Id == null ||
posMaster.orgChild2Id == null
) {
condition.orgChild1Id = IsNull();
} else if (posMaster.orgChild3Id == null) {
condition.orgChild2Id = IsNull();
} else if (posMaster.orgChild4Id == null) {
condition.orgChild3Id = IsNull();
} else if (posMaster.orgChild4Id != null) {
condition.orgChild4Id = IsNull();
}
if (body.isDirector == true) {
condition.isDirector = true;
conditionNow.isDirector = true;
}
console.log(condition);
console.log(conditionNow);
if (body.isAct == true) {
const [lists, total] = await AppDataSource.getRepository(viewDirectorActing)
.createQueryBuilder("viewDirectorActing")
.andWhere(
new Brackets((qb) => {
qb.orWhere(condition).orWhere(conditionNow);
}),
)
.andWhere(
new Brackets((qb) => {
qb.orWhere(
body.keyword != null && body.keyword != ""
? "CONCAT(viewDirectorActing.prefix,viewDirectorActing.firstName,' ',viewDirectorActing.lastName) LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirectorActing.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirectorActing.actFullName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "CONCAT(viewDirectorActing.posType, ' (', viewDirectorActing.posLevel, ')') LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirectorActing.posNo LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirectorActing.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
}),
)
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: lists, total });
} else {
const [lists, total] = await AppDataSource.getRepository(viewDirector)
.createQueryBuilder("viewDirector")
.andWhere(
new Brackets((qb) => {
qb.orWhere(condition).orWhere(conditionNow);
}),
)
.andWhere(
new Brackets((qb) => {
qb.orWhere(
body.keyword != null && body.keyword != ""
? "CONCAT(viewDirector.prefix,viewDirector.firstName,' ',viewDirector.lastName) LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirector.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirector.actFullName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "CONCAT(viewDirector.posType, ' (', viewDirector.posLevel, ')') LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirector.posNo LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "viewDirector.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
}),
)
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: lists, total });
}
}
/**
* API User (ADMIN)
@ -4036,9 +4236,7 @@ export class ProfileController extends Controller {
@Query() yearLeave?: number,
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
@Query() node?: number,
@Query() nodeId?: string,
@Query() isAll?: boolean,
) {
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
@ -4057,30 +4255,32 @@ export class ProfileController extends Controller {
END LIKE :keyword
`;
}
let nodeCondition = "1=1";
let nodeAll = "";
if (node === 0 && nodeId) {
nodeCondition = "current_holders.orgRootId = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL";
} else if (node === 1 && nodeId) {
nodeCondition = "current_holders.orgChild1Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL";
} else if (node === 2 && nodeId) {
nodeCondition = "current_holders.orgChild2Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL";
} else if (node === 3 && nodeId) {
nodeCondition = "current_holders.orgChild3Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL";
} else if (node === 4 && nodeId) {
nodeCondition = "current_holders.orgChild4Id = :nodeId";
}
nodeCondition = nodeCondition + nodeAll;
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
let posMaster = await this.posMasterRepo.findOne({
where: {
current_holder: { keycloak: request.user.sub },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
let revisionId = "";
if (nodeId == null) {
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
revisionId = findRevision.id;
if (posMaster != null) nodeId = posMaster.orgRootId ?? "";
} else {
const findRoot = await this.orgRootRepo.findOne({
where: { id: nodeId },
});
if (!findRoot) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบสำนักงานนี้ในระบบ");
}
revisionId = findRoot.orgRevisionId;
}
let nodeCondition = "current_holders.orgRootId = :nodeId";
const [record, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
@ -4094,7 +4294,7 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: revisionId })
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
@ -4135,7 +4335,7 @@ export class ProfileController extends Controller {
nodeId: nodeId,
})
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
// orgRevisionId: findRevision.id,
// orgRevisionId: revisionId,
// })
.orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize)
@ -4146,80 +4346,77 @@ export class ProfileController extends Controller {
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 == revisionId) == null ||
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.positions.length == 0 ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
.find((x) => x.orgRevisionId == revisionId)
?.positions.find((x: any) => x.positionIsSelected == true) == null ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
.find((x) => x.orgRevisionId == revisionId)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
? null
: _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
.find((x) => x.orgRevisionId == revisionId)
?.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}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.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)
(_data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null)
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot;
const child1 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1;
const child2 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2;
const child3 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3;
const child4 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
@ -4649,10 +4846,10 @@ export class ProfileController extends Controller {
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name} `;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name} `;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name} `;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name} `;
return {
id: _data.id,
@ -4928,7 +5125,7 @@ export class ProfileController extends Controller {
requestBody.position != null && requestBody.position !== ""
? "positions.positionName LIKE :positionName"
: "1=1",
{ positionName: `${requestBody.position}` },
{ positionName: `%${requestBody.position}%` },
)
.getMany();
@ -5125,18 +5322,23 @@ export class ProfileController extends Controller {
posExecutiveId:
position == null || position.posExecutive == null ? null : position.posExecutive.id,
rootId: root == null ? null : root.id,
rootDnaId: root == null ? null : root.ancestorDNA,
root: root == null ? null : root.orgRootName,
rootShortName: root == null ? null : root.orgRootShortName,
child1Id: child1 == null ? null : child1.id,
child1DnaId: child1 == null ? null : child1.ancestorDNA,
child1: child1 == null ? null : child1.orgChild1Name,
child1ShortName: child1 == null ? null : child1.orgChild1ShortName,
child2Id: child2 == null ? null : child2.id,
child2DnaId: child2 == null ? null : child2.ancestorDNA,
child2: child2 == null ? null : child2.orgChild2Name,
child2ShortName: child2 == null ? null : child2.orgChild2ShortName,
child3Id: child3 == null ? null : child3.id,
child3DnaId: child3 == null ? null : child3.ancestorDNA,
child3: child3 == null ? null : child3.orgChild3Name,
child3ShortName: child3 == null ? null : child3.orgChild3ShortName,
child4Id: child4 == null ? null : child4.id,
child4DnaId: child4 == null ? null : child4.ancestorDNA,
child4: child4 == null ? null : child4.orgChild4Name,
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null,
@ -5271,18 +5473,23 @@ export class ProfileController extends Controller {
posExecutiveId:
position == null || position.posExecutive == null ? null : position.posExecutive.id,
rootId: root == null ? null : root.id,
rootDnaId: root == null ? null : root.ancestorDNA,
root: root == null ? null : root.orgRootName,
rootShortName: root == null ? null : root.orgRootShortName,
child1Id: child1 == null ? null : child1.id,
child1DnaId: child1 == null ? null : child1.ancestorDNA,
child1: child1 == null ? null : child1.orgChild1Name,
child1ShortName: child1 == null ? null : child1.orgChild1ShortName,
child2Id: child2 == null ? null : child2.id,
child2DnaId: child2 == null ? null : child2.ancestorDNA,
child2: child2 == null ? null : child2.orgChild2Name,
child2ShortName: child2 == null ? null : child2.orgChild2ShortName,
child3Id: child3 == null ? null : child3.id,
child3DnaId: child3 == null ? null : child3.ancestorDNA,
child3: child3 == null ? null : child3.orgChild3Name,
child3ShortName: child3 == null ? null : child3.orgChild3ShortName,
child4Id: child4 == null ? null : child4.id,
child4DnaId: child4 == null ? null : child4.ancestorDNA,
child4: child4 == null ? null : child4.orgChild4Name,
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null,
@ -5502,7 +5709,7 @@ export class ProfileController extends Controller {
: posMaster_.orgChild1.orgChild1Name,
posMaster_ == null || posMaster_.orgRoot == null ? null : posMaster_.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
//find commander(ผู้บังคับบัญชา)
let node = 4;
@ -5707,7 +5914,7 @@ export class ProfileController extends Controller {
];
commanderOrg_ = commanderFullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
.join(" ");
const commandAboveProfile = await this.profileRepo.findOne({
where: { id: String(commandAboveProfileId) },
@ -5755,7 +5962,7 @@ export class ProfileController extends Controller {
];
commanderAboveOrg_ = commanderAboveFullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
.join(" ");
const _profile: any = {
profileId: profile.id,
@ -7338,6 +7545,7 @@ export class ProfileController extends Controller {
.orWhere(conditionFullName, {
keyword: `%${body.keyword}%`,
})
.andWhere("profile.isLeave = false")
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
@ -7530,11 +7738,12 @@ export class ProfileController extends Controller {
.where((qb) => {
if (body.rootId) {
qb.andWhere("posMaster.orgRootId = :rootId", { rootId: body.rootId });
} else {
qb.andWhere("posMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
}
qb.andWhere("posMaster.current_holderId IS NOT NULL");
qb.andWhere("posMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
})
.andWhere(
new Brackets((qb) => {
@ -8082,6 +8291,7 @@ export class ProfileController extends Controller {
if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER");
}
profile.leaveType = "RETIRE_DECEASED";
await this.profileRepo.save(profile, { data: request });
setLogDataDiff(request, { before, after: profile });

View file

@ -127,23 +127,18 @@ export class ProfileDevelopmentController extends Controller {
public async developmentDetail(
@Path() developmentId: string,
@Path() type: string,
@Request() req: RequestWithUser
@Request() req: RequestWithUser,
) {
const data = await this.developmentRequestRepository.findOne({
where: { id: developmentId },
relations: ["developmentProjects"],
});
if (!data)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบรายการพัฒนารายบุคคลดังกล่าว");
if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบรายการพัฒนารายบุคคลดังกล่าว");
if (type.trim().toLocaleUpperCase() == "OFFICER") {
let _workflow = await new permission().Workflow(req, developmentId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(
req,
"SYS_REGISTRY_OFFICER",
data.profileId,
);
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", data.profileId);
} else if (type.trim().toLocaleUpperCase() == "EMPLOYEE") {
let _workflow = await new permission().Workflow(req, developmentId, "SYS_REGISTRY_EMP");
if (_workflow == false)
@ -183,8 +178,8 @@ export class ProfileDevelopmentController extends Controller {
reasonDevelopment10: data.reasonDevelopment10,
selectType: null,
selectTypeYear: null,
selectTypeId: null
}
selectTypeId: null,
};
const _data = {
..._mapData,
developmentProjects: data.developmentProjects.map((x) => x.name),
@ -249,7 +244,7 @@ export class ProfileDevelopmentController extends Controller {
);
}
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{developmentId}")

View file

@ -135,7 +135,7 @@ export class ProfileDevelopmentEmployeeController extends Controller {
);
}
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{developmentId}")

View file

@ -127,7 +127,7 @@ export class ProfileDevelopmentEmployeeTempController extends Controller {
);
}
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{developmentId}")

View file

@ -133,7 +133,7 @@ export class ProfileDisciplineController extends Controller {
await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{disciplineId}")

View file

@ -135,7 +135,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
history.profileDisciplineId = data.id;
await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{disciplineId}")

View file

@ -128,7 +128,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{disciplineId}")

View file

@ -110,7 +110,7 @@ export class ProfileDutyController extends Controller {
history.profileDutyId = data.id;
await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{dutyId}")

View file

@ -115,7 +115,7 @@ export class ProfileDutyEmployeeController extends Controller {
await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{dutyId}")

View file

@ -107,7 +107,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{dutyId}")

View file

@ -145,7 +145,7 @@ export class ProfileEducationsController extends Controller {
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{educationId}")

View file

@ -151,7 +151,7 @@ export class ProfileEducationsEmployeeController extends Controller {
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{educationId}")

View file

@ -141,7 +141,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{educationId}")

View file

@ -1714,10 +1714,10 @@ export class ProfileEmployeeController extends Controller {
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name} `;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name} `;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name} `;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name} `;
return {
id: _data.id,
prefix: _data.prefix,
@ -2069,7 +2069,7 @@ export class ProfileEmployeeController extends Controller {
requestBody.position != null && requestBody.position !== ""
? "positions.positionName LIKE :positionName"
: "1=1",
{ positionName: `${requestBody.position}` },
{ positionName: `%${requestBody.position}%` },
)
.getMany();
@ -3141,6 +3141,192 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("retire")
async getProfileBySearchKeywordRetire(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
},
) {
let conditionFullName =
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
const [findProfile, total] = await AppDataSource.getRepository(ProfileEmployee)
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType")
.leftJoinAndSelect("profileEmployee.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")
.where(`profileEmployee.position LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profileEmployee.prefix LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profileEmployee.firstName LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profileEmployee.lastName LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posLevel.posLevelName LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posType.posTypeName LIKE :keyword`, {
keyword: `%${body.keyword}%`,
})
.orWhere(conditionFullName, {
keyword: `%${body.keyword}%`,
})
.andWhere("profileEmployee.isLeave = false")
.orderBy("profileEmployee.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
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 mapDataProfile = await Promise.all(
findProfile.map(async (item: ProfileEmployee) => {
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 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
*
@ -3182,11 +3368,12 @@ export class ProfileEmployeeController extends Controller {
.where((qb) => {
if (body.rootId) {
qb.andWhere("employeePosMaster.orgRootId = :rootId", { rootId: body.rootId });
} else {
qb.andWhere("employeePosMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
}
qb.andWhere("employeePosMaster.current_holderId IS NOT NULL");
qb.andWhere("employeePosMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
})
.andWhere(
new Brackets((qb) => {
@ -3684,6 +3871,7 @@ export class ProfileEmployeeController extends Controller {
if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
profile.leaveType = "RETIRE_DECEASED";
await this.profileRepo.save(profile);
return new HttpSuccess();

View file

@ -2686,11 +2686,12 @@ export class ProfileEmployeeTempController extends Controller {
.where((qb) => {
if (body.rootId) {
qb.andWhere("employeePosMaster.orgRootId = :rootId", { rootId: body.rootId });
} else {
qb.andWhere("employeePosMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
}
qb.andWhere("employeePosMaster.current_holderId IS NOT NULL");
qb.andWhere("employeePosMaster.orgRevisionId = :orgRevisionId", {
orgRevisionId: findRevision?.id,
});
})
.andWhere(
new Brackets((qb) => {

View file

@ -8,7 +8,12 @@ import { Profile } from "../entities/Profile";
import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileGovernment";
import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster";
import { calculateAge, calculateGovAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
import {
calculateAge,
calculateGovAge,
calculateRetireDate,
setLogDataDiff,
} from "../interfaces/utils";
import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org/profile/government")
@ -89,7 +94,7 @@ export class ProfileGovernmentHistoryController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -120,7 +125,7 @@ export class ProfileGovernmentHistoryController extends Controller {
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
dateRetireLaw: record.dateRetireLaw ?? null,
// govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
govAge: await calculateGovAge(profile.id,"OFFICER"),
govAge: await calculateGovAge(profile.id, "OFFICER"),
dateAppoint: record.dateAppoint,
dateStart: record.dateStart,
govAgeAbsent: record.govAgeAbsent,
@ -200,7 +205,7 @@ export class ProfileGovernmentHistoryController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -231,7 +236,7 @@ export class ProfileGovernmentHistoryController extends Controller {
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
dateRetireLaw: record.dateRetireLaw ?? null,
// govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
govAge: await calculateGovAge(profileId,"OFFICER"),
govAge: await calculateGovAge(profileId, "OFFICER"),
dateAppoint: record.dateAppoint,
dateStart: record.dateStart,
govAgeAbsent: record.govAgeAbsent,
@ -294,7 +299,7 @@ export class ProfileGovernmentHistoryController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -325,7 +330,7 @@ export class ProfileGovernmentHistoryController extends Controller {
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
dateRetireLaw: record.dateRetireLaw ?? null,
// govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
govAge: await calculateGovAge(profileId,"OFFICER"),
govAge: await calculateGovAge(profileId, "OFFICER"),
dateAppoint: record.dateAppoint,
dateStart: record.dateStart,
govAgeAbsent: record.govAgeAbsent,

View file

@ -90,7 +90,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -194,7 +194,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -281,7 +281,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {

View file

@ -85,7 +85,7 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -184,7 +184,7 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
@ -271,7 +271,7 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join(" ");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {

View file

@ -137,7 +137,7 @@ export class ProfileHonorController extends Controller {
history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{honorId}")

View file

@ -145,7 +145,7 @@ export class ProfileHonorEmployeeController extends Controller {
history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{honorId}")

View file

@ -136,7 +136,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{honorId}")

View file

@ -150,7 +150,7 @@ export class ProfileInsigniaController extends Controller {
history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{insigniaId}")

View file

@ -157,7 +157,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{insigniaId}")

View file

@ -149,7 +149,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{insigniaId}")

View file

@ -215,7 +215,7 @@ export class ProfileLeaveController extends Controller {
history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{leaveId}")

View file

@ -143,7 +143,7 @@ export class ProfileLeaveEmployeeController extends Controller {
history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{leaveId}")

View file

@ -133,7 +133,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history);
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{leaveId}")

View file

@ -101,7 +101,7 @@ export class ProfileNopaidController extends Controller {
history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{nopaidId}")

View file

@ -103,7 +103,7 @@ export class ProfileNopaidEmployeeController extends Controller {
history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{nopaidId}")

View file

@ -104,7 +104,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{nopaidId}")

View file

@ -111,7 +111,7 @@ export class ProfileOtherController extends Controller {
history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{otherId}")

View file

@ -118,7 +118,7 @@ export class ProfileOtherEmployeeController extends Controller {
history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{otherId}")

View file

@ -110,7 +110,7 @@ export class ProfileOtherEmployeeTempController extends Controller {
history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{otherId}")

View file

@ -118,7 +118,7 @@ export class ProfileTrainingController extends Controller {
history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{trainingId}")

View file

@ -126,7 +126,7 @@ export class ProfileTrainingEmployeeController extends Controller {
history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{trainingId}")

View file

@ -117,7 +117,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{trainingId}")

View file

@ -30,6 +30,7 @@ import {
getRoleMappings,
getUserCount,
enableStatus,
getUserByUsername,
} from "../keycloak";
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
@ -96,15 +97,21 @@ export class KeycloakController extends Controller {
profileId?: string;
},
) {
const userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
const checkUser = await getUserByUsername(body.username);
let userId: any = "";
if (checkUser.length == 0) {
userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
}
} else {
userId = checkUser[0].id;
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
@ -647,6 +654,78 @@ export class KeycloakController extends Controller {
}
}
@Post("user/emp")
@Security("bearerAuth", ["system", "admin"])
async createUserEmp(
@Request() request: { user: { sub: string; preferred_username: string } },
@Body()
body: {
username: string;
password: string;
firstName?: string;
lastName?: string;
email?: string;
roles: string[];
profileId?: string;
},
) {
const checkUser = await getUserByUsername(body.username);
let userId: any = "";
if (checkUser.length == 0) {
userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
}
} else {
userId = checkUser[0].id;
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
userId,
list.filter((v) => body.roles.includes(v.id)),
);
if (!result) {
throw new Error("Failed. Cannot set user's role.");
}
const profile = await this.profileEmpRepo.findOne({
where: {
id: body.profileId,
},
});
if (profile) {
let _null: any = null;
if (typeof userId === "string") {
profile.keycloak = userId;
}
profile.email = body.email == null ? _null : body.email;
await this.profileEmpRepo.save(profile);
if (body.roles != null && body.roles.length > 0) {
const roleKeycloak = await this.roleKeycloakRepo.find({
where: { id: In(body.roles) },
});
const _profile = await this.profileEmpRepo.findOne({
where: { keycloak: userId },
relations: ["roleKeycloaks"],
});
if (_profile) {
_profile.roleKeycloaks = Array.from(
new Set([..._profile.roleKeycloaks, ...roleKeycloak]),
);
this.profileEmpRepo.save(_profile);
}
}
}
return userId;
}
@Delete("group/{groupId}")
async deleteGroup(@Path() groupId: string) {
const result = await deleteGroup(groupId);
@ -693,6 +772,24 @@ export class KeycloakController extends Controller {
return profile.roleKeycloaks;
}
@Get("user/username/{citizenId}")
async getUserByUsername(@Path("citizenId") citizenId: string) {
const userData = await getUserByUsername(citizenId);
if (!userData || userData.length == 0) {
throw new Error("User not found");
}
const rolesData = await getRoleMappings(userData[0].id);
if (!rolesData) {
throw new Error("Role mappings not found");
}
const userDataWithRoles = {
...userData,
roles: rolesData,
};
return userDataWithRoles;
}
@Put("user/{userId}/enableStatus/{status}") //#log?
async changeEnableStatus(@Path() userId: string, @Path() status: boolean) {
const profile = await this.profileRepo.findOne({

View file

@ -815,6 +815,13 @@ export class WorkflowController extends Controller {
let condition: any = {
isDirector: true,
orgRootId: posMasterUser.orgRootId,
orgRevisionId: posMasterUser.orgRevisionId,
};
let conditionOfficer: any = {
isDirector: true,
isOfficer: true,
orgRevisionId: posMasterUser.orgRevisionId,
};
if (type.trim().toUpperCase() == "OPERATE") {
@ -832,6 +839,7 @@ export class WorkflowController extends Controller {
condition = {
isDirector: true,
orgRootId: posMasterUser.orgRootId,
orgRevisionId: posMasterUser.orgRevisionId,
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
@ -848,6 +856,7 @@ export class WorkflowController extends Controller {
condition = {
isDirector: true,
isDeputy: true,
orgRevisionId: posMasterUser.orgRevisionId,
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
@ -860,7 +869,11 @@ export class WorkflowController extends Controller {
if (body.isAct == true) {
const [lists, total] = await AppDataSource.getRepository(viewDirectorActing)
.createQueryBuilder("viewDirectorActing")
.andWhere(condition)
.andWhere(
new Brackets((qb) => {
qb.orWhere(condition).orWhere(conditionOfficer);
}),
)
.andWhere(
new Brackets((qb) => {
qb.orWhere(
@ -936,7 +949,11 @@ export class WorkflowController extends Controller {
} else {
const [lists, total] = await AppDataSource.getRepository(viewDirector)
.createQueryBuilder("viewDirector")
.andWhere(condition)
.andWhere(
new Brackets((qb) => {
qb.orWhere(condition).orWhere(conditionOfficer);
}),
)
.andWhere(
new Brackets((qb) => {
qb.orWhere(