Implement feature X to enhance user experience and optimize performance #1555
This commit is contained in:
parent
5a4b7c92a3
commit
5b2c968033
1 changed files with 464 additions and 481 deletions
|
|
@ -1,45 +1,44 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Path,
|
||||
Post,
|
||||
Put,
|
||||
Request,
|
||||
Response,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { And, Between, Brackets, In, IsNull, LessThanOrEqual, Not } from "typeorm";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
import { Position } from "../entities/Position";
|
||||
import { Insignia } from "../entities/Insignia";
|
||||
import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||
import { calculateRetireLaw } from "../interfaces/utils";
|
||||
import Extension from "../interfaces/extension";
|
||||
import { PosMasterHistory } from "../entities/PosMasterHistory";
|
||||
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
|
||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
|
||||
import { PosMasterHistory } from "../entities/PosMasterHistory";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileEducation } from "../entities/ProfileEducation";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia";
|
||||
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||
import Extension from "../interfaces/extension";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { calculateRetireLaw } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
@Route("api/v1/org/dotnet")
|
||||
@Tags("Dotnet")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -60,12 +59,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private posMasterHistoryRepository = AppDataSource.getRepository(PosMasterHistory);
|
||||
private posMasterEmployeeHistoryRepository =
|
||||
AppDataSource.getRepository(PosMasterEmployeeHistory);
|
||||
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||
private posMasterAssignRepo = AppDataSource.getRepository(PosMasterAssign);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
|
||||
private educationRepo = AppDataSource.getRepository(ProfileEducation);
|
||||
|
|
@ -105,10 +101,40 @@ export class OrganizationDotnetController extends Controller {
|
|||
node?: number | null;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
selectedNodeId?: string | null;
|
||||
selectedNode?: number | null;
|
||||
},
|
||||
) {
|
||||
let condition = "1=1";
|
||||
let conditionParams = {};
|
||||
|
||||
let selectedNodeCondition = "1=1";
|
||||
let selectedNodeConditionParams = {};
|
||||
|
||||
if (body.selectedNodeId && body.selectedNode != null) {
|
||||
switch (body.selectedNode) {
|
||||
case 0:
|
||||
selectedNodeCondition = "orgRoot.ancestorDNA = :selectedNodeId";
|
||||
break;
|
||||
case 1:
|
||||
selectedNodeCondition = "orgChild1.ancestorDNA = :selectedNodeId";
|
||||
break;
|
||||
case 2:
|
||||
selectedNodeCondition = "orgChild2.ancestorDNA = :selectedNodeId";
|
||||
break;
|
||||
case 3:
|
||||
selectedNodeCondition = "orgChild3.ancestorDNA = :selectedNodeId";
|
||||
break;
|
||||
case 4:
|
||||
selectedNodeCondition = "orgChild4.ancestorDNA = :selectedNodeId";
|
||||
break;
|
||||
default:
|
||||
selectedNodeCondition = "1=1";
|
||||
break;
|
||||
}
|
||||
selectedNodeConditionParams = { selectedNodeId: body.selectedNodeId };
|
||||
}
|
||||
|
||||
if (body.role === "CHILD") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
|
|
@ -214,6 +240,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
}),
|
||||
)
|
||||
.andWhere(condition, conditionParams)
|
||||
.andWhere(selectedNodeCondition, selectedNodeConditionParams)
|
||||
.select([
|
||||
"profile.id",
|
||||
"profile.citizenId",
|
||||
|
|
@ -411,20 +438,18 @@ export class OrganizationDotnetController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("get-profileId")
|
||||
async getProfileInbox(
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
let profile: any
|
||||
async getProfileInbox(@Request() request: { user: Record<string, any> }) {
|
||||
let profile: any;
|
||||
//OFF
|
||||
profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
select: { id: true }
|
||||
select: { id: true },
|
||||
});
|
||||
//EMP
|
||||
if (!profile) {
|
||||
profile = await this.profileEmpRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
select: { id: true }
|
||||
select: { id: true },
|
||||
});
|
||||
if (!profile) {
|
||||
if (request.user.role.includes("SUPER_ADMIN")) {
|
||||
|
|
@ -435,8 +460,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
}
|
||||
}
|
||||
const result = {
|
||||
profileId: profile ? profile.id : null
|
||||
}
|
||||
profileId: profile ? profile.id : null,
|
||||
};
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
|
|
@ -1048,7 +1073,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
profile.posLevel != null &&
|
||||
(profile.posType.posTypeName == "บริหาร" || profile.posType.posTypeName == "อำนวยการ")
|
||||
? `${profile.posType?.posTypeName ?? ""}${profile.posLevel?.posLevelName ?? ""}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
const _profileCurrent = profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
|
|
@ -1236,7 +1261,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
|
||||
profileType: "OFFICER",
|
||||
positionLeaveName: positionLeaveName,
|
||||
posExecutiveName: position == null || position.posExecutive == null
|
||||
posExecutiveName:
|
||||
position == null || position.posExecutive == null
|
||||
? null
|
||||
: position.posExecutive.posExecutiveName,
|
||||
oc: oc,
|
||||
|
|
@ -1297,7 +1323,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
|
@ -1346,8 +1372,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
.getOne();
|
||||
|
||||
if (pos?.current_holder) {
|
||||
commanderFullname =
|
||||
`${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderFullname = `${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderPositionName = pos.current_holder.position;
|
||||
commanderId = pos.current_holder.id;
|
||||
commanderKeycloak = pos.current_holder.keycloak;
|
||||
|
|
@ -1382,10 +1407,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
|
||||
const mapProfile = {
|
||||
id: profile.id,
|
||||
|
|
@ -1474,9 +1498,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
* 2. current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
const org = {
|
||||
|
|
@ -1526,8 +1549,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
.getOne();
|
||||
|
||||
if (pos?.current_holder) {
|
||||
commanderFullname =
|
||||
`${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderFullname = `${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderPositionName = pos.current_holder.position;
|
||||
commanderId = pos.current_holder.id;
|
||||
commanderKeycloak = pos.current_holder.keycloak;
|
||||
|
|
@ -1586,10 +1608,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
|
||||
/* =========================================
|
||||
* 8. map response
|
||||
|
|
@ -1718,7 +1739,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
|
@ -1772,7 +1793,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
posLevel: profile.posType?.posTypeShortName == null && profile.posLevel?.posLevelName == null
|
||||
posLevel:
|
||||
profile.posType?.posTypeShortName == null && profile.posLevel?.posLevelName == null
|
||||
? null
|
||||
: `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
|
||||
oc,
|
||||
|
|
@ -1801,9 +1823,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
* 2. current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
/* =========================================
|
||||
|
|
@ -1845,10 +1866,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
|
||||
/* =========================================
|
||||
* 8. map response
|
||||
|
|
@ -1961,7 +1981,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
|
@ -1997,8 +2017,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
.getOne();
|
||||
|
||||
if (pos?.current_holder) {
|
||||
commanderFullname =
|
||||
`${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderFullname = `${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderPositionName = pos.current_holder.position;
|
||||
commanderId = pos.current_holder.id;
|
||||
}
|
||||
|
|
@ -2052,7 +2071,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
posLevel: profile.posType?.posTypeShortName == null && profile.posLevel?.posLevelName == null
|
||||
posLevel:
|
||||
profile.posType?.posTypeShortName == null && profile.posLevel?.posLevelName == null
|
||||
? null
|
||||
: `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
|
||||
oc,
|
||||
|
|
@ -2091,9 +2111,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
* 2. current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
/* =================================================
|
||||
|
|
@ -2130,8 +2149,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
.getOne();
|
||||
|
||||
if (pos?.current_holder) {
|
||||
commanderFullname =
|
||||
`${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderFullname = `${pos.current_holder.prefix}${pos.current_holder.firstName} ${pos.current_holder.lastName}`;
|
||||
commanderPositionName = pos.current_holder.position;
|
||||
commanderId = pos.current_holder.id;
|
||||
}
|
||||
|
|
@ -2175,10 +2193,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
|
||||
/* =========================================
|
||||
* 8. map response
|
||||
|
|
@ -2287,7 +2304,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
|
@ -2310,9 +2327,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
* 2. current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
/* =========================================
|
||||
|
|
@ -4180,7 +4196,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("find/employee/position")
|
||||
async GetProfileByPositionEmpAsync(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
empPosId: string[];
|
||||
|
|
@ -4601,8 +4616,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
|
|
@ -4879,9 +4894,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
// }),
|
||||
// );
|
||||
const profile_ = profile.map((item: Profile) => {
|
||||
const holder = item.current_holders?.find(
|
||||
(x) => x.orgRevisionId === findRevision?.id,
|
||||
);
|
||||
const holder = item.current_holders?.find((x) => x.orgRevisionId === findRevision?.id);
|
||||
|
||||
const rootName = holder?.orgRoot?.orgRootName ?? null;
|
||||
|
||||
|
|
@ -5101,7 +5114,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("keycloak-all-officer")
|
||||
async PostProfileWithKeycloakAllOfficer(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -5272,7 +5284,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("keycloak-all-officer/date")
|
||||
async PostProfileWithKeycloakAllOfficerDate(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -5451,7 +5462,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("none-validate-keycloak-all-officer")
|
||||
async PostProfileWithNoneValidateKeycloakAllOfficer(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -5621,7 +5631,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("find-node-name")
|
||||
async findNodeName(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -5730,7 +5739,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("officer-by-admin-role")
|
||||
async GetOfficersByAdminRole(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -5785,8 +5793,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
typeCondition = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (body.role === "BROTHER") {
|
||||
} else if (body.role === "BROTHER") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
typeCondition = {
|
||||
|
|
@ -6069,7 +6076,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("keycloak-all-employee")
|
||||
async PostProfileWithKeycloakAllEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -6223,7 +6229,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("none-validate-keycloak-all-employee")
|
||||
async PostProfileWithNoneValidateKeycloakAllEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -6377,7 +6382,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("employee-by-admin-role")
|
||||
async GetEmployeesByAdminRole(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -6434,8 +6438,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
typeCondition = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (body.role === "BROTHER") {
|
||||
} else if (body.role === "BROTHER") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
typeCondition = {
|
||||
|
|
@ -7350,10 +7353,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
|
||||
@Post("profile-leave/keycloak")
|
||||
async GetProfileLeaveReportByKeycloakIdAsync(
|
||||
@Body() body: {
|
||||
keycloakId: string,
|
||||
report?: string
|
||||
}
|
||||
@Body() body: { keycloakId: string; report?: string },
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
relations: {
|
||||
|
|
@ -7396,14 +7396,14 @@ export class OrganizationDotnetController extends Controller {
|
|||
},
|
||||
where: {
|
||||
keycloak: body.keycloakId,
|
||||
}
|
||||
},
|
||||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
/* =========================================
|
||||
* current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
|
@ -7425,18 +7425,20 @@ export class OrganizationDotnetController extends Controller {
|
|||
let _positions: any[] = [];
|
||||
let _educations: any[] = [];
|
||||
if (body.report && ["LEAVE16", "LEAVE18"].includes(body.report.trim().toUpperCase())) {
|
||||
|
||||
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
|
||||
let _currentDate = CURRENT_DATE[0].today;
|
||||
if (profile && profile?.isLeave) {
|
||||
_currentDate =
|
||||
profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
|
||||
profile && profile.leaveDate
|
||||
? Extension.toDateOnlyString(profile.leaveDate)
|
||||
: _currentDate;
|
||||
}
|
||||
const positions = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [
|
||||
profile!.id,
|
||||
_currentDate,
|
||||
]);
|
||||
_positions = positions[0].length > 0
|
||||
_positions =
|
||||
positions[0].length > 0
|
||||
? _positions.slice(0, -1).map((x: any, idx: number) => ({
|
||||
positionName: x.positionName,
|
||||
dateStart: x.commandDateAffect ?? null,
|
||||
|
|
@ -7448,7 +7450,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
where: { profileEmployeeId: profile!.id, isDeleted: false },
|
||||
order: { level: "ASC" },
|
||||
});
|
||||
_educations = profileEducations.length > 0
|
||||
_educations =
|
||||
profileEducations.length > 0
|
||||
? profileEducations.map((x) => ({
|
||||
educationLevel: x.educationLevel,
|
||||
institute: x.institute ?? "-",
|
||||
|
|
@ -7465,15 +7468,11 @@ export class OrganizationDotnetController extends Controller {
|
|||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
birthDate: profile.birthDate,
|
||||
retireDate: profile.birthDate
|
||||
? calculateRetireLaw(profile.birthDate)
|
||||
: null,
|
||||
retireDate: profile.birthDate ? calculateRetireLaw(profile.birthDate) : null,
|
||||
govAge: profile.dateAppoint
|
||||
? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี`
|
||||
: null,
|
||||
age: profile.birthDate
|
||||
? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET")
|
||||
: null,
|
||||
age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET") : null,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateCurrent: new Date(),
|
||||
amount: profile.amount,
|
||||
|
|
@ -7516,9 +7515,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
* current holder
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
let oc = "";
|
||||
|
|
@ -7542,10 +7540,9 @@ export class OrganizationDotnetController extends Controller {
|
|||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
: (profile.posLevel?.posLevelName ?? null);
|
||||
|
||||
/* =========================================
|
||||
* position executive
|
||||
|
|
@ -7565,18 +7562,20 @@ export class OrganizationDotnetController extends Controller {
|
|||
let _positions: any[] = [];
|
||||
let _educations: any[] = [];
|
||||
if (body.report && ["LEAVE16", "LEAVE18"].includes(body.report.trim().toUpperCase())) {
|
||||
|
||||
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
|
||||
let _currentDate = CURRENT_DATE[0].today;
|
||||
if (profile && profile?.isLeave) {
|
||||
_currentDate =
|
||||
profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
|
||||
profile && profile.leaveDate
|
||||
? Extension.toDateOnlyString(profile.leaveDate)
|
||||
: _currentDate;
|
||||
}
|
||||
const positions = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
|
||||
profile!.id,
|
||||
_currentDate,
|
||||
]);
|
||||
_positions = positions[0].length > 0
|
||||
_positions =
|
||||
positions[0].length > 0
|
||||
? _positions.slice(0, -1).map((x: any, idx: number) => ({
|
||||
positionName: x.positionName,
|
||||
dateStart: x.commandDateAffect ?? null,
|
||||
|
|
@ -7588,7 +7587,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
where: { profileId: profile!.id, isDeleted: false },
|
||||
order: { level: "ASC" },
|
||||
});
|
||||
_educations = profileEducations.length > 0
|
||||
_educations =
|
||||
profileEducations.length > 0
|
||||
? profileEducations.map((x) => ({
|
||||
educationLevel: x.educationLevel,
|
||||
institute: x.institute ?? "-",
|
||||
|
|
@ -7605,15 +7605,11 @@ export class OrganizationDotnetController extends Controller {
|
|||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
birthDate: profile.birthDate,
|
||||
retireDate: profile.birthDate
|
||||
? calculateRetireLaw(profile.birthDate)
|
||||
: null,
|
||||
retireDate: profile.birthDate ? calculateRetireLaw(profile.birthDate) : null,
|
||||
govAge: profile.dateAppoint
|
||||
? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี`
|
||||
: null,
|
||||
age: profile.birthDate
|
||||
? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET")
|
||||
: null,
|
||||
age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET") : null,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateCurrent: new Date(),
|
||||
amount: profile.amount,
|
||||
|
|
@ -7661,7 +7657,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("find/insignia-requests-profile/{type}")
|
||||
async GetInsigniaRequestsProfileAsync(
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() type: string,
|
||||
@Body()
|
||||
body: {
|
||||
|
|
@ -7791,7 +7786,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("officer-by-admin-rolev2")
|
||||
async GetOfficersByAdminRoleV2(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -7836,8 +7830,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
typeCondition = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (body.role === "BROTHER") {
|
||||
} else if (body.role === "BROTHER") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
typeCondition = {
|
||||
|
|
@ -8016,7 +8009,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("officer-by-admin-rolev3")
|
||||
async GetOfficersByAdminRoleV3(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -8073,8 +8065,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
typeCondition = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (body.role === "BROTHER") {
|
||||
} else if (body.role === "BROTHER") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
typeCondition = {
|
||||
|
|
@ -8364,7 +8355,6 @@ export class OrganizationDotnetController extends Controller {
|
|||
*/
|
||||
@Post("officer-by-admin-rolev4")
|
||||
async GetOfficersByAdminRoleV4(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
|
|
@ -8409,8 +8399,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
typeCondition = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (body.role === "BROTHER") {
|
||||
} else if (body.role === "BROTHER") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
typeCondition = {
|
||||
|
|
@ -8608,8 +8597,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
);
|
||||
|
||||
return new HttpSuccess(
|
||||
(profile_ ?? []).sort((a, b) =>
|
||||
a.posNo.localeCompare(b.posNo, undefined, { numeric: true }))
|
||||
(profile_ ?? []).sort((a, b) => a.posNo.localeCompare(b.posNo, undefined, { numeric: true })),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -8626,18 +8614,13 @@ export class OrganizationDotnetController extends Controller {
|
|||
profileId: string;
|
||||
assignId: string;
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: requestBody.profileId },
|
||||
relations: [
|
||||
"current_holders",
|
||||
"current_holders.orgRevision"
|
||||
],
|
||||
relations: ["current_holders", "current_holders.orgRevision"],
|
||||
});
|
||||
|
||||
if (!profile)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: requestBody.assignId.trim().toLocaleUpperCase() },
|
||||
|
|
@ -8647,7 +8630,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระบบสิทธิ์หน้าที่ความรับผิดชอบ");
|
||||
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
h => h.orgRevision?.orgRevisionIsCurrent && !h.orgRevision?.orgRevisionIsDraft,
|
||||
(h) => h.orgRevision?.orgRevisionIsCurrent && !h.orgRevision?.orgRevisionIsDraft,
|
||||
);
|
||||
|
||||
if (!currentHolder)
|
||||
|
|
@ -8690,7 +8673,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
profileId: profile.id,
|
||||
})
|
||||
.andWhere("assign.assignId = :assignId", {
|
||||
assignId: assign.id
|
||||
assignId: assign.id,
|
||||
})
|
||||
.getRawMany();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue