isAncestorDNA to ancestorDNA

This commit is contained in:
Kittapath 2024-02-01 13:29:15 +07:00
parent 22b80868d4
commit 2832ab2268
9 changed files with 143 additions and 80 deletions

View file

@ -105,6 +105,9 @@ export class OrganizationController extends Controller {
activeName: orgRevisionActive == null ? null : orgRevisionActive.orgRevisionName, activeName: orgRevisionActive == null ? null : orgRevisionActive.orgRevisionName,
draftId: orgRevisionDraf == null ? null : orgRevisionDraf.id, draftId: orgRevisionDraf == null ? null : orgRevisionDraf.id,
draftName: orgRevisionDraf == null ? null : orgRevisionDraf.orgRevisionName, draftName: orgRevisionDraf == null ? null : orgRevisionDraf.orgRevisionName,
orgPublishDate: orgRevisionDraf == null ? null : orgRevisionDraf.orgPublishDate,
isPublic: orgRevisionDraf == null || orgRevisionDraf.orgRevisionName == null ? false : true,
}; };
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} catch (error) { } catch (error) {
@ -152,10 +155,10 @@ export class OrganizationController extends Controller {
}); });
const _orgRoot = orgRoot.map((x) => ({ const _orgRoot = orgRoot.map((x) => ({
...x, ...x,
isAncestorDNA: ancestorDNA:
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000" x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.isAncestorDNA, : x.ancestorDNA,
})); }));
await this.orgRootRepository.save(_orgRoot); await this.orgRootRepository.save(_orgRoot);
@ -169,10 +172,10 @@ export class OrganizationController extends Controller {
const _orgChild1 = orgChild1.map((x) => ({ const _orgChild1 = orgChild1.map((x) => ({
...x, ...x,
isAncestorDNA: ancestorDNA:
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000" x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.isAncestorDNA, : x.ancestorDNA,
})); }));
await this.child1Repository.save(_orgChild1); await this.child1Repository.save(_orgChild1);
@ -189,11 +192,11 @@ export class OrganizationController extends Controller {
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
const _posMaster = x.posMasters.map((item: any) => ({ const _posMaster = x.posMasters.map((item: any) => ({
...item, ...item,
isAncestorDNA: ancestorDNA:
item.isAncestorDNA == null || item.ancestorDNA == null ||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000" item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? item.id ? item.id
: item.isAncestorDNA, : item.ancestorDNA,
})); }));
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await Promise.all( await Promise.all(
@ -245,10 +248,10 @@ export class OrganizationController extends Controller {
}); });
const _orgChild2 = orgChild2.map((x) => ({ const _orgChild2 = orgChild2.map((x) => ({
...x, ...x,
isAncestorDNA: ancestorDNA:
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000" x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.isAncestorDNA, : x.ancestorDNA,
})); }));
await this.child2Repository.save(_orgChild2); await this.child2Repository.save(_orgChild2);
@ -266,11 +269,11 @@ export class OrganizationController extends Controller {
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
const _posMaster = x.posMasters.map((item: any) => ({ const _posMaster = x.posMasters.map((item: any) => ({
...item, ...item,
isAncestorDNA: ancestorDNA:
item.isAncestorDNA == null || item.ancestorDNA == null ||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000" item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? item.id ? item.id
: item.isAncestorDNA, : item.ancestorDNA,
})); }));
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await Promise.all( await Promise.all(
@ -325,11 +328,10 @@ export class OrganizationController extends Controller {
}); });
const _orgChild3 = orgChild3.map((x) => ({ const _orgChild3 = orgChild3.map((x) => ({
...x, ...x,
isAncestorDNA: ancestorDNA:
x.isAncestorDNA == null || x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.isAncestorDNA, : x.ancestorDNA,
})); }));
await this.child3Repository.save(_orgChild3); await this.child3Repository.save(_orgChild3);
@ -348,11 +350,11 @@ export class OrganizationController extends Controller {
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
const _posMaster = x.posMasters.map((item: any) => ({ const _posMaster = x.posMasters.map((item: any) => ({
...item, ...item,
isAncestorDNA: ancestorDNA:
item.isAncestorDNA == null || item.ancestorDNA == null ||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000" item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? item.id ? item.id
: item.isAncestorDNA, : item.ancestorDNA,
})); }));
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await Promise.all( await Promise.all(
@ -409,11 +411,10 @@ export class OrganizationController extends Controller {
}); });
const _orgChild4 = orgChild4.map((x) => ({ const _orgChild4 = orgChild4.map((x) => ({
...x, ...x,
isAncestorDNA: ancestorDNA:
x.isAncestorDNA == null || x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.isAncestorDNA, : x.ancestorDNA,
})); }));
await this.child4Repository.save(_orgChild4); await this.child4Repository.save(_orgChild4);
@ -433,11 +434,11 @@ export class OrganizationController extends Controller {
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
const _posMaster = x.posMasters.map((item: any) => ({ const _posMaster = x.posMasters.map((item: any) => ({
...item, ...item,
isAncestorDNA: ancestorDNA:
item.isAncestorDNA == null || item.ancestorDNA == null ||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000" item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? item.id ? item.id
: item.isAncestorDNA, : item.ancestorDNA,
})); }));
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await Promise.all( await Promise.all(
@ -498,11 +499,11 @@ export class OrganizationController extends Controller {
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
const _posMaster = x.posMasters.map((item: any) => ({ const _posMaster = x.posMasters.map((item: any) => ({
...item, ...item,
isAncestorDNA: ancestorDNA:
item.isAncestorDNA == null || item.ancestorDNA == null ||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000" item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? item.id ? item.id
: item.isAncestorDNA, : item.ancestorDNA,
})); }));
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await Promise.all( await Promise.all(
@ -867,11 +868,11 @@ export class OrganizationController extends Controller {
} }
const datas = await this.child1Repository const datas = await this.child1Repository
.createQueryBuilder("child1") .createQueryBuilder("child1")
.where("child1.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild1.isAncestorDNA }) .where("child1.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild1.ancestorDNA })
.andWhere("child1.isAncestorDNA <> :nullUUID", { .andWhere("child1.ancestorDNA <> :nullUUID", {
nullUUID: "00000000-0000-0000-0000-000000000000", nullUUID: "00000000-0000-0000-0000-000000000000",
}) })
.andWhere("child1.isAncestorDNA IS NOT NULL") .andWhere("child1.ancestorDNA IS NOT NULL")
.leftJoinAndSelect("child1.orgRevision", "orgRevision") .leftJoinAndSelect("child1.orgRevision", "orgRevision")
.orderBy("child1.lastUpdatedAt", "DESC") .orderBy("child1.lastUpdatedAt", "DESC")
.getMany(); .getMany();
@ -891,11 +892,11 @@ export class OrganizationController extends Controller {
} }
const datas = await this.child2Repository const datas = await this.child2Repository
.createQueryBuilder("child2") .createQueryBuilder("child2")
.where("child2.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild2.isAncestorDNA }) .where("child2.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild2.ancestorDNA })
.andWhere("child2.isAncestorDNA <> :nullUUID", { .andWhere("child2.ancestorDNA <> :nullUUID", {
nullUUID: "00000000-0000-0000-0000-000000000000", nullUUID: "00000000-0000-0000-0000-000000000000",
}) })
.andWhere("child2.isAncestorDNA IS NOT NULL") .andWhere("child2.ancestorDNA IS NOT NULL")
.leftJoinAndSelect("child2.orgRevision", "orgRevision") .leftJoinAndSelect("child2.orgRevision", "orgRevision")
.orderBy("child2.lastUpdatedAt", "DESC") .orderBy("child2.lastUpdatedAt", "DESC")
.getMany(); .getMany();
@ -915,11 +916,11 @@ export class OrganizationController extends Controller {
} }
const datas = await this.child3Repository const datas = await this.child3Repository
.createQueryBuilder("child3") .createQueryBuilder("child3")
.where("child3.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild3.isAncestorDNA }) .where("child3.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild3.ancestorDNA })
.andWhere("child3.isAncestorDNA <> :nullUUID", { .andWhere("child3.ancestorDNA <> :nullUUID", {
nullUUID: "00000000-0000-0000-0000-000000000000", nullUUID: "00000000-0000-0000-0000-000000000000",
}) })
.andWhere("child3.isAncestorDNA IS NOT NULL") .andWhere("child3.ancestorDNA IS NOT NULL")
.leftJoinAndSelect("child3.orgRevision", "orgRevision") .leftJoinAndSelect("child3.orgRevision", "orgRevision")
.orderBy("child3.lastUpdatedAt", "DESC") .orderBy("child3.lastUpdatedAt", "DESC")
.getMany(); .getMany();
@ -939,11 +940,11 @@ export class OrganizationController extends Controller {
} }
const datas = await this.child4Repository const datas = await this.child4Repository
.createQueryBuilder("child4") .createQueryBuilder("child4")
.where("child4.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild4.isAncestorDNA }) .where("child4.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild4.ancestorDNA })
.andWhere("child4.isAncestorDNA <> :nullUUID", { .andWhere("child4.ancestorDNA <> :nullUUID", {
nullUUID: "00000000-0000-0000-0000-000000000000", nullUUID: "00000000-0000-0000-0000-000000000000",
}) })
.andWhere("child4.isAncestorDNA IS NOT NULL") .andWhere("child4.ancestorDNA IS NOT NULL")
.leftJoinAndSelect("child4.orgRevision", "orgRevision") .leftJoinAndSelect("child4.orgRevision", "orgRevision")
.orderBy("child4.lastUpdatedAt", "DESC") .orderBy("child4.lastUpdatedAt", "DESC")
.getMany(); .getMany();
@ -963,11 +964,11 @@ export class OrganizationController extends Controller {
} }
const datas = await this.orgRootRepository const datas = await this.orgRootRepository
.createQueryBuilder("root") .createQueryBuilder("root")
.where("root.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgRoot.isAncestorDNA }) .where("root.ancestorDNA = :ancestorDNA", { ancestorDNA: orgRoot.ancestorDNA })
.andWhere("root.isAncestorDNA <> :nullUUID", { .andWhere("root.ancestorDNA <> :nullUUID", {
nullUUID: "00000000-0000-0000-0000-000000000000", nullUUID: "00000000-0000-0000-0000-000000000000",
}) })
.andWhere("root.isAncestorDNA IS NOT NULL") .andWhere("root.ancestorDNA IS NOT NULL")
.leftJoinAndSelect("root.orgRevision", "orgRevision") .leftJoinAndSelect("root.orgRevision", "orgRevision")
.orderBy("root.lastUpdatedAt", "DESC") .orderBy("root.lastUpdatedAt", "DESC")
.getMany(); .getMany();
@ -1104,4 +1105,42 @@ export class OrganizationController extends Controller {
return error; return error;
} }
} }
/**
* API
*
* @summary ORG_053 - (ADMIN) #57
*
* @param {string} id Id revison
*/
@Get("/get/publish")
async runPublish() {
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();
// 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);
return new HttpSuccess();
}
} }

View file

@ -507,9 +507,9 @@ export class PositionController extends Controller {
} }
/** /**
* API * API
* *
* @summary ORG_033 - (ADMIN) #35 * @summary ORG_034 - (ADMIN) #37
* *
*/ */
@Put("master/{id}") @Put("master/{id}")
@ -737,38 +737,38 @@ export class PositionController extends Controller {
typeCondition = { typeCondition = {
orgRootId: body.id, orgRootId: body.id,
}; };
if (!body.isAll) { if (!body.isAll) {
checkChildConditions = { checkChildConditions = {
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
}; };
} }
} else if (body.type === 1) { } else if (body.type === 1) {
typeCondition = { typeCondition = {
orgChild1Id: body.id, orgChild1Id: body.id,
}; };
if (!body.isAll) { if (!body.isAll) {
checkChildConditions = { checkChildConditions = {
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
}; };
} }
} else if (body.type === 2) { } else if (body.type === 2) {
typeCondition = { typeCondition = {
orgChild2Id: body.id, orgChild2Id: body.id,
}; };
if (!body.isAll) { if (!body.isAll) {
checkChildConditions = { checkChildConditions = {
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
}; };
} }
} else if (body.type === 3) { } else if (body.type === 3) {
typeCondition = { typeCondition = {
orgChild3Id: body.id, orgChild3Id: body.id,
}; };
if (!body.isAll) { if (!body.isAll) {
checkChildConditions = { checkChildConditions = {
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
}; };
} }
} else if (body.type === 4) { } else if (body.type === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.id, orgChild4Id: body.id,

View file

@ -95,7 +95,7 @@ export class OrgChild1 extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild1s) @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild1s)
@JoinColumn({ name: "orgRevisionId" }) @JoinColumn({ name: "orgRevisionId" })

View file

@ -99,7 +99,7 @@ export class OrgChild2 extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild2s) @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild2s)
@JoinColumn({ name: "orgRevisionId" }) @JoinColumn({ name: "orgRevisionId" })

View file

@ -105,7 +105,7 @@ export class OrgChild3 extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild3s) @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild3s)
@JoinColumn({ name: "orgRevisionId" }) @JoinColumn({ name: "orgRevisionId" })

View file

@ -109,7 +109,7 @@ export class OrgChild4 extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild4s) @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild4s)
@JoinColumn({ name: "orgRevisionId" }) @JoinColumn({ name: "orgRevisionId" })

View file

@ -85,7 +85,7 @@ export class OrgRoot extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@Column({ @Column({
length: 40, length: 40,

View file

@ -54,7 +54,7 @@ export class PosMaster extends EntityBase {
length: 40, length: 40,
default: null, default: null,
}) })
isAncestorDNA: string; ancestorDNA: string;
@Column({ @Column({
nullable: true, nullable: true,

View file

@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableAncestorDNA1706768882759 implements MigrationInterface {
name = 'UpdateTableAncestorDNA1706768882759'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`orgChild4\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild3\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild2\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild1\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`isAncestorDNA\` \`ancestorDNA\` varchar(40) NULL COMMENT 'รหัส DNA ใช้ในกรณีที่มีการทำสำเนาโครงสร้างและตำแหน่ง ตำแหน่งที่ทำสำเนามากับตำแหน่งเก่าจะต้องมี DNA เดียวกัน เพื่อให้ track ประวัติการแก้ไขตำแหน่งย้อนหลังได้'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL COMMENT 'รหัส DNA ใช้ในกรณีที่มีการทำสำเนาโครงสร้างและตำแหน่ง ตำแหน่งที่ทำสำเนามากับตำแหน่งเก่าจะต้องมี DNA เดียวกัน เพื่อให้ track ประวัติการแก้ไขตำแหน่งย้อนหลังได้'`);
await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild1\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild2\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild3\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`orgChild4\` CHANGE \`ancestorDNA\` \`isAncestorDNA\` varchar(40) NULL`);
}
}