isAncestorDNA to ancestorDNA
This commit is contained in:
parent
22b80868d4
commit
2832ab2268
9 changed files with 143 additions and 80 deletions
|
|
@ -105,6 +105,9 @@ export class OrganizationController extends Controller {
|
|||
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);
|
||||
} catch (error) {
|
||||
|
|
@ -152,10 +155,10 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
const _orgRoot = orgRoot.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
await this.orgRootRepository.save(_orgRoot);
|
||||
|
||||
|
|
@ -169,10 +172,10 @@ export class OrganizationController extends Controller {
|
|||
|
||||
const _orgChild1 = orgChild1.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
await this.child1Repository.save(_orgChild1);
|
||||
|
||||
|
|
@ -189,11 +192,11 @@ export class OrganizationController extends Controller {
|
|||
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
const _posMaster = x.posMasters.map((item: any) => ({
|
||||
...item,
|
||||
isAncestorDNA:
|
||||
item.isAncestorDNA == null ||
|
||||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
item.ancestorDNA == null ||
|
||||
item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? item.id
|
||||
: item.isAncestorDNA,
|
||||
: item.ancestorDNA,
|
||||
}));
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await Promise.all(
|
||||
|
|
@ -245,10 +248,10 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
const _orgChild2 = orgChild2.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
await this.child2Repository.save(_orgChild2);
|
||||
|
||||
|
|
@ -266,11 +269,11 @@ export class OrganizationController extends Controller {
|
|||
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
const _posMaster = x.posMasters.map((item: any) => ({
|
||||
...item,
|
||||
isAncestorDNA:
|
||||
item.isAncestorDNA == null ||
|
||||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
item.ancestorDNA == null ||
|
||||
item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? item.id
|
||||
: item.isAncestorDNA,
|
||||
: item.ancestorDNA,
|
||||
}));
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await Promise.all(
|
||||
|
|
@ -325,11 +328,10 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
const _orgChild3 = orgChild3.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null ||
|
||||
x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
await this.child3Repository.save(_orgChild3);
|
||||
|
||||
|
|
@ -348,11 +350,11 @@ export class OrganizationController extends Controller {
|
|||
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
const _posMaster = x.posMasters.map((item: any) => ({
|
||||
...item,
|
||||
isAncestorDNA:
|
||||
item.isAncestorDNA == null ||
|
||||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
item.ancestorDNA == null ||
|
||||
item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? item.id
|
||||
: item.isAncestorDNA,
|
||||
: item.ancestorDNA,
|
||||
}));
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await Promise.all(
|
||||
|
|
@ -409,11 +411,10 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
const _orgChild4 = orgChild4.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null ||
|
||||
x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
await this.child4Repository.save(_orgChild4);
|
||||
|
||||
|
|
@ -433,11 +434,11 @@ export class OrganizationController extends Controller {
|
|||
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
const _posMaster = x.posMasters.map((item: any) => ({
|
||||
...item,
|
||||
isAncestorDNA:
|
||||
item.isAncestorDNA == null ||
|
||||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
item.ancestorDNA == null ||
|
||||
item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? item.id
|
||||
: item.isAncestorDNA,
|
||||
: item.ancestorDNA,
|
||||
}));
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await Promise.all(
|
||||
|
|
@ -498,11 +499,11 @@ export class OrganizationController extends Controller {
|
|||
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
const _posMaster = x.posMasters.map((item: any) => ({
|
||||
...item,
|
||||
isAncestorDNA:
|
||||
item.isAncestorDNA == null ||
|
||||
item.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
ancestorDNA:
|
||||
item.ancestorDNA == null ||
|
||||
item.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? item.id
|
||||
: item.isAncestorDNA,
|
||||
: item.ancestorDNA,
|
||||
}));
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
await Promise.all(
|
||||
|
|
@ -867,11 +868,11 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child1Repository
|
||||
.createQueryBuilder("child1")
|
||||
.where("child1.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild1.isAncestorDNA })
|
||||
.andWhere("child1.isAncestorDNA <> :nullUUID", {
|
||||
.where("child1.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild1.ancestorDNA })
|
||||
.andWhere("child1.ancestorDNA <> :nullUUID", {
|
||||
nullUUID: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
.andWhere("child1.isAncestorDNA IS NOT NULL")
|
||||
.andWhere("child1.ancestorDNA IS NOT NULL")
|
||||
.leftJoinAndSelect("child1.orgRevision", "orgRevision")
|
||||
.orderBy("child1.lastUpdatedAt", "DESC")
|
||||
.getMany();
|
||||
|
|
@ -891,11 +892,11 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child2Repository
|
||||
.createQueryBuilder("child2")
|
||||
.where("child2.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild2.isAncestorDNA })
|
||||
.andWhere("child2.isAncestorDNA <> :nullUUID", {
|
||||
.where("child2.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild2.ancestorDNA })
|
||||
.andWhere("child2.ancestorDNA <> :nullUUID", {
|
||||
nullUUID: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
.andWhere("child2.isAncestorDNA IS NOT NULL")
|
||||
.andWhere("child2.ancestorDNA IS NOT NULL")
|
||||
.leftJoinAndSelect("child2.orgRevision", "orgRevision")
|
||||
.orderBy("child2.lastUpdatedAt", "DESC")
|
||||
.getMany();
|
||||
|
|
@ -915,11 +916,11 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child3Repository
|
||||
.createQueryBuilder("child3")
|
||||
.where("child3.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild3.isAncestorDNA })
|
||||
.andWhere("child3.isAncestorDNA <> :nullUUID", {
|
||||
.where("child3.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild3.ancestorDNA })
|
||||
.andWhere("child3.ancestorDNA <> :nullUUID", {
|
||||
nullUUID: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
.andWhere("child3.isAncestorDNA IS NOT NULL")
|
||||
.andWhere("child3.ancestorDNA IS NOT NULL")
|
||||
.leftJoinAndSelect("child3.orgRevision", "orgRevision")
|
||||
.orderBy("child3.lastUpdatedAt", "DESC")
|
||||
.getMany();
|
||||
|
|
@ -939,11 +940,11 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child4Repository
|
||||
.createQueryBuilder("child4")
|
||||
.where("child4.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgChild4.isAncestorDNA })
|
||||
.andWhere("child4.isAncestorDNA <> :nullUUID", {
|
||||
.where("child4.ancestorDNA = :ancestorDNA", { ancestorDNA: orgChild4.ancestorDNA })
|
||||
.andWhere("child4.ancestorDNA <> :nullUUID", {
|
||||
nullUUID: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
.andWhere("child4.isAncestorDNA IS NOT NULL")
|
||||
.andWhere("child4.ancestorDNA IS NOT NULL")
|
||||
.leftJoinAndSelect("child4.orgRevision", "orgRevision")
|
||||
.orderBy("child4.lastUpdatedAt", "DESC")
|
||||
.getMany();
|
||||
|
|
@ -963,11 +964,11 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.orgRootRepository
|
||||
.createQueryBuilder("root")
|
||||
.where("root.isAncestorDNA = :isAncestorDNA", { isAncestorDNA: orgRoot.isAncestorDNA })
|
||||
.andWhere("root.isAncestorDNA <> :nullUUID", {
|
||||
.where("root.ancestorDNA = :ancestorDNA", { ancestorDNA: orgRoot.ancestorDNA })
|
||||
.andWhere("root.ancestorDNA <> :nullUUID", {
|
||||
nullUUID: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
.andWhere("root.isAncestorDNA IS NOT NULL")
|
||||
.andWhere("root.ancestorDNA IS NOT NULL")
|
||||
.leftJoinAndSelect("root.orgRevision", "orgRevision")
|
||||
.orderBy("root.lastUpdatedAt", "DESC")
|
||||
.getMany();
|
||||
|
|
@ -1104,4 +1105,42 @@ export class OrganizationController extends Controller {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,9 +507,9 @@ export class PositionController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API เพิ่มอัตรากำลัง
|
||||
* API แก้ไขเลขที่ตำแหน่ง
|
||||
*
|
||||
* @summary ORG_033 - เพิ่มอัตรากำลัง (ADMIN) #35
|
||||
* @summary ORG_034 - แก้ไขเลขที่ตำแหน่ง (ADMIN) #37
|
||||
*
|
||||
*/
|
||||
@Put("master/{id}")
|
||||
|
|
@ -737,38 +737,38 @@ export class PositionController extends Controller {
|
|||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild1Id: IsNull(),
|
||||
};
|
||||
}
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild1Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild2Id: IsNull(),
|
||||
};
|
||||
}
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild2Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild3Id: IsNull(),
|
||||
};
|
||||
}
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild3Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild4Id: IsNull(),
|
||||
};
|
||||
}
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild4Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.id,
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ export class OrgChild1 extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild1s)
|
||||
@JoinColumn({ name: "orgRevisionId" })
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ export class OrgChild2 extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild2s)
|
||||
@JoinColumn({ name: "orgRevisionId" })
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export class OrgChild3 extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild3s)
|
||||
@JoinColumn({ name: "orgRevisionId" })
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ export class OrgChild4 extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild4s)
|
||||
@JoinColumn({ name: "orgRevisionId" })
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ export class OrgRoot extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export class PosMaster extends EntityBase {
|
|||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
ancestorDNA: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
|
|
|
|||
24
src/migration/1706768882759-update_table_ancestorDNA.ts
Normal file
24
src/migration/1706768882759-update_table_ancestorDNA.ts
Normal 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`);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue