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

4712 lines
207 KiB
TypeScript
Raw Normal View History

2024-01-26 13:32:56 +07:00
import {
Controller,
Get,
Post,
Put,
Route,
Security,
Tags,
Body,
Path,
Request,
2024-01-26 16:41:52 +07:00
SuccessResponse,
Response,
2024-01-26 13:32:56 +07:00
} from "tsoa";
import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision";
2024-01-26 13:32:56 +07:00
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
2024-08-07 17:49:28 +07:00
import { OrgChild1 } from "../entities/OrgChild1";
2024-01-26 13:32:56 +07:00
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
2024-02-01 11:02:35 +07:00
import { In, IsNull, Not } from "typeorm";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
2024-06-25 10:21:30 +07:00
import CallAPI from "../interfaces/call-api";
import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile";
import { request } from "axios";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
2024-01-30 15:10:11 +07:00
2024-01-26 16:41:52 +07:00
@Route("api/v1/org")
2024-01-26 13:32:56 +07:00
@Tags("Organization")
2024-02-15 09:41:27 +07:00
@Security("bearerAuth")
2024-01-26 16:41:52 +07:00
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
2024-01-26 13:32:56 +07:00
export class OrganizationController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
2024-06-25 10:21:30 +07:00
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileRepo = AppDataSource.getRepository(Profile);
2024-01-30 15:10:11 +07:00
2024-01-26 13:32:56 +07:00
/**
* API
*
* @summary ORG_020 - #21
*
*/
@Get("history")
async GetHistory() {
2024-02-28 14:48:41 +07:00
const orgRevision = await this.orgRevisionRepository.find({
select: [
"id",
"orgRevisionName",
"orgRevisionIsCurrent",
"orgRevisionCreatedAt",
"orgRevisionIsDraft",
],
order: { orgRevisionCreatedAt: "DESC" },
});
2024-02-28 15:07:35 +07:00
// if (!orgRevision) {
// return new HttpSuccess([]);
// }
2024-02-28 14:48:41 +07:00
const mapOrgRevisions = orgRevision.map((revision) => ({
orgRevisionId: revision.id,
orgRevisionName: revision.orgRevisionName,
orgRevisionIsCurrent: revision.orgRevisionIsCurrent,
orgRevisionCreatedAt: revision.orgRevisionCreatedAt,
orgRevisionIsDraft: revision.orgRevisionIsDraft,
}));
return new HttpSuccess(mapOrgRevisions);
2024-01-26 13:32:56 +07:00
}
/**
* API
*
* @summary ORG_021 - #22
*
*/
@Get("active")
async GetActive() {
2024-02-28 14:48:41 +07:00
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
const orgRevisionDraf = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
});
const mapData = {
activeId: orgRevisionActive == null ? null : orgRevisionActive.id,
activeName: orgRevisionActive == null ? null : orgRevisionActive.orgRevisionName,
draftId: orgRevisionDraf == null ? null : orgRevisionDraf.id,
draftName: orgRevisionDraf == null ? null : orgRevisionDraf.orgRevisionName,
orgPublishDate: orgRevisionDraf == null ? null : orgRevisionDraf.orgPublishDate,
isPublic: orgRevisionDraf == null || orgRevisionDraf.orgRevisionName == null ? false : true,
};
return new HttpSuccess(mapData);
2024-01-26 13:32:56 +07:00
}
/**
* API 4
*
2024-01-29 17:08:22 +07:00
* @summary ORG_022 - #23
2024-01-26 13:32:56 +07:00
*
*/
@Post("draft")
2024-01-26 13:32:56 +07:00
async CreateOrgRevision(
@Body() requestBody: CreateOrgRevision,
2024-01-26 13:32:56 +07:00
@Request() request: { user: Record<string, any> },
2024-01-26 16:41:52 +07:00
) {
2024-09-06 08:03:53 +07:00
//new main revision
2024-02-28 14:48:41 +07:00
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
revision.orgRevisionIsDraft = true;
revision.orgRevisionIsCurrent = false;
revision.createdUserId = request.user.sub;
revision.createdFullName = request.user.name;
revision.lastUpdateUserId = request.user.sub;
revision.lastUpdateFullName = request.user.name;
revision.createdAt = new Date();
revision.lastUpdatedAt = new Date();
2024-02-28 14:48:41 +07:00
await this.orgRevisionRepository.save(revision);
2024-09-06 08:03:53 +07:00
//cone tree
2024-02-28 14:48:41 +07:00
if (
requestBody.typeDraft.toUpperCase() == "ORG" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
2024-09-06 08:03:53 +07:00
//cone by revisionId
2024-02-28 14:48:41 +07:00
if (requestBody.orgRevisionId == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
const _revision = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId },
});
if (!_revision) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
2024-09-06 08:03:53 +07:00
//หา dna tree ถ้าไม่มีให้เอาตัวเองเป็น dna
2024-02-28 14:48:41 +07:00
const orgRoot = await this.orgRootRepository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
});
let _orgRoot: any = orgRoot.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.orgRootRepository.save(_orgRoot);
2024-02-28 14:48:41 +07:00
const orgChild1 = await this.child1Repository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
});
let _orgChild1: any = orgChild1.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.child1Repository.save(_orgChild1);
2024-02-28 14:48:41 +07:00
const orgChild2 = await this.child2Repository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
});
let _orgChild2: any = orgChild2.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.child2Repository.save(_orgChild2);
2024-02-28 14:48:41 +07:00
const orgChild3 = await this.child3Repository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
});
let _orgChild3: any = orgChild3.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.child3Repository.save(_orgChild3);
2024-02-11 22:30:12 +07:00
2024-02-28 14:48:41 +07:00
const orgChild4 = await this.child4Repository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
});
let _orgChild4: any = orgChild4.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.child4Repository.save(_orgChild4);
2024-02-11 22:30:12 +07:00
2024-09-06 08:03:53 +07:00
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
2024-02-28 14:48:41 +07:00
const orgPosMaster = await this.posMasterRepository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
relations: ["positions"],
});
let _orgPosMaster: PosMaster[];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
_orgPosMaster = orgPosMaster.map((x) => ({
2024-02-11 22:30:12 +07:00
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
2024-02-28 14:48:41 +07:00
await this.posMasterRepository.save(_orgPosMaster);
}
2024-09-06 08:03:53 +07:00
//create org
2024-02-28 14:48:41 +07:00
_orgRoot.forEach(async (x: any) => {
var dataId = x.id;
delete x.id;
const data = Object.assign(new OrgRoot(), x);
data.orgRevisionId = revision.id;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.lastUpdatedAt = new Date();
await this.orgRootRepository.save(data);
2024-02-11 22:30:12 +07:00
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
2024-09-06 08:03:53 +07:00
//create posmaster
2024-02-28 14:48:41 +07:00
await Promise.all(
_orgPosMaster
.filter((x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
.map(async (item: any) => {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
2024-09-06 08:03:53 +07:00
//create position
2024-02-28 14:48:41 +07:00
item.positions.map(async (pos: any) => {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position);
});
}),
);
2024-02-11 22:30:12 +07:00
}
2024-09-06 08:03:53 +07:00
//create org
2024-02-28 14:48:41 +07:00
_orgChild1
.filter((x: OrgChild1) => x.orgRootId == dataId)
.forEach(async (x: any) => {
var data1Id = x.id;
delete x.id;
const data1 = Object.assign(new OrgChild1(), x);
data1.orgRootId = data.id;
data1.orgRevisionId = revision.id;
data1.createdUserId = request.user.sub;
data1.createdFullName = request.user.name;
data1.createdAt = new Date();
data1.lastUpdateUserId = request.user.sub;
data1.lastUpdateFullName = request.user.name;
data1.lastUpdatedAt = new Date();
await this.child1Repository.save(data1);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
2024-09-06 08:03:53 +07:00
//create posmaster
2024-02-28 14:48:41 +07:00
await Promise.all(
_orgPosMaster
.filter((x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null)
.map(async (item: any) => {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
posMaster.orgChild1Id = data1.id;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
2024-09-06 08:03:53 +07:00
//create position
2024-02-28 14:48:41 +07:00
item.positions.map(async (pos: any) => {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
position.positionIsSelected = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position);
});
}),
);
}
2024-09-06 08:03:53 +07:00
//create org
2024-02-28 14:48:41 +07:00
_orgChild2
.filter((x: OrgChild2) => x.orgChild1Id == data1Id)
.forEach(async (x: any) => {
var data2Id = x.id;
delete x.id;
const data2 = Object.assign(new OrgChild2(), x);
data2.orgChild1Id = data1.id;
data2.orgRootId = data.id;
data2.orgRevisionId = revision.id;
data2.createdUserId = request.user.sub;
data2.createdFullName = request.user.name;
data2.createdAt = new Date();
data2.lastUpdateUserId = request.user.sub;
data2.lastUpdateFullName = request.user.name;
data2.lastUpdatedAt = new Date();
await this.child2Repository.save(data2);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
2024-09-06 08:03:53 +07:00
//create posmaster
2024-02-28 14:48:41 +07:00
await Promise.all(
_orgPosMaster
.filter((x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null)
.map(async (item: any) => {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
posMaster.orgChild1Id = data1.id;
posMaster.orgChild2Id = data2.id;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
2024-09-06 08:03:53 +07:00
//create position
2024-02-28 14:48:41 +07:00
item.positions.map(async (pos: any) => {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
position.positionIsSelected = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position);
});
}),
);
}
2024-09-06 08:03:53 +07:00
//create org
2024-02-28 14:48:41 +07:00
_orgChild3
.filter((x: OrgChild3) => x.orgChild2Id == data2Id)
.forEach(async (x: any) => {
var data3Id = x.id;
delete x.id;
const data3 = Object.assign(new OrgChild3(), x);
data3.orgChild2Id = data2.id;
data3.orgChild1Id = data1.id;
data3.orgRootId = data.id;
data3.orgRevisionId = revision.id;
data3.createdUserId = request.user.sub;
data3.createdFullName = request.user.name;
data3.createdAt = new Date();
data3.lastUpdateUserId = request.user.sub;
data3.lastUpdateFullName = request.user.name;
data3.lastUpdatedAt = new Date();
await this.child3Repository.save(data3);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
2024-09-06 08:03:53 +07:00
//create posmaster
2024-02-28 14:48:41 +07:00
await Promise.all(
_orgPosMaster
.filter(
(x: PosMaster) => x.orgChild3Id == data3Id && x.orgChild4Id == null,
)
.map(async (item: any) => {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
posMaster.orgChild1Id = data1.id;
posMaster.orgChild2Id = data2.id;
posMaster.orgChild3Id = data3.id;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
2024-09-06 08:03:53 +07:00
//create position
2024-02-28 14:48:41 +07:00
item.positions.map(async (pos: any) => {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
position.positionIsSelected = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position);
});
}),
);
}
2024-02-11 22:30:12 +07:00
2024-09-06 08:03:53 +07:00
//create org
2024-02-28 14:48:41 +07:00
_orgChild4
.filter((x: OrgChild4) => x.orgChild3Id == data3Id)
.forEach(async (x: any) => {
var data4Id = x.id;
delete x.id;
const data4 = Object.assign(new OrgChild4(), x);
data4.orgChild3Id = data3.id;
data4.orgChild2Id = data2.id;
data4.orgChild1Id = data1.id;
data4.orgRootId = data.id;
data4.orgRevisionId = revision.id;
data4.createdUserId = request.user.sub;
data4.createdFullName = request.user.name;
data4.createdAt = new Date();
data4.lastUpdateUserId = request.user.sub;
data4.lastUpdateFullName = request.user.name;
data4.lastUpdatedAt = new Date();
await this.child4Repository.save(data4);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
) {
await Promise.all(
_orgPosMaster
.filter((x: PosMaster) => x.orgChild4Id == data4Id)
.map(async (item: any) => {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
posMaster.orgChild1Id = data1.id;
posMaster.orgChild2Id = data2.id;
posMaster.orgChild3Id = data3.id;
posMaster.orgChild4Id = data4.id;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
posMaster.createdAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
2024-09-06 08:03:53 +07:00
//create position
2024-02-28 14:48:41 +07:00
item.positions.map(async (pos: any) => {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
position.positionIsSelected = false;
2024-02-12 09:50:04 +07:00
}
2024-02-28 14:48:41 +07:00
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position);
});
}),
);
}
});
});
});
});
});
2024-02-28 14:48:41 +07:00
}
const _orgRevisions = await this.orgRevisionRepository.find({
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
});
const _posMasters = await this.posMasterRepository.find({
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
});
const _positions = await this.positionRepository.find({
where: [{ posMasterId: In(_posMasters.map((x) => x.id)) }],
});
await this.positionRepository.remove(_positions);
await this.posMasterRepository.remove(_posMasters);
await this.child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.orgRootRepository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.orgRevisionRepository.remove(_orgRevisions);
return new HttpSuccess(revision);
2024-01-26 16:41:52 +07:00
}
2024-01-26 17:03:41 +07:00
/**
* API
*
* @summary ORG_023 - (ADMIN) #25
*
*/
2024-01-29 10:23:58 +07:00
@Get("{id}")
2024-08-19 17:58:33 +07:00
async detail(@Path() id: string, @Request() request: RequestWithUser) {
2024-08-20 13:37:41 +07:00
let _data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
2024-08-20 15:49:59 +07:00
};
if (!request.user.role.includes("SUPER_ADMIN")) {
_data = await new permission().PermissionOrgList(request, "SYS_ORG");
2024-08-20 13:37:41 +07:00
}
2024-02-28 14:48:41 +07:00
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
2024-09-06 08:03:53 +07:00
2024-02-28 14:48:41 +07:00
const orgRootData = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id })
2024-08-19 17:58:33 +07:00
.andWhere(
2024-08-29 14:41:48 +07:00
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `orgRoot.id IN (:...node)`
: `orgRoot.id is null`
: "1=1",
2024-08-19 17:58:33 +07:00
{
node: _data.root,
},
)
2024-02-28 14:48:41 +07:00
.select([
"orgRoot.id",
"orgRoot.orgRootName",
"orgRoot.orgRootShortName",
"orgRoot.orgRootCode",
"orgRoot.orgRootOrder",
"orgRoot.orgRootPhoneEx",
"orgRoot.orgRootPhoneIn",
"orgRoot.orgRootFax",
"orgRoot.orgRevisionId",
"orgRoot.orgRootRank",
2024-03-13 09:47:19 +07:00
"orgRoot.orgRootRankSub",
2024-05-15 12:28:58 +07:00
"orgRoot.responsibility",
2024-02-28 14:48:41 +07:00
])
.orderBy("orgRoot.orgRootOrder", "ASC")
.getMany();
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
const orgChild1Data =
orgRootIds && orgRootIds.length > 0
? await AppDataSource.getRepository(OrgChild1)
.createQueryBuilder("orgChild1")
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
2024-08-19 17:58:33 +07:00
.andWhere(
_data.child1 != undefined && _data.child1 != null
2024-08-29 14:41:48 +07:00
? _data.child1[0] != null
? `orgChild1.id IN (:...node)`
: `orgChild1.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child1,
},
)
2024-02-28 14:48:41 +07:00
.select([
"orgChild1.id",
"orgChild1.orgChild1Name",
"orgChild1.orgChild1ShortName",
"orgChild1.orgChild1Code",
"orgChild1.orgChild1Order",
"orgChild1.orgChild1PhoneEx",
"orgChild1.orgChild1PhoneIn",
"orgChild1.orgChild1Fax",
"orgChild1.orgRootId",
"orgChild1.orgChild1Rank",
2024-03-13 09:47:19 +07:00
"orgChild1.orgChild1RankSub",
2024-05-15 12:28:58 +07:00
"orgChild1.responsibility",
2024-02-28 14:48:41 +07:00
])
.orderBy("orgChild1.orgChild1Order", "ASC")
.getMany()
: [];
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
const orgChild2Data =
orgChild1Ids && orgChild1Ids.length > 0
? await AppDataSource.getRepository(OrgChild2)
.createQueryBuilder("orgChild2")
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
2024-08-19 17:58:33 +07:00
.andWhere(
_data.child2 != undefined && _data.child2 != null
2024-08-29 14:41:48 +07:00
? _data.child2[0] != null
? `orgChild2.id IN (:...node)`
: `orgChild2.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child2,
},
)
2024-02-28 14:48:41 +07:00
.select([
"orgChild2.id",
"orgChild2.orgChild2Name",
"orgChild2.orgChild2ShortName",
"orgChild2.orgChild2Code",
"orgChild2.orgChild2Order",
"orgChild2.orgChild2PhoneEx",
"orgChild2.orgChild2PhoneIn",
"orgChild2.orgChild2Fax",
"orgChild2.orgRootId",
"orgChild2.orgChild2Rank",
2024-03-13 09:47:19 +07:00
"orgChild2.orgChild2RankSub",
2024-02-28 14:48:41 +07:00
"orgChild2.orgChild1Id",
2024-05-15 12:28:58 +07:00
"orgChild2.responsibility",
2024-02-28 14:48:41 +07:00
])
.orderBy("orgChild2.orgChild2Order", "ASC")
.getMany()
: [];
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
const orgChild3Data =
orgChild2Ids && orgChild2Ids.length > 0
? await AppDataSource.getRepository(OrgChild3)
.createQueryBuilder("orgChild3")
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
2024-08-19 17:58:33 +07:00
.andWhere(
_data.child3 != undefined && _data.child3 != null
2024-08-29 14:41:48 +07:00
? _data.child3[0] != null
? `orgChild3.id IN (:...node)`
: `orgChild3.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child3,
},
)
2024-02-28 14:48:41 +07:00
.select([
"orgChild3.id",
"orgChild3.orgChild3Name",
"orgChild3.orgChild3ShortName",
"orgChild3.orgChild3Code",
"orgChild3.orgChild3Order",
"orgChild3.orgChild3PhoneEx",
"orgChild3.orgChild3PhoneIn",
"orgChild3.orgChild3Fax",
"orgChild3.orgRootId",
"orgChild3.orgChild3Rank",
2024-03-13 09:47:19 +07:00
"orgChild3.orgChild3RankSub",
2024-02-28 14:48:41 +07:00
"orgChild3.orgChild2Id",
2024-05-15 12:28:58 +07:00
"orgChild3.responsibility",
2024-02-28 14:48:41 +07:00
])
.orderBy("orgChild3.orgChild3Order", "ASC")
.getMany()
: [];
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
const orgChild4Data =
orgChild3Ids && orgChild3Ids.length > 0
? await AppDataSource.getRepository(OrgChild4)
.createQueryBuilder("orgChild4")
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
2024-08-19 17:58:33 +07:00
.andWhere(
_data.child4 != undefined && _data.child4 != null
2024-08-29 14:41:48 +07:00
? _data.child4[0] != null
? `orgChild4.id IN (:...node)`
: `orgChild4.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child4,
},
)
2024-02-28 14:48:41 +07:00
.select([
"orgChild4.id",
"orgChild4.orgChild4Name",
"orgChild4.orgChild4ShortName",
"orgChild4.orgChild4Code",
"orgChild4.orgChild4Order",
"orgChild4.orgChild4PhoneEx",
"orgChild4.orgChild4PhoneIn",
"orgChild4.orgChild4Fax",
"orgChild4.orgRootId",
"orgChild4.orgChild4Rank",
2024-03-13 09:47:19 +07:00
"orgChild4.orgChild4RankSub",
2024-02-28 14:48:41 +07:00
"orgChild4.orgChild3Id",
2024-05-15 12:28:58 +07:00
"orgChild4.responsibility",
2024-02-28 14:48:41 +07:00
])
.orderBy("orgChild4.orgChild4Order", "ASC")
.getMany()
: [];
// const formattedData = orgRootData.map((orgRoot) => {
const formattedData = await Promise.all(
orgRootData.map(async (orgRoot) => {
return {
orgTreeId: orgRoot.id,
orgLevel: 0,
orgName: orgRoot.orgRootName,
orgTreeName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName,
orgTreeCode: orgRoot.orgRootCode,
orgCode: orgRoot.orgRootCode + "00",
orgTreeRank: orgRoot.orgRootRank,
2024-03-13 09:47:19 +07:00
orgTreeRankSub: orgRoot.orgRootRankSub,
2024-02-28 14:48:41 +07:00
orgTreeOrder: orgRoot.orgRootOrder,
orgTreePhoneEx: orgRoot.orgRootPhoneEx,
orgTreePhoneIn: orgRoot.orgRootPhoneIn,
orgTreeFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgRoot.responsibility,
2024-03-13 09:47:19 +07:00
labelName:
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
2024-02-28 14:48:41 +07:00
totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild1Data
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
.map(async (orgChild1) => ({
orgTreeId: orgChild1.id,
orgRootId: orgRoot.id,
2024-02-28 14:48:41 +07:00
orgLevel: 1,
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild1.orgChild1Name,
orgTreeShortName: orgChild1.orgChild1ShortName,
orgTreeCode: orgChild1.orgChild1Code,
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
orgTreeRank: orgChild1.orgChild1Rank,
2024-03-13 09:47:19 +07:00
orgTreeRankSub: orgChild1.orgChild1RankSub,
2024-02-28 14:48:41 +07:00
orgTreeOrder: orgChild1.orgChild1Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
orgTreeFax: orgChild1.orgChild1Fax,
2024-02-09 22:55:42 +07:00
orgRevisionId: orgRoot.orgRevisionId,
2024-02-28 14:48:41 +07:00
orgRootName: orgRoot.orgRootName,
2024-07-08 11:06:40 +07:00
responsibility: orgChild1.responsibility,
2024-03-13 09:47:19 +07:00
labelName:
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName,
2024-02-28 14:48:41 +07:00
totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
children: await Promise.all(
orgChild2Data
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
.map(async (orgChild2) => ({
orgTreeId: orgChild2.id,
orgRootId: orgChild1.id,
orgLevel: 2,
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild2.orgChild2Name,
orgTreeShortName: orgChild2.orgChild2ShortName,
orgTreeCode: orgChild2.orgChild2Code,
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgTreeRank: orgChild2.orgChild2Rank,
2024-03-13 09:47:19 +07:00
orgTreeRankSub: orgChild2.orgChild2RankSub,
2024-02-28 14:48:41 +07:00
orgTreeOrder: orgChild2.orgChild2Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
orgTreeFax: orgChild2.orgChild2Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
2024-07-08 11:06:40 +07:00
responsibility: orgChild2.responsibility,
2024-03-13 09:47:19 +07:00
labelName:
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName,
2024-02-28 14:48:41 +07:00
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild3Data
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
.map(async (orgChild3) => ({
orgTreeId: orgChild3.id,
orgRootId: orgChild2.id,
orgLevel: 3,
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild3.orgChild3Name,
orgTreeShortName: orgChild3.orgChild3ShortName,
orgTreeCode: orgChild3.orgChild3Code,
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
orgTreeRank: orgChild3.orgChild3Rank,
2024-03-13 09:47:19 +07:00
orgTreeRankSub: orgChild3.orgChild3RankSub,
2024-02-28 14:48:41 +07:00
orgTreeOrder: orgChild3.orgChild3Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
orgTreeFax: orgChild3.orgChild3Fax,
2024-02-09 22:55:42 +07:00
orgRevisionId: orgRoot.orgRevisionId,
2024-02-28 14:48:41 +07:00
orgRootName: orgRoot.orgRootName,
2024-07-08 11:06:40 +07:00
responsibility: orgChild3.responsibility,
2024-03-13 09:47:19 +07:00
labelName:
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName,
2024-02-28 14:48:41 +07:00
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
children: await Promise.all(
orgChild4Data
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
orgRootId: orgChild3.id,
orgLevel: 4,
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild4.orgChild4Name,
orgTreeShortName: orgChild4.orgChild4ShortName,
orgTreeCode: orgChild4.orgChild4Code,
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
orgTreeRank: orgChild4.orgChild4Rank,
2024-03-13 09:47:19 +07:00
orgTreeRankSub: orgChild4.orgChild4RankSub,
2024-02-28 14:48:41 +07:00
orgTreeOrder: orgChild4.orgChild4Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
orgTreeFax: orgChild4.orgChild4Fax,
2024-02-06 16:23:33 +07:00
orgRevisionId: orgRoot.orgRevisionId,
2024-02-28 14:48:41 +07:00
orgRootName: orgRoot.orgRootName,
2024-07-08 11:06:40 +07:00
responsibility: orgChild4.responsibility,
2024-03-13 09:47:19 +07:00
labelName:
orgChild4.orgChild4Name +
" " +
orgRoot.orgRootCode +
orgChild4.orgChild4Code +
" " +
orgChild4.orgChild4ShortName,
2024-02-28 14:48:41 +07:00
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count(
{
2024-02-02 10:15:03 +07:00
where: {
2024-02-06 16:23:33 +07:00
orgRevisionId: orgRoot.orgRevisionId,
2024-02-28 14:48:41 +07:00
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
2024-02-02 10:15:03 +07:00
orgChild4Id: orgChild4.id,
current_holderId: Not(IsNull()) || Not(""),
2024-02-02 10:15:03 +07:00
},
2024-02-28 14:48:41 +07:00
},
),
totalRootPositionCurrentVacant:
await this.posMasterRepository.count({
2024-02-09 22:55:42 +07:00
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
2024-02-09 22:55:42 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
2024-02-28 14:48:41 +07:00
current_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count(
{
2024-02-09 22:55:42 +07:00
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
2024-02-09 22:55:42 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
2024-02-28 14:48:41 +07:00
next_holderId: IsNull() || "",
},
2024-02-28 14:48:41 +07:00
},
),
})),
),
})),
),
})),
),
})),
),
};
}),
);
return new HttpSuccess(formattedData);
2024-01-29 10:23:58 +07:00
}
/**
* API
*
* @summary ORG_025 - (ADMIN) #27
*
* @param {string} id Id revison
*/
@Put("/set/publish/{id}")
async Edit(
@Path() id: string,
@Body() requestBody: { orgPublishDate: Date },
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_ORG");//ไม่แน่ใจOFFปิดไว้ก่อน
const orgRevision = await this.orgRevisionRepository.findOne({
where: {
id: id,
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
},
});
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
}
2024-02-28 14:48:41 +07:00
orgRevision.lastUpdateUserId = request.user.sub;
orgRevision.lastUpdateFullName = request.user.name;
orgRevision.lastUpdatedAt = new Date();
orgRevision.orgPublishDate = requestBody.orgPublishDate;
this.orgRevisionRepository.merge(orgRevision, requestBody);
await this.orgRevisionRepository.save(orgRevision);
return new HttpSuccess();
}
/**
2024-01-31 14:29:39 +07:00
* API
*
2024-01-31 14:29:39 +07:00
* @summary ORG_039 - (ADMIN) #42
*
*/
2024-01-31 17:20:08 +07:00
@Post("/history/publish")
async GetHistoryPublish(
@Body()
requestBody: {
id: string;
type: number;
},
@Request() request: { user: Record<string, any> },
) {
if (requestBody.type == 1) {
const orgChild1 = await this.child1Repository.findOne({
2024-01-31 17:20:08 +07:00
where: { id: requestBody.id },
});
if (!orgChild1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1");
}
2024-02-01 11:34:13 +07:00
const datas = await this.child1Repository
.createQueryBuilder("child1")
2024-02-01 13:29:15 +07:00
.where("child1.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild1.ancestorDNA })
.andWhere("child1.ancestorDNA <> :nullUUID", {
2024-02-01 11:34:13 +07:00
nullUUID: "00000000-0000-0000-0000-000000000000",
})
2024-02-01 13:29:15 +07:00
.andWhere("child1.ancestorDNA IS NOT NULL")
2024-02-01 11:34:13 +07:00
.leftJoinAndSelect("child1.orgRevision", "orgRevision")
.orderBy("child1.lastUpdatedAt", "DESC")
.getMany();
2024-01-31 14:29:39 +07:00
const _data = datas.map((item) => ({
id: item.id,
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
name: item.orgChild1Name,
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
2024-01-31 17:20:08 +07:00
} else if (requestBody.type == 2) {
const orgChild2 = await this.child2Repository.findOne({
2024-01-31 17:20:08 +07:00
where: { id: requestBody.id },
});
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2");
}
2024-02-01 11:34:13 +07:00
const datas = await this.child2Repository
.createQueryBuilder("child2")
2024-02-01 13:29:15 +07:00
.where("child2.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild2.ancestorDNA })
.andWhere("child2.ancestorDNA <> :nullUUID", {
2024-02-01 11:34:13 +07:00
nullUUID: "00000000-0000-0000-0000-000000000000",
})
2024-02-01 13:29:15 +07:00
.andWhere("child2.ancestorDNA IS NOT NULL")
2024-02-01 11:34:13 +07:00
.leftJoinAndSelect("child2.orgRevision", "orgRevision")
.orderBy("child2.lastUpdatedAt", "DESC")
.getMany();
2024-01-31 14:29:39 +07:00
const _data = datas.map((item) => ({
id: item.id,
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
name: item.orgChild2Name,
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
2024-01-31 17:20:08 +07:00
} else if (requestBody.type == 3) {
const orgChild3 = await this.child3Repository.findOne({
2024-01-31 17:20:08 +07:00
where: { id: requestBody.id },
});
if (!orgChild3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3");
}
2024-02-01 11:34:13 +07:00
const datas = await this.child3Repository
.createQueryBuilder("child3")
2024-02-01 13:29:15 +07:00
.where("child3.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild3.ancestorDNA })
.andWhere("child3.ancestorDNA <> :nullUUID", {
2024-02-01 11:34:13 +07:00
nullUUID: "00000000-0000-0000-0000-000000000000",
})
2024-02-01 13:29:15 +07:00
.andWhere("child3.ancestorDNA IS NOT NULL")
2024-02-01 11:34:13 +07:00
.leftJoinAndSelect("child3.orgRevision", "orgRevision")
.orderBy("child3.lastUpdatedAt", "DESC")
.getMany();
2024-01-31 14:29:39 +07:00
const _data = datas.map((item) => ({
id: item.id,
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
name: item.orgChild3Name,
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
2024-01-31 17:20:08 +07:00
} else if (requestBody.type == 4) {
const orgChild4 = await this.child4Repository.findOne({
2024-01-31 17:20:08 +07:00
where: { id: requestBody.id },
});
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child4");
}
2024-02-01 11:34:13 +07:00
const datas = await this.child4Repository
.createQueryBuilder("child4")
2024-02-01 13:29:15 +07:00
.where("child4.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild4.ancestorDNA })
.andWhere("child4.ancestorDNA <> :nullUUID", {
2024-02-01 11:34:13 +07:00
nullUUID: "00000000-0000-0000-0000-000000000000",
})
2024-02-01 13:29:15 +07:00
.andWhere("child4.ancestorDNA IS NOT NULL")
2024-02-01 11:34:13 +07:00
.leftJoinAndSelect("child4.orgRevision", "orgRevision")
.orderBy("child4.lastUpdatedAt", "DESC")
.getMany();
2024-01-31 14:29:39 +07:00
const _data = datas.map((item) => ({
id: item.id,
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
name: item.orgChild4Name,
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
} else {
const orgRoot = await this.orgRootRepository.findOne({
2024-01-31 17:20:08 +07:00
where: { id: requestBody.id },
});
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
}
2024-02-01 11:34:13 +07:00
const datas = await this.orgRootRepository
.createQueryBuilder("root")
2024-02-01 13:29:15 +07:00
.where("root.ancestorDNA = :ancestorDNA", { ancestorDNA: orgRoot.ancestorDNA })
.andWhere("root.ancestorDNA <> :nullUUID", {
2024-02-01 11:34:13 +07:00
nullUUID: "00000000-0000-0000-0000-000000000000",
})
2024-02-01 13:29:15 +07:00
.andWhere("root.ancestorDNA IS NOT NULL")
2024-02-01 11:34:13 +07:00
.leftJoinAndSelect("root.orgRevision", "orgRevision")
.orderBy("root.lastUpdatedAt", "DESC")
.getMany();
2024-01-31 14:29:39 +07:00
const _data = datas.map((item) => ({
id: item.id,
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
name: item.orgRootName,
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
}
}
/**
* API
*
* @summary ORG_038 - (ADMIN) #41
*
*/
@Post("sort")
2024-08-19 17:58:33 +07:00
async Sort(
@Body() requestBody: { id: string; type: number; sortId: string[] },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_ORG");
2024-02-28 14:48:41 +07:00
switch (requestBody.type) {
case 0: {
const revisionId = await this.orgRevisionRepository.findOne({
where: { id: requestBody.id },
});
if (!revisionId?.id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revisionId: " + requestBody.id);
}
2024-02-28 14:48:41 +07:00
const listRootId = await this.orgRootRepository.find({
where: { orgRevisionId: requestBody.id },
select: ["id", "orgRootOrder"],
});
if (!listRootId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
}
2024-02-28 14:48:41 +07:00
const sortData = listRootId.map((data) => ({
id: data.id,
orgRootOrder: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.orgRootRepository.save(sortData);
break;
}
2024-02-28 14:48:41 +07:00
case 1: {
const rootId = await this.orgRootRepository.findOne({ where: { id: requestBody.id } });
if (!rootId?.id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId: " + requestBody.id);
}
2024-02-28 14:48:41 +07:00
const listChild1Id = await this.child1Repository.find({
where: { orgRootId: requestBody.id },
select: ["id", "orgChild1Order"],
});
if (!listChild1Id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id.");
}
const sortData = listChild1Id.map((data) => ({
id: data.id,
orgChild1Order: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.child1Repository.save(sortData);
break;
}
2024-02-28 14:48:41 +07:00
case 2: {
const child1Id = await this.child1Repository.findOne({ where: { id: requestBody.id } });
if (!child1Id?.id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id: " + requestBody.id);
}
const listChild2Id = await this.child2Repository.find({
where: { orgChild1Id: requestBody.id },
select: ["id", "orgChild2Order"],
});
if (!listChild2Id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id.");
}
2024-02-28 14:48:41 +07:00
const sortData = listChild2Id.map((data) => ({
id: data.id,
orgChild2Order: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.child2Repository.save(sortData);
break;
}
2024-02-28 14:48:41 +07:00
case 3: {
const child2Id = await this.child2Repository.findOne({ where: { id: requestBody.id } });
if (!child2Id?.id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id: " + requestBody.id);
}
const listChild3Id = await this.child3Repository.find({
where: { orgChild2Id: requestBody.id },
select: ["id", "orgChild3Order"],
});
if (!listChild3Id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id.");
}
2024-02-28 14:48:41 +07:00
const sortData = listChild3Id.map((data) => ({
id: data.id,
orgChild3Order: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.child3Repository.save(sortData);
break;
}
2024-01-31 18:24:38 +07:00
2024-02-28 14:48:41 +07:00
case 4: {
const child3Id = await this.child3Repository.findOne({ where: { id: requestBody.id } });
if (!child3Id?.id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id: " + requestBody.id);
}
const listChild4Id = await this.child4Repository.find({
where: { orgChild3Id: requestBody.id },
select: ["id", "orgChild4Order"],
});
if (!listChild4Id) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id.");
}
const sortData = listChild4Id.map((data) => ({
id: data.id,
orgChild4Order: requestBody.sortId.indexOf(data.id) + 1,
}));
await this.child4Repository.save(sortData);
break;
}
2024-02-28 14:48:41 +07:00
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.type);
}
return new HttpSuccess();
}
2024-02-01 13:29:15 +07:00
/**
* API
*
2024-02-20 16:01:05 +07:00
* @summary ORG_071 - (ADMIN) #57
2024-02-01 13:29:15 +07:00
*
* @param {string} id Id revison
*/
2024-06-19 23:03:54 +07:00
@Get("get/publish")
2024-06-25 10:21:30 +07:00
async runPublish(@Request() request: { user: Record<string, any> }) {
2024-02-01 13:29:15 +07:00
const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
const orgRevisionPublish = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const orgRevisionDraft = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
// .andWhere("DATE(orgRevision.orgPublishDate) = :today", { today })
2024-02-01 13:29:15 +07:00
.getOne();
if (!orgRevisionDraft) {
return new HttpSuccess();
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่มีข้อมูลเผยแพร่");
}
if (orgRevisionPublish) {
orgRevisionPublish.orgRevisionIsDraft = false;
orgRevisionPublish.orgRevisionIsCurrent = false;
await this.orgRevisionRepository.save(orgRevisionPublish);
}
orgRevisionDraft.orgRevisionIsCurrent = true;
orgRevisionDraft.orgRevisionIsDraft = false;
await this.orgRevisionRepository.save(orgRevisionDraft);
2024-02-09 22:55:42 +07:00
const posMaster = await this.posMasterRepository.find({
where: { orgRevisionId: orgRevisionDraft.id },
2024-06-25 10:21:30 +07:00
relations: [
"orgRoot",
"orgChild4",
"orgChild3",
"orgChild2",
"orgChild1",
"positions",
"positions.posLevel",
"positions.posType",
"positions.posExecutive",
],
2024-02-09 22:55:42 +07:00
});
2024-06-25 10:21:30 +07:00
await Promise.all(
posMaster.map(async (item) => {
// if(item.next_holderId != null){
if (item.next_holderId != null) {
const profile = await this.profileRepo.findOne({
where: { id: item.next_holderId == null ? "" : item.next_holderId },
});
const position = await item.positions.find((x) => x.positionIsSelected == true);
const _null: any = null;
if (profile != null) {
profile.posLevelId = position?.posLevelId ?? _null;
profile.posTypeId = position?.posTypeId ?? _null;
profile.position = position?.positionName ?? _null;
await this.profileRepo.save(profile);
}
const profileSalary = await this.salaryRepository.findOne({
where: { profileId: item.next_holderId },
order: { createdAt: "DESC" },
});
const shortName =
item != null && item.orgChild4 != null
? `${item.orgChild4.orgChild4ShortName}${item.posMasterNo}`
: item != null && item?.orgChild3 != null
? `${item.orgChild3.orgChild3ShortName}${item.posMasterNo}`
: item != null && item?.orgChild2 != null
? `${item.orgChild2.orgChild2ShortName}${item.posMasterNo}`
: item != null && item?.orgChild1 != null
? `${item.orgChild1.orgChild1ShortName}${item.posMasterNo}`
: item != null && item?.orgRoot != null
? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
: null;
2024-08-07 17:49:28 +07:00
await new CallAPI().PostData(request, "/org/profile/salary", {
profileId: item.next_holderId,
date: new Date(),
amount: profileSalary?.amount ?? null,
positionSalaryAmount: profileSalary?.positionSalaryAmount ?? null,
mouthSalaryAmount: profileSalary?.mouthSalaryAmount ?? null,
posNo: shortName,
position: position?.positionName ?? _null,
positionLine: position?.positionField ?? _null,
positionPathSide: position?.positionArea ?? _null,
positionExecutive: position?.posExecutive?.posExecutiveName ?? _null,
positionType: position?.posType?.posTypeName ?? _null,
positionLevel: position?.posLevel?.posLevelName ?? _null,
refCommandNo: null,
templateDoc: "ปรับโครงสร้าง",
});
2024-06-25 10:21:30 +07:00
}
item.current_holderId = item.next_holderId;
item.next_holderId = null;
await this.posMasterRepository.save(item);
// }
}),
);
2024-02-01 13:29:15 +07:00
return new HttpSuccess();
}
2024-02-07 15:45:13 +07:00
/**
* Cronjob
*/
async cronjobRevision() {
const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
const orgRevisionPublish = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const orgRevisionDraft = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
.andWhere("DATE(orgRevision.orgPublishDate) = :today", { today })
.getOne();
if (!orgRevisionDraft) {
return new HttpSuccess();
}
if (orgRevisionPublish) {
orgRevisionPublish.orgRevisionIsDraft = false;
orgRevisionPublish.orgRevisionIsCurrent = false;
await this.orgRevisionRepository.save(orgRevisionPublish);
}
orgRevisionDraft.orgRevisionIsCurrent = true;
orgRevisionDraft.orgRevisionIsDraft = false;
await this.orgRevisionRepository.save(orgRevisionDraft);
const posMaster = await this.posMasterRepository.find({
where: { orgRevisionId: orgRevisionDraft.id },
});
posMaster.forEach(async (item) => {
// if(item.next_holderId != null){
2024-02-09 22:55:42 +07:00
item.current_holderId = item.next_holderId;
item.next_holderId = null;
await this.posMasterRepository.save(item);
// }
});
2024-02-09 22:55:42 +07:00
2024-02-07 15:45:13 +07:00
return new HttpSuccess();
}
2024-02-14 12:18:24 +07:00
/**
* API Organizational Chart
*
* @summary Organizational Chart
*
* @param {string} revisionId Id revison
*/
@Get("org-chart/{revisionId}")
async orgchart(@Path() revisionId: string) {
const data = await this.orgRevisionRepository.findOne({
where: { id: revisionId },
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
}
let posMasterRoot: any;
let posMasterChild1: any;
let posMasterChild2: any;
let posMasterChild3: any;
let posMasterChild4: any;
if (data.orgRevisionIsCurrent == true && data.orgRevisionIsDraft == false) {
posMasterRoot = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild1Id: IsNull(),
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
posMasterChild1 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild2Id: IsNull(),
orgChild1Id: Not(IsNull()),
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgChild1"],
});
posMasterChild2 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild3Id: IsNull(),
orgChild2Id: Not(IsNull()),
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgChild2"],
});
posMasterChild3 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild4Id: IsNull(),
orgChild3Id: Not(IsNull()),
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgChild3"],
});
posMasterChild4 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild4Id: Not(IsNull()),
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgChild4"],
});
let formattedData = posMasterRoot
.filter((x: any) => x.current_holderId != null)
.map((x0: PosMaster) => ({
personID: x0.current_holder.id,
name: x0.current_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x0.current_holder &&
x0.current_holder.avatar != null &&
x0.current_holder.avatarName != null
? `${x0.current_holder.avatar}/${x0.current_holder.avatarName}`
: null,
positionName: x0.current_holder.position,
positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo,
positionNumInt: x0.posMasterNo,
departmentName: x0.orgRoot.orgRootName,
organizationId: x0.orgRoot.id,
children: posMasterChild1
.filter((x: any) => x.current_holderId != null && x.orgRootId == x0.orgRootId)
.map((x1: PosMaster) => ({
personID: x1.current_holder.id,
name: x1.current_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x1.current_holder &&
x1.current_holder.avatar != null &&
x1.current_holder.avatarName != null
? `${x1.current_holder.avatar}/${x1.current_holder.avatarName}`
: null,
positionName: x1.current_holder.position,
positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo,
positionNumInt: x1.posMasterNo,
departmentName: x1.orgChild1.orgChild1Name,
organizationId: x1.orgChild1.id,
children: posMasterChild2
.filter((x: any) => x.current_holderId != null && x.child1Id == x1.orgChild1Id)
.map((x2: PosMaster) => ({
personID: x2.current_holder.id,
name: x2.current_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x2.current_holder &&
x2.current_holder.avatar != null &&
x2.current_holder.avatarName != null
? `${x2.current_holder.avatar}/${x2.current_holder.avatarName}`
: null,
positionName: x2.current_holder.position,
positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo,
positionNumInt: x2.posMasterNo,
departmentName: x2.orgChild2.orgChild2Name,
organizationId: x2.orgChild2.id,
children: posMasterChild3
.filter((x: any) => x.current_holderId != null && x.child2Id == x2.orgChild2Id)
.map((x3: PosMaster) => ({
personID: x3.current_holder.id,
name: x3.current_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x3.current_holder &&
x3.current_holder.avatar != null &&
x3.current_holder.avatarName != null
? `${x3.current_holder.avatar}/${x3.current_holder.avatarName}`
: null,
positionName: x3.current_holder.position,
positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo,
positionNumInt: x3.posMasterNo,
departmentName: x3.orgChild3.orgChild3Name,
organizationId: x3.orgChild3.id,
children: posMasterChild4
.filter(
(x: any) => x.current_holderId != null && x.child3Id == x3.orgChild3Id,
)
.map((x4: PosMaster) => ({
personID: x4.current_holder.id,
name: x4.current_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x4.current_holder &&
x4.current_holder.avatar != null &&
x4.current_holder.avatarName != null
? `${x4.current_holder.avatar}/${x4.current_holder.avatarName}`
: null,
positionName: x4.current_holder.position,
positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo,
positionNumInt: x4.posMasterNo,
departmentName: x4.orgChild4.orgChild4Name,
organizationId: x4.orgChild4.id,
})),
})),
})),
})),
}));
const formattedData_ = {
personID: "",
name: "",
avatar: "",
positionName: "",
positionNum: "",
positionNumInt: null,
departmentName: data.orgRevisionName,
organizationId: data.id,
children: formattedData,
};
return new HttpSuccess([formattedData_]);
} else if (data.orgRevisionIsCurrent == false && data.orgRevisionIsDraft == true) {
posMasterRoot = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild1Id: IsNull(),
next_holderId: Not(IsNull()),
},
relations: ["next_holder", "orgRoot"],
});
posMasterChild1 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild2Id: IsNull(),
orgChild1Id: Not(IsNull()),
next_holderId: Not(IsNull()),
},
relations: ["next_holder", "orgChild1"],
});
posMasterChild2 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild3Id: IsNull(),
orgChild2Id: Not(IsNull()),
next_holderId: Not(IsNull()),
},
relations: ["next_holder", "orgChild2"],
});
posMasterChild3 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild4Id: IsNull(),
orgChild3Id: Not(IsNull()),
next_holderId: Not(IsNull()),
},
relations: ["next_holder", "orgChild3"],
});
posMasterChild4 = await this.posMasterRepository.find({
where: {
orgRevisionId: data.id,
orgChild4Id: Not(IsNull()),
next_holderId: Not(IsNull()),
},
relations: ["next_holder", "orgChild4"],
});
let formattedData = posMasterRoot
.filter((x: any) => x.next_holderId != null)
.map((x0: PosMaster) => ({
personID: x0.next_holder.id,
name: x0.next_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x0.next_holder && x0.next_holder.avatar != null && x0.next_holder.avatarName != null
? `${x0.next_holder.avatar}/${x0.next_holder.avatarName}`
: null,
positionName: x0.next_holder.position,
positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo,
positionNumInt: x0.posMasterNo,
departmentName: x0.orgRoot.orgRootName,
organizationId: x0.orgRoot.id,
children: posMasterChild1
.filter((x: any) => x.next_holderId != null && x.orgRootId == x0.orgRootId)
.map((x1: PosMaster) => ({
personID: x1.next_holder.id,
name: x1.next_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x1.next_holder && x1.next_holder.avatar != null && x1.next_holder.avatarName != null
? `${x1.next_holder.avatar}/${x1.next_holder.avatarName}`
: null,
positionName: x1.next_holder.position,
positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo,
positionNumInt: x1.posMasterNo,
departmentName: x1.orgChild1.orgChild1Name,
organizationId: x1.orgChild1.id,
children: posMasterChild2
.filter((x: any) => x.next_holderId != null && x.child1Id == x1.orgChild1Id)
.map((x2: PosMaster) => ({
personID: x2.next_holder.id,
name: x2.next_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x2.next_holder &&
x2.next_holder.avatar != null &&
x2.next_holder.avatarName != null
? `${x2.next_holder.avatar}/${x2.next_holder.avatarName}`
: null,
positionName: x2.next_holder.position,
positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo,
positionNumInt: x2.posMasterNo,
departmentName: x2.orgChild2.orgChild2Name,
organizationId: x2.orgChild2.id,
children: posMasterChild3
.filter((x: any) => x.next_holderId != null && x.child2Id == x2.orgChild2Id)
.map((x3: PosMaster) => ({
personID: x3.next_holder.id,
name: x3.next_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x3.next_holder &&
x3.next_holder.avatar != null &&
x3.next_holder.avatarName != null
? `${x3.next_holder.avatar}/${x3.next_holder.avatarName}`
: null,
positionName: x3.next_holder.position,
positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo,
positionNumInt: x3.posMasterNo,
departmentName: x3.orgChild3.orgChild3Name,
organizationId: x3.orgChild3.id,
children: posMasterChild4
.filter((x: any) => x.next_holderId != null && x.child3Id == x3.orgChild3Id)
.map((x4: PosMaster) => ({
personID: x4.next_holder.id,
name: x4.next_holder.firstName,
2024-08-20 15:49:59 +07:00
avatar:
x4.next_holder &&
x4.next_holder.avatar != null &&
x4.next_holder.avatarName != null
? `${x4.next_holder.avatar}/${x4.next_holder.avatarName}`
: null,
positionName: x4.next_holder.position,
positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo,
positionNumInt: x4.posMasterNo,
departmentName: x4.orgChild4.orgChild4Name,
organizationId: x4.orgChild4.id,
})),
})),
})),
})),
}));
const formattedData_ = {
personID: "",
name: "",
avatar: "",
positionName: "",
positionNum: "",
positionNumInt: null,
departmentName: data.orgRevisionName,
organizationId: data.id,
children: formattedData,
};
return new HttpSuccess([formattedData_]);
} else {
return new HttpSuccess([
{
personID: "",
name: "",
avatar: "",
positionName: "",
positionNum: "",
positionNumInt: null,
departmentName: data.orgRevisionName,
organizationId: data.id,
children: [],
},
]);
}
}
2024-02-14 12:18:24 +07:00
/**
* API Organizational StructChart
*
* @summary Organizational StructChart
*
*/
2024-04-19 14:48:17 +07:00
@Get("struct-chart/{idNode}/{type}")
2024-02-14 12:18:24 +07:00
async structchart(@Path() idNode: string, type: number) {
2024-02-28 14:48:41 +07:00
switch (type) {
case 0: {
const data = await this.orgRevisionRepository.findOne({
where: { id: idNode },
relations: [
"orgRoots",
"orgRoots.orgChild1s",
"orgRoots.orgChild1s.orgChild2s",
"orgRoots.orgChild1s.orgChild2s.orgChild3s",
"orgRoots.orgChild1s.orgChild2s.orgChild3s.orgChild4s",
],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revision");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgRevisionName,
deptID: data.id,
type: 0,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRevisionId: data.id },
}),
totalPositionVacant:
data.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
data.orgRoots
.sort((a, b) => a.orgRootOrder - b.orgRootOrder)
.map(async (orgRoot: OrgRoot) => {
return {
departmentName: orgRoot.orgRootName,
deptID: orgRoot.id,
type: 1,
2024-02-15 08:56:26 +07:00
// heads:
totalPositionCount: await this.posMasterRepository.count({
2024-02-28 14:48:41 +07:00
where: { orgRevisionId: data.id, orgRootId: orgRoot.id },
2024-02-15 08:56:26 +07:00
}),
totalPositionVacant:
2024-02-28 14:48:41 +07:00
data.orgRevisionIsDraft == true
2024-02-15 08:56:26 +07:00
? await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
current_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// next_holderId: IsNull() || "",
// },
// }),
2024-02-15 08:56:26 +07:00
children: await Promise.all(
2024-02-28 14:48:41 +07:00
orgRoot.orgChild1s
.sort((a, b) => a.orgChild1Order - b.orgChild1Order)
.map(async (orgChild1) => ({
departmentName: orgChild1.orgChild1Name,
deptID: orgChild1.id,
type: 2,
2024-02-15 08:56:26 +07:00
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
},
}),
2024-02-28 14:48:41 +07:00
totalPositionVacant:
data.orgRevisionIsDraft == true
2024-02-15 08:56:26 +07:00
? await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
current_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// next_holderId: IsNull() || "",
// },
// }),
2024-02-15 08:56:26 +07:00
children: await Promise.all(
2024-02-28 14:48:41 +07:00
orgChild1.orgChild2s
.sort((a, b) => a.orgChild2Order - b.orgChild2Order)
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
2024-02-15 08:56:26 +07:00
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
},
}),
totalPositionVacant:
2024-02-28 14:48:41 +07:00
data.orgRevisionIsDraft == true
2024-02-15 08:56:26 +07:00
? await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
current_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// next_holderId: IsNull() || "",
// },
// }),
2024-02-15 08:56:26 +07:00
children: await Promise.all(
2024-02-28 14:48:41 +07:00
orgChild2.orgChild3s
.sort((a, b) => a.orgChild3Order - b.orgChild3Order)
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
2024-02-15 08:56:26 +07:00
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
},
}),
totalPositionVacant:
2024-02-28 14:48:41 +07:00
data.orgRevisionIsDraft == true
2024-02-15 08:56:26 +07:00
? await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
2024-02-28 14:48:41 +07:00
orgRevisionId: data.id,
orgRootId: orgRoot.id,
2024-02-15 08:56:26 +07:00
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
2024-02-28 14:48:41 +07:00
// totalPositionCurrentVacant:
// await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count(
// {
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// next_holderId: IsNull() || "",
// },
2024-02-15 08:56:26 +07:00
// },
2024-02-28 14:48:41 +07:00
// ),
children: await Promise.all(
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalPositionVacant:
data.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant:
// await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant:
// await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
})),
),
2024-02-15 08:56:26 +07:00
})),
),
})),
),
})),
),
2024-02-28 14:48:41 +07:00
};
}),
),
};
return new HttpSuccess([formattedData]);
}
case 1: {
const data = await this.orgRootRepository.findOne({
where: { id: idNode },
relations: [
"orgRevision",
"orgChild1s",
"orgChild1s.orgChild2s",
"orgChild1s.orgChild2s.orgChild3s",
"orgChild1s.orgChild2s.orgChild3s.orgChild4s",
],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgRootName,
deptID: data.id,
type: 1,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRootId: data.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRootId: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
data.orgChild1s
.sort((a, b) => a.orgChild1Order - b.orgChild1Order)
.map(async (orgChild1) => ({
departmentName: orgChild1.orgChild1Name,
deptID: orgChild1.id,
type: 2,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRootId: data.id, orgChild1Id: orgChild1.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild1.orgChild2s
.sort((a, b) => a.orgChild2Order - b.orgChild2Order)
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
},
}),
totalPositionCurrentVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild2.orgChild3s
.sort((a, b) => a.orgChild3Order - b.orgChild3Order)
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
},
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRootId: data.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant:
// await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRootId: data.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
})),
),
})),
),
})),
),
})),
),
};
return new HttpSuccess([formattedData]);
}
case 2: {
const data = await this.child1Repository.findOne({
where: { id: idNode },
relations: [
"orgRevision",
"orgChild2s",
"orgChild2s.orgChild3s",
"orgChild2s.orgChild3s.orgChild4s",
],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgChild1Name,
deptID: data.id,
type: 2,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRevisionId: data.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild1Id: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild1Id: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild1Id: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild1Id: data.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
data.orgChild2s
.sort((a, b) => a.orgChild2Order - b.orgChild2Order)
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild1Id: data.id, orgChild2Id: orgChild2.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild1Id: data.id,
orgChild2Id: orgChild2.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild1Id: data.id,
orgChild2Id: orgChild2.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild1Id: data.id,
// orgChild2Id: orgChild2.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild1Id: data.id,
// orgChild2Id: orgChild2.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild2.orgChild3s
.sort((a, b) => a.orgChild3Order - b.orgChild3Order)
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
},
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgRevisionId: data.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: data.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
})),
),
})),
),
})),
),
};
return new HttpSuccess([formattedData]);
}
case 3: {
const data = await this.child2Repository.findOne({
where: { id: idNode },
relations: ["orgRevision", "orgChild3s", "orgChild3s.orgChild4s"],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgChild2Name,
deptID: data.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild2Id: data.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
data.orgChild3s
.sort((a, b) => a.orgChild3Order - b.orgChild3Order)
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild2Id: data.id, orgChild3Id: orgChild3.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// orgChild3Id: orgChild3.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// orgChild3Id: orgChild3.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild2Id: data.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild2Id: data.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
})),
),
})),
),
};
return new HttpSuccess([formattedData]);
}
case 4: {
const data = await this.child3Repository.findOne({
where: { id: idNode },
relations: ["orgRevision", "orgChild4s"],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgChild3Name,
deptID: data.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild3Id: data.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild3Id: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild3Id: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild3Id: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild3Id: data.id,
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all(
data.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild3Id: data.id, orgChild4Id: orgChild4.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild3Id: data.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild3Id: data.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild3Id: data.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild3Id: data.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
})),
),
};
return new HttpSuccess([formattedData]);
}
case 5: {
const data = await this.child4Repository.findOne({
where: { id: idNode },
relations: ["orgRevision"],
});
if (!data) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id");
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
const formattedData = {
departmentName: data.orgChild4Name,
deptID: data.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild4Id: data.id },
}),
totalPositionVacant:
data.orgRevision.orgRevisionIsDraft == true
? await this.posMasterRepository.count({
where: {
orgChild4Id: data.id,
next_holderId: IsNull() || "",
},
})
: await this.posMasterRepository.count({
where: {
orgChild4Id: data.id,
current_holderId: IsNull() || "",
},
}),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgChild4Id: data.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgChild4Id: data.id,
// next_holderId: IsNull() || "",
// },
// }),
};
return new HttpSuccess([formattedData]);
2024-02-14 12:18:24 +07:00
}
2024-02-28 14:48:41 +07:00
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: ");
}
2024-02-14 12:18:24 +07:00
}
/**
* API node
*
* @summary node (ADMIN)
*
*/
@Post("find/node")
async findNodeAll(@Body() requestBody: { node: number; nodeId: string }) {
2024-02-28 14:48:41 +07:00
switch (requestBody.node) {
case 0: {
const data = await this.orgRootRepository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
}
2024-02-28 14:48:41 +07:00
return new HttpSuccess([data.id]);
}
case 1: {
const data = await this.child1Repository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1.");
}
2024-02-28 14:48:41 +07:00
return new HttpSuccess([data.orgRootId, data.id]);
}
case 2: {
const data = await this.child2Repository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2.");
}
2024-02-28 14:48:41 +07:00
return new HttpSuccess([data.orgRootId, data.orgChild1Id, data.id]);
}
case 3: {
const data = await this.child3Repository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3.");
}
2024-02-28 14:48:41 +07:00
return new HttpSuccess([data.orgRootId, data.orgChild1Id, data.orgChild2Id, data.id]);
}
case 4: {
const data = await this.child4Repository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4.");
}
2024-02-28 14:48:41 +07:00
return new HttpSuccess([
data.orgRootId,
data.orgChild1Id,
data.orgChild2Id,
data.orgChild3Id,
data.id,
]);
}
2024-02-28 14:48:41 +07:00
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.node);
}
}
2024-02-27 17:30:37 +07:00
/**
* API node detail
*
* @summary node detail (ADMIN)
*
*/
@Post("find/all")
async findNodeAllDetail(@Body() requestBody: { node: number; nodeId: string }) {
switch (requestBody.node) {
case 0: {
const data = await this.orgRootRepository.findOne({
where: { id: requestBody.nodeId },
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
}
return new HttpSuccess({
rootId: data.id,
root: data.orgRootName,
rootShortName: data.orgRootShortName,
});
}
case 1: {
const data = await this.child1Repository.findOne({
where: { id: requestBody.nodeId },
relations: {
orgRoot: true,
},
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1.");
}
return new HttpSuccess({
rootId: data.orgRootId,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.id,
child1: data.orgChild1Name,
child1ShortName: data.orgChild1ShortName,
});
}
case 2: {
const data = await this.child2Repository.findOne({
where: { id: requestBody.nodeId },
relations: {
orgRoot: true,
orgChild1: true,
},
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2.");
}
return new HttpSuccess({
rootId: data.orgRootId,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.id,
child2: data.orgChild2Name,
child2ShortName: data.orgChild2ShortName,
});
}
case 3: {
const data = await this.child3Repository.findOne({
where: { id: requestBody.nodeId },
relations: {
orgRoot: true,
orgChild1: true,
orgChild2: true,
},
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3.");
}
return new HttpSuccess({
rootId: data.orgRootId,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.orgChild2Id,
child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name,
child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName,
child3Id: data.id,
child3: data.orgChild3Name,
child3ShortName: data.orgChild3ShortName,
});
}
case 4: {
const data = await this.child4Repository.findOne({
where: { id: requestBody.nodeId },
relations: {
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
},
});
if (data == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4.");
}
return new HttpSuccess({
rootId: data.orgRootId,
root: data.orgRoot == null ? null : data.orgRoot.orgRootName,
rootShortName: data.orgRoot == null ? null : data.orgRoot.orgRootShortName,
child1Id: data.orgChild1Id,
child1: data.orgChild1 == null ? null : data.orgChild1.orgChild1Name,
child1ShortName: data.orgChild1 == null ? null : data.orgChild1.orgChild1ShortName,
child2Id: data.orgChild2Id,
child2: data.orgChild2 == null ? null : data.orgChild2.orgChild2Name,
child2ShortName: data.orgChild2 == null ? null : data.orgChild2.orgChild2ShortName,
child3Id: data.orgChild3Id,
child3: data.orgChild3 == null ? null : data.orgChild3.orgChild3Name,
child3ShortName: data.orgChild3 == null ? null : data.orgChild3.orgChild3ShortName,
child4Id: data.id,
child4: data.orgChild4Name,
child4ShortName: data.orgChild4ShortName,
});
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.node);
}
}
2024-02-27 17:30:37 +07:00
/**
* API
*
* @summary
*
*/
@Get("active/root")
async GetActiveRoot() {
2024-02-28 14:48:41 +07:00
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร๋อยู่ตอนนี้");
}
2024-02-27 17:30:37 +07:00
2024-02-28 14:48:41 +07:00
const data = await this.orgRootRepository.find({
where: { orgRevisionId: orgRevisionActive.id },
relations: [
"orgRevision",
"orgChild1s",
"orgChild1s.orgChild2s",
"orgChild1s.orgChild2s.orgChild3s",
"orgChild1s.orgChild2s.orgChild3s.orgChild4s",
],
2024-08-30 18:02:34 +07:00
order: {
orgChild1s: {
orgChild1Order: "ASC",
orgChild2s: {
orgChild2Order: "ASC",
orgChild3s: {
orgChild3Order: "ASC",
orgChild4s: {
orgChild4Order: "ASC",
},
},
},
},
},
2024-02-28 14:48:41 +07:00
});
return new HttpSuccess(data);
2024-02-27 17:30:37 +07:00
}
2024-02-28 11:28:06 +07:00
/**
* API
*
* @summary
*
*/
@Get("active/root/id")
async GetActiveRootId() {
2024-02-28 14:48:41 +07:00
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร๋อยู่ตอนนี้");
}
2024-02-28 11:28:06 +07:00
2024-02-28 14:48:41 +07:00
const data = await this.orgRootRepository.find({
where: { orgRevisionId: orgRevisionActive.id },
});
return new HttpSuccess(data.map((x) => x.id));
2024-02-28 11:28:06 +07:00
}
2024-03-29 12:00:12 +07:00
/**
* API
*
* @summary
*
*/
@Get("active/root/latest")
async GetActiveRootIdLatest() {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร๋อยู่ตอนนี้");
}
return new HttpSuccess(orgRevisionActive.id);
}
/**
* API by revision
*
* @summary by revision
*
*/
@Get("active/root/{revisionId}")
async GetActiveRootByRevision(@Path() revisionId: string) {
2024-02-28 14:48:41 +07:00
const data = await this.orgRootRepository.find({
where: { orgRevisionId: revisionId },
relations: [
"orgRevision",
"orgChild1s",
"orgChild1s.orgChild2s",
"orgChild1s.orgChild2s.orgChild3s",
"orgChild1s.orgChild2s.orgChild3s.orgChild4s",
],
2024-05-23 10:07:07 +07:00
order: {
2024-06-19 23:03:54 +07:00
orgChild1s: {
2024-05-23 10:26:43 +07:00
orgChild1Order: "ASC",
2024-06-19 23:03:54 +07:00
orgChild2s: {
2024-05-23 10:26:43 +07:00
orgChild2Order: "ASC",
2024-06-19 23:03:54 +07:00
orgChild3s: {
2024-05-23 10:26:43 +07:00
orgChild3Order: "ASC",
2024-06-19 23:03:54 +07:00
orgChild4s: {
2024-05-23 10:26:43 +07:00
orgChild4Order: "ASC",
2024-06-19 23:03:54 +07:00
},
},
},
2024-05-23 10:07:07 +07:00
},
2024-06-19 23:03:54 +07:00
},
2024-02-28 14:48:41 +07:00
});
return new HttpSuccess(data);
}
/**
* API revision
*
* @summary revision
*
*/
@Get("revision/latest")
async salaryGen() {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างล่าสุด");
}
return new HttpSuccess(findRevision.id);
}
2024-06-19 23:03:54 +07:00
/**
* API
*
* @summary (ADMIN)
*
*/
@Get("act/{id}")
2024-09-04 14:18:15 +07:00
async detailAct(@Path() id: string, @Request() request: RequestWithUser) {
let _data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
2024-09-06 08:03:53 +07:00
2024-09-04 14:18:15 +07:00
if (!request.user.role.includes("SUPER_ADMIN")) {
_data = await new permission().PermissionOrgList(request, "SYS_ACTING");
}
2024-09-06 08:03:53 +07:00
2024-06-19 23:03:54 +07:00
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const orgRootData = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id })
2024-09-04 14:18:15 +07:00
.andWhere(
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `orgRoot.id IN (:...node)`
: `orgRoot.id is null`
: "1=1",
{
node: _data.root,
},
)
2024-06-19 23:03:54 +07:00
.leftJoinAndSelect("orgRoot.posMasters", "posMasters")
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
.orderBy("orgRoot.orgRootOrder", "ASC")
.getMany();
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
const orgChild1Data =
orgRootIds && orgRootIds.length > 0
? await AppDataSource.getRepository(OrgChild1)
.createQueryBuilder("orgChild1")
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
2024-09-04 14:18:15 +07:00
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `orgChild1.id IN (:...node)`
: `orgChild1.id is null`
: "1=1",
{
node: _data.child1,
},
)
2024-06-19 23:03:54 +07:00
.leftJoinAndSelect("orgChild1.posMasters", "posMasters")
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
.orderBy("orgChild1.orgChild1Order", "ASC")
.getMany()
: [];
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
const orgChild2Data =
orgChild1Ids && orgChild1Ids.length > 0
? await AppDataSource.getRepository(OrgChild2)
.createQueryBuilder("orgChild2")
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
2024-09-04 14:18:15 +07:00
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `orgChild2.id IN (:...node)`
: `orgChild2.id is null`
: "1=1",
{
node: _data.child2,
},
)
2024-06-19 23:03:54 +07:00
.leftJoinAndSelect("orgChild2.posMasters", "posMasters")
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
.orderBy("orgChild2.orgChild2Order", "ASC")
.getMany()
: [];
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
const orgChild3Data =
orgChild2Ids && orgChild2Ids.length > 0
? await AppDataSource.getRepository(OrgChild3)
.createQueryBuilder("orgChild3")
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
2024-09-04 14:18:15 +07:00
.andWhere(
2024-09-06 08:03:53 +07:00
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `orgChild3.id IN (:...node)`
: `orgChild3.id is null`
: "1=1",
{
node: _data.child3,
},
2024-09-04 14:18:15 +07:00
)
2024-06-19 23:03:54 +07:00
.leftJoinAndSelect("orgChild3.posMasters", "posMasters")
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
.orderBy("orgChild3.orgChild3Order", "ASC")
.getMany()
: [];
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
const orgChild4Data =
orgChild3Ids && orgChild3Ids.length > 0
? await AppDataSource.getRepository(OrgChild4)
.createQueryBuilder("orgChild4")
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
2024-09-04 14:18:15 +07:00
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `orgChild4.id IN (:...node)`
: `orgChild4.id is null`
: "1=1",
{
node: _data.child4,
},
)
2024-06-19 23:03:54 +07:00
.leftJoinAndSelect("orgChild4.posMasters", "posMasters")
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
.orderBy("orgChild4.orgChild4Order", "ASC")
.getMany()
: [];
// const formattedData = orgRootData.map((orgRoot) => {
const formattedData = await Promise.all(
orgRootData.map(async (orgRoot) => {
return {
orgTreeId: orgRoot.id,
orgLevel: 0,
orgName: orgRoot.orgRootName,
orgTreeName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName,
orgTreeCode: orgRoot.orgRootCode,
orgCode: orgRoot.orgRootCode + "00",
orgRootName: orgRoot.orgRootName,
labelName:
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
posMaster: await Promise.all(
orgRoot.posMasters
.filter(
(x) => x.orgChild1Id == null && x.current_holderId != null && x.posMasterOrder <= 3,
2024-06-19 23:03:54 +07:00
)
.map(async (x) => ({
posmasterId: x.id,
2024-06-19 23:03:54 +07:00
orgTreeId: orgRoot.id,
orgLevel: 0,
fullNameCurrentHolder:
x.current_holder == null
? null
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
})),
),
children: await Promise.all(
orgChild1Data
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
.map(async (orgChild1) => ({
orgTreeId: orgChild1.id,
orgRootId: orgRoot.id,
orgLevel: 1,
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild1.orgChild1Name,
orgTreeShortName: orgChild1.orgChild1ShortName,
orgTreeCode: orgChild1.orgChild1Code,
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
orgRootName: orgRoot.orgRootName,
labelName:
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName,
posMaster: await Promise.all(
orgChild1.posMasters
.filter(
(x) =>
x.orgChild2Id == null &&
2024-06-19 23:03:54 +07:00
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
2024-06-19 23:03:54 +07:00
orgTreeId: orgChild1.id,
orgLevel: 1,
fullNameCurrentHolder:
x.current_holder == null
? null
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
})),
),
children: await Promise.all(
orgChild2Data
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
.map(async (orgChild2) => ({
orgTreeId: orgChild2.id,
orgRootId: orgChild1.id,
orgLevel: 2,
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild2.orgChild2Name,
orgTreeShortName: orgChild2.orgChild2ShortName,
orgTreeCode: orgChild2.orgChild2Code,
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgRootName: orgRoot.orgRootName,
labelName:
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName,
posMaster: await Promise.all(
orgChild2.posMasters
.filter(
(x) =>
x.orgChild3Id == null &&
2024-06-19 23:03:54 +07:00
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
2024-06-19 23:03:54 +07:00
orgTreeId: orgChild2.id,
orgLevel: 2,
fullNameCurrentHolder:
x.current_holder == null
? null
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
})),
),
children: await Promise.all(
orgChild3Data
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
.map(async (orgChild3) => ({
orgTreeId: orgChild3.id,
orgRootId: orgChild2.id,
orgLevel: 3,
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild3.orgChild3Name,
orgTreeShortName: orgChild3.orgChild3ShortName,
orgTreeCode: orgChild3.orgChild3Code,
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
orgRootName: orgRoot.orgRootName,
labelName:
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName,
posMaster: await Promise.all(
orgChild3.posMasters
.filter(
(x) =>
x.orgChild4Id == null &&
2024-06-19 23:03:54 +07:00
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
2024-06-19 23:03:54 +07:00
orgTreeId: orgChild3.id,
orgLevel: 3,
fullNameCurrentHolder:
x.current_holder == null
? null
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
})),
),
children: await Promise.all(
orgChild4Data
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
orgRootId: orgChild3.id,
orgLevel: 4,
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild4.orgChild4Name,
orgTreeShortName: orgChild4.orgChild4ShortName,
orgTreeCode: orgChild4.orgChild4Code,
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
orgRootName: orgRoot.orgRootName,
labelName:
orgChild4.orgChild4Name +
" " +
orgRoot.orgRootCode +
orgChild4.orgChild4Code +
" " +
orgChild4.orgChild4ShortName,
posMaster: await Promise.all(
orgChild4.posMasters
.filter(
(x) => x.current_holderId != null && x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
2024-06-19 23:03:54 +07:00
orgTreeId: orgChild4.id,
orgLevel: 4,
fullNameCurrentHolder:
x.current_holder == null
? null
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
})),
),
})),
),
})),
),
})),
),
})),
),
};
}),
);
return new HttpSuccess(formattedData);
}
2024-06-24 10:52:40 +07:00
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id
*/
@Get("approver/{id}")
async getUserRootOrg(@Path() id: string, @Request() request: { user: Record<string, any> }) {
2024-06-25 10:21:30 +07:00
if (id == "00000000-0000-0000-0000-000000000000") {
const maps = {
id: "00000000-0000-0000-0000-000000000000",
name: "",
positionName: "ปลัดกรุงเทพมหานคร",
};
return new HttpSuccess(maps);
}
2024-06-24 10:52:40 +07:00
const root = await this.orgRootRepository.findOne({
where: { id: id },
});
if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
const posMaster = await this.posMasterRepository.find({
where: { orgRootId: root.id, orgChild1Id: IsNull(), current_holder: Not(IsNull()) },
2024-06-24 10:52:40 +07:00
relations: ["current_holder"],
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const maps = posMaster.map((posMaster) => ({
id: posMaster?.current_holder?.id,
name: `${posMaster?.current_holder?.prefix}${posMaster?.current_holder?.firstName} ${posMaster?.current_holder?.lastName}`,
positionName: posMaster?.current_holder?.position,
2024-06-24 10:52:40 +07:00
}));
return new HttpSuccess(maps);
}
2024-08-19 17:58:33 +07:00
/**
* API
*
* @summary ORG_023 - (ADMIN) #25
*
*/
2024-08-20 15:49:59 +07:00
@Get("system/{id}/{system}")
2024-08-19 17:58:33 +07:00
async detailBySystem(
@Path() id: string,
@Path() system: string,
@Request() request: RequestWithUser,
) {
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
let _data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
const orgRootData = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id })
.andWhere(
2024-08-29 14:41:48 +07:00
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `orgRoot.id IN (:...node)`
: `orgRoot.id is null`
: "1=1",
2024-08-19 17:58:33 +07:00
{
node: _data.root,
},
)
.select([
"orgRoot.id",
"orgRoot.orgRootName",
"orgRoot.orgRootShortName",
"orgRoot.orgRootCode",
"orgRoot.orgRootOrder",
"orgRoot.orgRootPhoneEx",
"orgRoot.orgRootPhoneIn",
"orgRoot.orgRootFax",
"orgRoot.orgRevisionId",
"orgRoot.orgRootRank",
"orgRoot.orgRootRankSub",
"orgRoot.responsibility",
])
.orderBy("orgRoot.orgRootOrder", "ASC")
.getMany();
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
const orgChild1Data =
orgRootIds && orgRootIds.length > 0
? await AppDataSource.getRepository(OrgChild1)
.createQueryBuilder("orgChild1")
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `orgChild1.id IN (:...node)`
: `orgChild1.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child1,
},
)
.select([
"orgChild1.id",
"orgChild1.orgChild1Name",
"orgChild1.orgChild1ShortName",
"orgChild1.orgChild1Code",
"orgChild1.orgChild1Order",
"orgChild1.orgChild1PhoneEx",
"orgChild1.orgChild1PhoneIn",
"orgChild1.orgChild1Fax",
"orgChild1.orgRootId",
"orgChild1.orgChild1Rank",
"orgChild1.orgChild1RankSub",
"orgChild1.responsibility",
])
.orderBy("orgChild1.orgChild1Order", "ASC")
.getMany()
: [];
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
const orgChild2Data =
orgChild1Ids && orgChild1Ids.length > 0
? await AppDataSource.getRepository(OrgChild2)
.createQueryBuilder("orgChild2")
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `orgChild2.id IN (:...node)`
: `orgChild2.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child2,
},
)
.select([
"orgChild2.id",
"orgChild2.orgChild2Name",
"orgChild2.orgChild2ShortName",
"orgChild2.orgChild2Code",
"orgChild2.orgChild2Order",
"orgChild2.orgChild2PhoneEx",
"orgChild2.orgChild2PhoneIn",
"orgChild2.orgChild2Fax",
"orgChild2.orgRootId",
"orgChild2.orgChild2Rank",
"orgChild2.orgChild2RankSub",
"orgChild2.orgChild1Id",
"orgChild2.responsibility",
])
.orderBy("orgChild2.orgChild2Order", "ASC")
.getMany()
: [];
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
const orgChild3Data =
orgChild2Ids && orgChild2Ids.length > 0
? await AppDataSource.getRepository(OrgChild3)
.createQueryBuilder("orgChild3")
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `orgChild3.id IN (:...node)`
: `orgChild3.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child3,
},
)
.select([
"orgChild3.id",
"orgChild3.orgChild3Name",
"orgChild3.orgChild3ShortName",
"orgChild3.orgChild3Code",
"orgChild3.orgChild3Order",
"orgChild3.orgChild3PhoneEx",
"orgChild3.orgChild3PhoneIn",
"orgChild3.orgChild3Fax",
"orgChild3.orgRootId",
"orgChild3.orgChild3Rank",
"orgChild3.orgChild3RankSub",
"orgChild3.orgChild2Id",
"orgChild3.responsibility",
])
.orderBy("orgChild3.orgChild3Order", "ASC")
.getMany()
: [];
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
const orgChild4Data =
orgChild3Ids && orgChild3Ids.length > 0
? await AppDataSource.getRepository(OrgChild4)
.createQueryBuilder("orgChild4")
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `orgChild4.id IN (:...node)`
: `orgChild4.id is null`
2024-08-19 17:58:33 +07:00
: "1=1",
{
node: _data.child4,
},
)
.select([
"orgChild4.id",
"orgChild4.orgChild4Name",
"orgChild4.orgChild4ShortName",
"orgChild4.orgChild4Code",
"orgChild4.orgChild4Order",
"orgChild4.orgChild4PhoneEx",
"orgChild4.orgChild4PhoneIn",
"orgChild4.orgChild4Fax",
"orgChild4.orgRootId",
"orgChild4.orgChild4Rank",
"orgChild4.orgChild4RankSub",
"orgChild4.orgChild3Id",
"orgChild4.responsibility",
])
.orderBy("orgChild4.orgChild4Order", "ASC")
.getMany()
: [];
// const formattedData = orgRootData.map((orgRoot) => {
const formattedData = await Promise.all(
orgRootData.map(async (orgRoot) => {
return {
orgTreeId: orgRoot.id,
orgLevel: 0,
orgName: orgRoot.orgRootName,
orgTreeName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName,
orgTreeCode: orgRoot.orgRootCode,
orgCode: orgRoot.orgRootCode + "00",
orgTreeRank: orgRoot.orgRootRank,
orgTreeRankSub: orgRoot.orgRootRankSub,
orgTreeOrder: orgRoot.orgRootOrder,
orgTreePhoneEx: orgRoot.orgRootPhoneEx,
orgTreePhoneIn: orgRoot.orgRootPhoneIn,
orgTreeFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgRoot.responsibility,
labelName:
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: IsNull() || "",
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild1Data
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
.map(async (orgChild1) => ({
orgTreeId: orgChild1.id,
orgRootId: orgRoot.id,
orgLevel: 1,
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild1.orgChild1Name,
orgTreeShortName: orgChild1.orgChild1ShortName,
orgTreeCode: orgChild1.orgChild1Code,
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
orgTreeRank: orgChild1.orgChild1Rank,
orgTreeRankSub: orgChild1.orgChild1RankSub,
orgTreeOrder: orgChild1.orgChild1Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
orgTreeFax: orgChild1.orgChild1Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgChild1.responsibility,
labelName:
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName,
totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: IsNull() || "",
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild2Data
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
.map(async (orgChild2) => ({
orgTreeId: orgChild2.id,
orgRootId: orgChild1.id,
orgLevel: 2,
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild2.orgChild2Name,
orgTreeShortName: orgChild2.orgChild2ShortName,
orgTreeCode: orgChild2.orgChild2Code,
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgTreeRank: orgChild2.orgChild2Rank,
orgTreeRankSub: orgChild2.orgChild2RankSub,
orgTreeOrder: orgChild2.orgChild2Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
orgTreeFax: orgChild2.orgChild2Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgChild2.responsibility,
labelName:
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName,
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: IsNull() || "",
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild3Data
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
.map(async (orgChild3) => ({
orgTreeId: orgChild3.id,
orgRootId: orgChild2.id,
orgLevel: 3,
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild3.orgChild3Name,
orgTreeShortName: orgChild3.orgChild3ShortName,
orgTreeCode: orgChild3.orgChild3Code,
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
orgTreeRank: orgChild3.orgChild3Rank,
orgTreeRankSub: orgChild3.orgChild3RankSub,
orgTreeOrder: orgChild3.orgChild3Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
orgTreeFax: orgChild3.orgChild3Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgChild3.responsibility,
labelName:
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName,
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild3Id: orgChild3.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
orgChild4Data
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
orgRootId: orgChild3.id,
orgLevel: 4,
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeName: orgChild4.orgChild4Name,
orgTreeShortName: orgChild4.orgChild4ShortName,
orgTreeCode: orgChild4.orgChild4Code,
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
orgTreeRank: orgChild4.orgChild4Rank,
orgTreeRankSub: orgChild4.orgChild4RankSub,
orgTreeOrder: orgChild4.orgChild4Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
orgTreeFax: orgChild4.orgChild4Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgChild4.responsibility,
labelName:
orgChild4.orgChild4Name +
" " +
orgRoot.orgRootCode +
orgChild4.orgChild4Code +
" " +
orgChild4.orgChild4ShortName,
totalPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
},
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
}),
totalRootPosition: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
},
}),
totalRootPositionCurrentUse: await this.posMasterRepository.count(
{
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: Not(IsNull()) || Not(""),
},
},
),
totalRootPositionCurrentVacant:
await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
current_holderId: IsNull() || "",
},
}),
totalRootPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalRootPositionNextVacant: await this.posMasterRepository.count(
{
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
orgChild1Id: orgChild1.id,
orgChild2Id: orgChild2.id,
orgChild3Id: orgChild3.id,
orgChild4Id: orgChild4.id,
next_holderId: IsNull() || "",
},
},
),
})),
),
})),
),
})),
),
})),
),
};
}),
);
return new HttpSuccess(formattedData);
}
2024-01-26 13:32:56 +07:00
}