2024-01-26 13:32:56 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Patch,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Body,
|
|
|
|
|
Path,
|
|
|
|
|
Request,
|
|
|
|
|
Example,
|
2024-01-26 16:41:52 +07:00
|
|
|
SuccessResponse,
|
|
|
|
|
Response,
|
2024-01-26 13:32:56 +07:00
|
|
|
} from "tsoa";
|
2024-01-26 20:25:18 +07:00
|
|
|
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";
|
|
|
|
|
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
|
|
|
|
import HttpError from "../interfaces/http-error";
|
|
|
|
|
import HttpStatusCode from "../interfaces/http-status";
|
2024-01-26 20:25:18 +07:00
|
|
|
import { In, Not } from "typeorm";
|
|
|
|
|
import { OrgRoot } from "../entities/OrgRoot";
|
|
|
|
|
import { OrgChild2 } from "../entities/OrgChild2";
|
|
|
|
|
import { OrgChild3 } from "../entities/OrgChild3";
|
|
|
|
|
import { OrgChild4 } from "../entities/OrgChild4";
|
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")
|
|
|
|
|
@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);
|
2024-01-26 20:25:18 +07:00
|
|
|
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);
|
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() {
|
|
|
|
|
try {
|
|
|
|
|
const orgRevision = await this.orgRevisionRepository.find({
|
2024-01-26 16:41:52 +07:00
|
|
|
select: [
|
|
|
|
|
"id",
|
|
|
|
|
"orgRevisionName",
|
|
|
|
|
"orgRevisionIsCurrent",
|
|
|
|
|
"orgRevisionCreatedAt",
|
|
|
|
|
"orgRevisionIsDraft",
|
|
|
|
|
],
|
|
|
|
|
order: { orgRevisionCreatedAt: "DESC" },
|
2024-01-26 13:32:56 +07:00
|
|
|
});
|
|
|
|
|
if (!orgRevision) {
|
2024-01-26 16:41:52 +07:00
|
|
|
return new HttpSuccess([]);
|
2024-01-26 13:32:56 +07:00
|
|
|
}
|
|
|
|
|
const mapOrgRevisions = orgRevision.map((revision) => ({
|
|
|
|
|
orgRevisionId: revision.id,
|
|
|
|
|
orgRevisionName: revision.orgRevisionName,
|
|
|
|
|
orgRevisionIsCurrent: revision.orgRevisionIsCurrent,
|
|
|
|
|
orgRevisionCreatedAt: revision.orgRevisionCreatedAt,
|
|
|
|
|
orgRevisionIsDraft: revision.orgRevisionIsDraft,
|
|
|
|
|
}));
|
2024-01-26 16:41:52 +07:00
|
|
|
|
2024-01-26 13:32:56 +07:00
|
|
|
return new HttpSuccess(mapOrgRevisions);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API โครงสร้างปัจจุบันที่ใช้อยู่
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_021 - โครงสร้างปัจจุบันที่ใช้อยู่ #22
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("active")
|
|
|
|
|
async GetActive() {
|
|
|
|
|
try {
|
|
|
|
|
const orgRevisionActive = await this.orgRevisionRepository.findOne({
|
2024-01-26 16:41:52 +07:00
|
|
|
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
2024-01-26 13:32:56 +07:00
|
|
|
});
|
|
|
|
|
const orgRevisionDraf = await this.orgRevisionRepository.findOne({
|
2024-01-26 16:41:52 +07:00
|
|
|
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
|
2024-01-26 13:32:56 +07:00
|
|
|
});
|
|
|
|
|
const mapData = {
|
2024-01-26 16:41:52 +07:00
|
|
|
activeId: orgRevisionActive == null ? null : orgRevisionActive.id,
|
|
|
|
|
activeName: orgRevisionActive == null ? null : orgRevisionActive.orgRevisionName,
|
|
|
|
|
draftId: orgRevisionDraf == null ? null : orgRevisionDraf.id,
|
|
|
|
|
draftName: orgRevisionDraf == null ? null : orgRevisionDraf.orgRevisionName,
|
2024-01-26 13:32:56 +07:00
|
|
|
};
|
|
|
|
|
return new HttpSuccess(mapData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API สร้างโครงสร้างระดับ4
|
|
|
|
|
*
|
2024-01-29 17:08:22 +07:00
|
|
|
* @summary ORG_022 - สร้างโครงสร้างใหม่ #23
|
2024-01-26 13:32:56 +07:00
|
|
|
*
|
|
|
|
|
*/
|
2024-01-29 11:36:03 +07:00
|
|
|
@Post("draft")
|
2024-01-26 13:32:56 +07:00
|
|
|
async CreateOrgRevision(
|
2024-01-26 20:25:18 +07:00
|
|
|
@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
|
|
|
) {
|
|
|
|
|
try {
|
2024-01-26 20:25:18 +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;
|
|
|
|
|
await this.orgRevisionRepository.save(revision);
|
|
|
|
|
|
|
|
|
|
if (requestBody.typeDraft.toUpperCase() == "ORG") {
|
|
|
|
|
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.");
|
|
|
|
|
|
|
|
|
|
//clone data
|
|
|
|
|
const orgRoot = await this.orgRootRepository.find({
|
|
|
|
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
|
|
|
|
});
|
|
|
|
|
const _orgRoot = orgRoot.map((x) => ({
|
|
|
|
|
...x,
|
|
|
|
|
isAncestorDNA:
|
|
|
|
|
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
|
|
|
? x.id
|
|
|
|
|
: x.isAncestorDNA,
|
|
|
|
|
}));
|
|
|
|
|
await this.orgRootRepository.save(_orgRoot);
|
|
|
|
|
|
|
|
|
|
_orgRoot.forEach(async (x: any) => {
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
//clone data
|
|
|
|
|
const orgChild1 = await this.child1Repository.find({
|
|
|
|
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
|
|
|
|
});
|
|
|
|
|
const _orgChild1 = orgChild1.map((x) => ({
|
|
|
|
|
...x,
|
|
|
|
|
isAncestorDNA:
|
|
|
|
|
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
|
|
|
? x.id
|
|
|
|
|
: x.isAncestorDNA,
|
|
|
|
|
}));
|
|
|
|
|
await this.child1Repository.save(_orgChild1);
|
|
|
|
|
|
|
|
|
|
_orgChild1.forEach(async (x: any) => {
|
|
|
|
|
delete x.id;
|
|
|
|
|
const data = Object.assign(new OrgChild1(), 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.child1Repository.save(data);
|
|
|
|
|
});
|
|
|
|
|
//clone data
|
|
|
|
|
const orgChild2 = await this.child2Repository.find({
|
|
|
|
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
|
|
|
|
});
|
|
|
|
|
const _orgChild2 = orgChild2.map((x) => ({
|
|
|
|
|
...x,
|
|
|
|
|
isAncestorDNA:
|
|
|
|
|
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
|
|
|
? x.id
|
|
|
|
|
: x.isAncestorDNA,
|
|
|
|
|
}));
|
|
|
|
|
await this.child2Repository.save(_orgChild2);
|
|
|
|
|
|
|
|
|
|
_orgChild2.forEach(async (x: any) => {
|
|
|
|
|
delete x.id;
|
|
|
|
|
const data = Object.assign(new OrgChild2(), 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.child2Repository.save(data);
|
|
|
|
|
});
|
|
|
|
|
//clone data
|
|
|
|
|
const orgChild3 = await this.child3Repository.find({
|
|
|
|
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
|
|
|
|
});
|
|
|
|
|
const _orgChild3 = orgChild3.map((x) => ({
|
|
|
|
|
...x,
|
|
|
|
|
isAncestorDNA:
|
|
|
|
|
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
|
|
|
? x.id
|
|
|
|
|
: x.isAncestorDNA,
|
|
|
|
|
}));
|
|
|
|
|
await this.child3Repository.save(_orgChild3);
|
|
|
|
|
|
|
|
|
|
_orgChild3.forEach(async (x: any) => {
|
|
|
|
|
delete x.id;
|
|
|
|
|
const data = Object.assign(new OrgChild3(), 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.child3Repository.save(data);
|
|
|
|
|
});
|
|
|
|
|
//clone data
|
|
|
|
|
const orgChild4 = await this.child4Repository.find({
|
|
|
|
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
|
|
|
|
});
|
|
|
|
|
const _orgChild4 = orgChild4.map((x) => ({
|
|
|
|
|
...x,
|
|
|
|
|
isAncestorDNA:
|
|
|
|
|
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
|
|
|
? x.id
|
|
|
|
|
: x.isAncestorDNA,
|
|
|
|
|
}));
|
|
|
|
|
await this.child4Repository.save(_orgChild4);
|
|
|
|
|
|
|
|
|
|
_orgChild4.forEach(async (x: any) => {
|
|
|
|
|
delete x.id;
|
|
|
|
|
const data = Object.assign(new OrgChild4(), 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.child4Repository.save(data);
|
|
|
|
|
});
|
|
|
|
|
} else if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
|
|
|
|
} else if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const orgRevisions = await this.orgRevisionRepository.find({
|
|
|
|
|
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
|
|
|
|
|
});
|
|
|
|
|
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
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
2024-01-26 13:32:56 +07:00
|
|
|
}
|
2024-01-26 16:41:52 +07:00
|
|
|
}
|
2024-01-26 20:25:18 +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}")
|
|
|
|
|
async detail(@Path() id: string) {
|
2024-01-29 17:08:22 +07:00
|
|
|
try {
|
|
|
|
|
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
|
|
|
|
if (!orgRevision) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
|
|
|
|
.createQueryBuilder("orgRoot")
|
|
|
|
|
.where("orgRoot.orgRevisionId = :id", { id })
|
|
|
|
|
.select([
|
|
|
|
|
"orgRoot.id",
|
|
|
|
|
"orgRoot.orgRootName",
|
|
|
|
|
"orgRoot.orgRootShortName",
|
|
|
|
|
"orgRoot.orgRootCode",
|
|
|
|
|
"orgRoot.orgRootOrder",
|
|
|
|
|
"orgRoot.orgRootPhoneEx",
|
|
|
|
|
"orgRoot.orgRootPhoneIn",
|
|
|
|
|
"orgRoot.orgRootFax",
|
|
|
|
|
"orgRoot.orgRevisionId",
|
2024-01-30 10:29:03 +07:00
|
|
|
"orgRoot.orgRootRank",
|
2024-01-29 17:08:22 +07:00
|
|
|
])
|
2024-01-30 16:39:22 +07:00
|
|
|
.orderBy("orgRoot.createdAt","ASC")
|
2024-01-29 17:08:22 +07:00
|
|
|
.getMany();
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
|
2024-01-29 17:29:15 +07:00
|
|
|
const orgChild1Data =
|
|
|
|
|
orgRootIds && orgRootIds.length > 0
|
|
|
|
|
? await AppDataSource.getRepository(OrgChild1)
|
|
|
|
|
.createQueryBuilder("orgChild1")
|
|
|
|
|
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
|
|
|
|
.select([
|
|
|
|
|
"orgChild1.id",
|
|
|
|
|
"orgChild1.orgChild1Name",
|
|
|
|
|
"orgChild1.orgChild1ShortName",
|
|
|
|
|
"orgChild1.orgChild1Code",
|
|
|
|
|
"orgChild1.orgChild1Order",
|
|
|
|
|
"orgChild1.orgChild1PhoneEx",
|
|
|
|
|
"orgChild1.orgChild1PhoneIn",
|
|
|
|
|
"orgChild1.orgChild1Fax",
|
|
|
|
|
"orgChild1.orgRootId",
|
2024-01-30 10:29:03 +07:00
|
|
|
"orgChild1.orgChild1Rank",
|
2024-01-29 17:29:15 +07:00
|
|
|
])
|
2024-01-30 16:39:22 +07:00
|
|
|
.orderBy("orgChild1.createdAt","ASC")
|
2024-01-29 17:29:15 +07:00
|
|
|
.getMany()
|
|
|
|
|
: [];
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
|
2024-01-29 17:29:15 +07:00
|
|
|
const orgChild2Data =
|
|
|
|
|
orgChild1Ids && orgChild1Ids.length > 0
|
|
|
|
|
? await AppDataSource.getRepository(OrgChild2)
|
|
|
|
|
.createQueryBuilder("orgChild2")
|
|
|
|
|
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
|
|
|
|
.select([
|
|
|
|
|
"orgChild2.id",
|
|
|
|
|
"orgChild2.orgChild2Name",
|
|
|
|
|
"orgChild2.orgChild2ShortName",
|
|
|
|
|
"orgChild2.orgChild2Code",
|
|
|
|
|
"orgChild2.orgChild2Order",
|
|
|
|
|
"orgChild2.orgChild2PhoneEx",
|
|
|
|
|
"orgChild2.orgChild2PhoneIn",
|
|
|
|
|
"orgChild2.orgChild2Fax",
|
|
|
|
|
"orgChild2.orgRootId",
|
2024-01-30 10:29:03 +07:00
|
|
|
"orgChild2.orgChild2Rank",
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:29:15 +07:00
|
|
|
"orgChild2.orgChild1Id",
|
|
|
|
|
])
|
2024-01-30 16:39:22 +07:00
|
|
|
.orderBy("orgChild2.createdAt","ASC")
|
2024-01-29 17:29:15 +07:00
|
|
|
.getMany()
|
|
|
|
|
: [];
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
|
2024-01-29 17:29:15 +07:00
|
|
|
const orgChild3Data =
|
|
|
|
|
orgChild2Ids && orgChild2Ids.length > 0
|
|
|
|
|
? await AppDataSource.getRepository(OrgChild3)
|
|
|
|
|
.createQueryBuilder("orgChild3")
|
|
|
|
|
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
|
|
|
|
.select([
|
|
|
|
|
"orgChild3.id",
|
|
|
|
|
"orgChild3.orgChild3Name",
|
|
|
|
|
"orgChild3.orgChild3ShortName",
|
|
|
|
|
"orgChild3.orgChild3Code",
|
|
|
|
|
"orgChild3.orgChild3Order",
|
|
|
|
|
"orgChild3.orgChild3PhoneEx",
|
|
|
|
|
"orgChild3.orgChild3PhoneIn",
|
|
|
|
|
"orgChild3.orgChild3Fax",
|
|
|
|
|
"orgChild3.orgRootId",
|
2024-01-30 10:29:03 +07:00
|
|
|
"orgChild3.orgChild3Rank",
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:29:15 +07:00
|
|
|
"orgChild3.orgChild2Id",
|
|
|
|
|
])
|
2024-01-30 16:39:22 +07:00
|
|
|
.orderBy("orgChild3.createdAt","ASC")
|
2024-01-29 17:29:15 +07:00
|
|
|
.getMany()
|
|
|
|
|
: [];
|
2024-01-29 10:23:58 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
|
2024-01-29 17:29:15 +07:00
|
|
|
const orgChild4Data =
|
|
|
|
|
orgChild3Ids && orgChild3Ids.length > 0
|
|
|
|
|
? await AppDataSource.getRepository(OrgChild4)
|
|
|
|
|
.createQueryBuilder("orgChild4")
|
|
|
|
|
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
|
|
|
|
.select([
|
|
|
|
|
"orgChild4.id",
|
|
|
|
|
"orgChild4.orgChild4Name",
|
|
|
|
|
"orgChild4.orgChild4ShortName",
|
|
|
|
|
"orgChild4.orgChild4Code",
|
|
|
|
|
"orgChild4.orgChild4Order",
|
|
|
|
|
"orgChild4.orgChild4PhoneEx",
|
|
|
|
|
"orgChild4.orgChild4PhoneIn",
|
|
|
|
|
"orgChild4.orgChild4Fax",
|
|
|
|
|
"orgChild4.orgRootId",
|
2024-01-30 10:29:03 +07:00
|
|
|
"orgChild4.orgChild4Rank",
|
2024-01-29 16:21:57 +07:00
|
|
|
|
2024-01-29 17:29:15 +07:00
|
|
|
"orgChild4.orgChild3Id",
|
|
|
|
|
])
|
2024-01-30 16:39:22 +07:00
|
|
|
.orderBy("orgChild4.createdAt","ASC")
|
2024-01-29 17:29:15 +07:00
|
|
|
.getMany()
|
|
|
|
|
: [];
|
2024-01-29 16:26:08 +07:00
|
|
|
|
2024-01-29 17:08:22 +07:00
|
|
|
const formattedData = orgRootData.map((orgRoot) => {
|
|
|
|
|
return {
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeId: orgRoot.id,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgLevel: 0,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeName: orgRoot.orgRootName,
|
|
|
|
|
orgTreeShortName: orgRoot.orgRootShortName,
|
|
|
|
|
orgTreeCode: orgRoot.orgRootCode,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgCode: orgRoot.orgRootCode + "00",
|
2024-01-30 10:29:03 +07:00
|
|
|
orgTreeRank: orgRoot.orgRootRank,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeOrder: orgRoot.orgRootOrder,
|
|
|
|
|
orgTreePhoneEx: orgRoot.orgRootPhoneEx,
|
|
|
|
|
orgTreePhoneIn: orgRoot.orgRootPhoneIn,
|
|
|
|
|
orgTreeFax: orgRoot.orgRootFax,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRevisionId: orgRoot.orgRevisionId,
|
2024-01-30 09:37:20 +07:00
|
|
|
children: orgChild1Data
|
2024-01-29 17:08:22 +07:00
|
|
|
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
|
|
|
|
.map((orgChild1) => ({
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeId: orgChild1.id,
|
2024-01-30 11:53:29 +07:00
|
|
|
orgRootId: orgRoot.id,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgLevel: 1,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeName: orgChild1.orgChild1Name,
|
|
|
|
|
orgTreeShortName: orgChild1.orgChild1ShortName,
|
|
|
|
|
orgTreeCode: orgChild1.orgChild1Code,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
2024-01-30 10:29:03 +07:00
|
|
|
orgTreeRank: orgChild1.orgChild1Rank,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeOrder: orgChild1.orgChild1Order,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRootCode: orgRoot.orgRootCode,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
|
|
|
|
|
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
|
|
|
|
|
orgTreeFax: orgChild1.orgChild1Fax,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRevisionId: orgRoot.orgRevisionId,
|
2024-01-30 09:37:20 +07:00
|
|
|
children: orgChild2Data
|
2024-01-29 17:08:22 +07:00
|
|
|
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
|
|
|
|
|
.map((orgChild2) => ({
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeId: orgChild2.id,
|
2024-01-30 13:22:19 +07:00
|
|
|
orgRootId: orgChild1.id,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgLevel: 2,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeName: orgChild2.orgChild2Name,
|
|
|
|
|
orgTreeShortName: orgChild2.orgChild2ShortName,
|
|
|
|
|
orgTreeCode: orgChild2.orgChild2Code,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
2024-01-30 10:29:03 +07:00
|
|
|
orgTreeRank: orgChild2.orgChild2Rank,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeOrder: orgChild2.orgChild2Order,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRootCode: orgRoot.orgRootCode,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
|
|
|
|
|
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
|
|
|
|
orgTreeFax: orgChild2.orgChild2Fax,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRevisionId: orgRoot.orgRevisionId,
|
2024-01-30 09:37:20 +07:00
|
|
|
children: orgChild3Data
|
2024-01-29 17:08:22 +07:00
|
|
|
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
|
|
|
|
.map((orgChild3) => ({
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeId: orgChild3.id,
|
2024-01-30 13:22:19 +07:00
|
|
|
orgRootId: orgChild2.id,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgLevel: 3,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeName: orgChild3.orgChild3Name,
|
|
|
|
|
orgTreeShortName: orgChild3.orgChild3ShortName,
|
|
|
|
|
orgTreeCode: orgChild3.orgChild3Code,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
2024-01-30 10:29:03 +07:00
|
|
|
orgTreeRank: orgChild3.orgChild3Rank,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeOrder: orgChild3.orgChild3Order,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRootCode: orgRoot.orgRootCode,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
|
|
|
|
|
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
|
|
|
|
|
orgTreeFax: orgChild3.orgChild3Fax,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRevisionId: orgRoot.orgRevisionId,
|
2024-01-30 09:37:20 +07:00
|
|
|
children: orgChild4Data
|
2024-01-29 17:08:22 +07:00
|
|
|
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
|
|
|
|
|
.map((orgChild4) => ({
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeId: orgChild4.id,
|
2024-01-30 13:22:19 +07:00
|
|
|
orgRootId: orgChild3.id,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgLevel: 4,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeName: orgChild4.orgChild4Name,
|
|
|
|
|
orgTreeShortName: orgChild4.orgChild4ShortName,
|
|
|
|
|
orgTreeCode: orgChild4.orgChild4Code,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
2024-01-30 10:29:03 +07:00
|
|
|
orgTreeRank: orgChild4.orgChild4Rank,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreeOrder: orgChild4.orgChild4Order,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRootCode: orgRoot.orgRootCode,
|
2024-01-29 17:48:37 +07:00
|
|
|
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
|
|
|
|
|
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
|
|
|
|
|
orgTreeFax: orgChild4.orgChild4Fax,
|
2024-01-29 17:08:22 +07:00
|
|
|
orgRevisionId: orgRoot.orgRevisionId,
|
|
|
|
|
})),
|
|
|
|
|
})),
|
|
|
|
|
})),
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess(formattedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2024-01-29 10:23:58 +07:00
|
|
|
}
|
2024-01-29 15:46:33 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API ตั้งเวลาเผยแพร่
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_025 - ตั้งเวลาเผยแพร่ (ADMIN) #27
|
|
|
|
|
*
|
2024-01-30 14:18:46 +07:00
|
|
|
* @param {string} id Id revison
|
2024-01-29 15:46:33 +07:00
|
|
|
*/
|
|
|
|
|
@Put("/set/publish/{id}")
|
|
|
|
|
async Edit(
|
|
|
|
|
@Path() id: string,
|
2024-01-29 16:26:08 +07:00
|
|
|
@Body() requestBody: { orgPublishDate: Date },
|
2024-01-29 15:46:33 +07:00
|
|
|
@Request() request: { user: Record<string, any> },
|
|
|
|
|
) {
|
2024-01-30 14:18:46 +07:00
|
|
|
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-01-29 15:46:33 +07:00
|
|
|
try {
|
|
|
|
|
orgRevision.lastUpdateUserId = request.user.sub;
|
|
|
|
|
orgRevision.lastUpdateFullName = request.user.name;
|
|
|
|
|
orgRevision.lastUpdatedAt = new Date();
|
2024-01-29 16:26:08 +07:00
|
|
|
orgRevision.orgPublishDate = requestBody.orgPublishDate;
|
2024-01-29 15:46:33 +07:00
|
|
|
this.orgRevisionRepository.merge(orgRevision, requestBody);
|
|
|
|
|
await this.orgRevisionRepository.save(orgRevision);
|
|
|
|
|
return new HttpSuccess();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-26 13:32:56 +07:00
|
|
|
}
|