Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-02-06 15:44:16 +07:00
commit 08f2c8753e
10 changed files with 265 additions and 85 deletions

View file

@ -22,7 +22,10 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { Not } from "typeorm";
import { In, Not } from "typeorm";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child1")
@Tags("OrgChild1")
@Security("bearerAuth")
@ -36,6 +39,9 @@ export class OrgChild1Controller {
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);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -240,15 +246,27 @@ export class OrgChild1Controller {
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
);
}
const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
if (exitsChild2) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
);
}
// const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
// if (exitsChild2) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
// );
// }
try {
await this.child1Repository.remove(child1);
const posMasters = await this.posMasterRepository.find({
where: { orgChild1Id: 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({ orgChild1Id: id });
await this.child3Repository.delete({ orgChild1Id: id });
await this.child2Repository.delete({ orgChild1Id: id });
await this.child1Repository.delete({id});
return new HttpSuccess();
} catch (error) {
return error;

View file

@ -19,11 +19,15 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child2")
@Tags("OrgChild2")
@Security("bearerAuth")
@ -37,6 +41,9 @@ export class OrgChild2Controller extends Controller {
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);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -253,15 +260,26 @@ export class OrgChild2Controller extends Controller {
);
}
const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
if (exitsChild3) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
// const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
// if (exitsChild3) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
// );
// }
try {
await this.child2Repository.remove(child2);
const posMasters = await this.posMasterRepository.find({
where: { orgChild2Id: 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({ orgChild2Id: id });
await this.child3Repository.delete({ orgChild2Id: id });
await this.child2Repository.delete({ id });
return new HttpSuccess();
} catch (error) {
return error;

View file

@ -22,6 +22,9 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child3")
@Tags("OrgChild3")
@Security("bearerAuth")
@ -35,6 +38,8 @@ export class OrgChild3Controller {
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);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -225,15 +230,25 @@ export class OrgChild3Controller {
);
}
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
if (exitsChild4) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
// const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
// if (exitsChild4) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
// );
// }
try {
await this.child3Repository.remove(child3);
const posMasters = await this.posMasterRepository.find({
where: { orgChild3Id: 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({ orgChild3Id: id });
await this.child3Repository.delete( id );
return new HttpSuccess();
} catch (error) {
return error;

View file

@ -19,11 +19,14 @@ import {
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { In } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { CreateOrgChild4, OrgChild4, UpdateOrgChild4 } from "../entities/OrgChild4";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
@Route("api/v1/org/child4")
@Tags("OrgChild4")
@ -37,6 +40,8 @@ export class OrgChild4Controller extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
/**
@ -258,7 +263,16 @@ export class OrgChild4Controller extends Controller {
);
}
try {
await this.child4Repository.remove(child4);
const posMasters = await this.posMasterRepository.find({
where: { orgChild4Id: 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( id );
return new HttpSuccess();
} catch (error) {
return error;

View file

@ -728,28 +728,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: orgRoot.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
@ -780,28 +780,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild1Id: orgChild1.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -834,28 +834,28 @@ export class OrganizationController extends Controller {
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgChild2Id: orgChild2.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -884,25 +884,25 @@ export class OrganizationController extends Controller {
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
children: await Promise.all(
@ -931,26 +931,26 @@ export class OrganizationController extends Controller {
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: Not(IsNull()) || Not(""),
current_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionCurrentVacant:
await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: IsNull() || "",
current_holderId: IsNull() || "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: Not(IsNull()) || Not(""),
next_holderId: Not(IsNull()) || Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: IsNull() || "",
next_holderId: IsNull() || "",
},
}),
})),

View file

@ -1112,25 +1112,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1151,25 +1151,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1190,25 +1190,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1229,25 +1229,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;
@ -1268,25 +1268,25 @@ export class PositionController extends Controller {
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
next_holderId: IsNull() && "",
},
});
break;

View file

@ -1,4 +1,4 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany, ManyToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { CreatePosDict } from "./PosDict";
import { OrgRevision } from "./OrgRevision";
@ -127,7 +127,7 @@ export class PosMaster extends EntityBase {
"คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้",
default: null,
})
profileIdCurrentHolder: string;
current_holderId: string;
@Column({
nullable: true,
@ -136,7 +136,7 @@ export class PosMaster extends EntityBase {
"คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย",
default: null,
})
profileIdNextHolder: string;
next_holderId: string;
@Column({
length: 40,
@ -168,13 +168,13 @@ export class PosMaster extends EntityBase {
@JoinColumn({ name: "orgChild4Id" })
orgChild4: OrgChild4;
@OneToOne(() => Profile)
@JoinColumn()
current_holder: Profile;
@ManyToOne(() => PosMaster, (posMaster) => posMaster.current_holder)
@JoinColumn({ name: "current_holderId" })
current_holder: Profile[];
@OneToOne(() => Profile)
@JoinColumn()
next_holder: Profile;
@ManyToOne(() => PosMaster, (posMaster) => posMaster.next_holder)
@JoinColumn({ name: "next_holderId" })
next_holder: Profile[];
@OneToMany(() => Position, (position) => position.posMaster)
positions: Position[];

View file

@ -1,4 +1,4 @@
import { Entity, Column, OneToMany, OneToOne, JoinColumn} from "typeorm";
import { Entity, Column, OneToMany, OneToOne, JoinColumn, ManyToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { PosMaster } from "./PosMaster";
@ -32,17 +32,34 @@ export class Profile extends EntityBase {
nullable: true,
comment: "เลขประจำตัวประชาชน",
default: null,
length: 13
length: 13,
})
citizenId: string;
@OneToOne(() => PosMaster)
@JoinColumn()
current_holder: PosMaster;
// @Column({
// nullable: true,
// length: 40,
// comment:
// "คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้",
// default: null,
// unique: false,
// })
// current_holderId: string;
@OneToOne(() => PosMaster)
@JoinColumn()
next_holder: PosMaster;
// @Column({
// nullable: true,
// length: 40,
// comment:
// "คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย",
// default: null,
// unique: false,
// })
// next_holderId: string;
@OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder)
current_holders: PosMaster[];
@OneToMany(() => PosMaster, (posMaster) => posMaster.next_holder)
next_holders: PosMaster[];
}
export class CreateProfile {
@ -59,6 +76,4 @@ export class CreateProfile {
citizenId: string;
}
export type UpdateProfile = Partial<CreateProfile>;

View file

@ -0,0 +1,56 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableProfile31707207718721 implements MigrationInterface {
name = 'AddTableProfile31707207718721'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_d15696d0e541ead772db817b36a\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_dca00872043f09a74af1d5172f3\``);
await queryRunner.query(`DROP INDEX \`FK_1acc4ba5b4af308f0d8a1b7b249\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`FK_9d29f52dcf499db3a5e8209b6dc\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`IDX_d15696d0e541ead772db817b36\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`IDX_dca00872043f09a74af1d5172f\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`REL_d15696d0e541ead772db817b36\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`REL_dca00872043f09a74af1d5172f\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`IDX_49d2dcf6c8bd789ca99df7dc0d\` ON \`profile\``);
await queryRunner.query(`DROP INDEX \`IDX_b5bfc34771c02a8078b9bf8944\` ON \`profile\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`currentHolderId\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`nextHolderId\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`profileIdCurrentHolder\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`profileIdNextHolder\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`current_holderId\` varchar(40) NULL COMMENT 'คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD UNIQUE INDEX \`IDX_9f765a0fef405dfafbd1b5f6c0\` (\`current_holderId\`)`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`next_holderId\` varchar(40) NULL COMMENT 'คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD UNIQUE INDEX \`IDX_22499e79738c6873fc7ede3f6d\` (\`next_holderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_9f765a0fef405dfafbd1b5f6c0\` ON \`posMaster\` (\`current_holderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_22499e79738c6873fc7ede3f6d\` ON \`posMaster\` (\`next_holderId\`)`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_9f765a0fef405dfafbd1b5f6c0a\` FOREIGN KEY (\`current_holderId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_22499e79738c6873fc7ede3f6dd\` FOREIGN KEY (\`next_holderId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_22499e79738c6873fc7ede3f6dd\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_9f765a0fef405dfafbd1b5f6c0a\``);
await queryRunner.query(`DROP INDEX \`REL_22499e79738c6873fc7ede3f6d\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`REL_9f765a0fef405dfafbd1b5f6c0\` ON \`posMaster\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP INDEX \`IDX_22499e79738c6873fc7ede3f6d\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`next_holderId\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP INDEX \`IDX_9f765a0fef405dfafbd1b5f6c0\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`current_holderId\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`profileIdNextHolder\` varchar(40) NULL COMMENT 'คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`profileIdCurrentHolder\` varchar(40) NULL COMMENT 'คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`nextHolderId\` varchar(36) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`currentHolderId\` varchar(36) NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_b5bfc34771c02a8078b9bf8944\` ON \`profile\` (\`currentHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_49d2dcf6c8bd789ca99df7dc0d\` ON \`profile\` (\`nextHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_dca00872043f09a74af1d5172f\` ON \`posMaster\` (\`currentHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_d15696d0e541ead772db817b36\` ON \`posMaster\` (\`nextHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_dca00872043f09a74af1d5172f\` ON \`posMaster\` (\`currentHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_d15696d0e541ead772db817b36\` ON \`posMaster\` (\`nextHolderId\`)`);
await queryRunner.query(`CREATE INDEX \`FK_9d29f52dcf499db3a5e8209b6dc\` ON \`posMaster\` (\`profileIdNextHolder\`)`);
await queryRunner.query(`CREATE INDEX \`FK_1acc4ba5b4af308f0d8a1b7b249\` ON \`posMaster\` (\`profileIdCurrentHolder\`)`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_dca00872043f09a74af1d5172f3\` FOREIGN KEY (\`currentHolderId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_d15696d0e541ead772db817b36a\` FOREIGN KEY (\`nextHolderId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}

View file

@ -0,0 +1,44 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableProfile41707207914350 implements MigrationInterface {
name = 'AddTableProfile41707207914350'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_49d2dcf6c8bd789ca99df7dc0d4\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_b5bfc34771c02a8078b9bf89445\``);
await queryRunner.query(`DROP INDEX \`IDX_22499e79738c6873fc7ede3f6d\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`IDX_9f765a0fef405dfafbd1b5f6c0\` ON \`posMaster\``);
await queryRunner.query(`DROP INDEX \`REL_49d2dcf6c8bd789ca99df7dc0d\` ON \`profile\``);
await queryRunner.query(`DROP INDEX \`REL_b5bfc34771c02a8078b9bf8944\` ON \`profile\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`currentHolderId\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`nextHolderId\``);
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`current_holderId\` varchar(40) NULL COMMENT 'คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้'`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD UNIQUE INDEX \`IDX_ee79137a2909faa188c20a7041\` (\`current_holderId\`)`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`next_holderId\` varchar(40) NULL COMMENT 'คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย'`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD UNIQUE INDEX \`IDX_c2ff3f61c281ece7f3ab5a2c20\` (\`next_holderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_ee79137a2909faa188c20a7041\` ON \`profile\` (\`current_holderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_c2ff3f61c281ece7f3ab5a2c20\` ON \`profile\` (\`next_holderId\`)`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_ee79137a2909faa188c20a70413\` FOREIGN KEY (\`current_holderId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_c2ff3f61c281ece7f3ab5a2c20b\` FOREIGN KEY (\`next_holderId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_c2ff3f61c281ece7f3ab5a2c20b\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP FOREIGN KEY \`FK_ee79137a2909faa188c20a70413\``);
await queryRunner.query(`DROP INDEX \`REL_c2ff3f61c281ece7f3ab5a2c20\` ON \`profile\``);
await queryRunner.query(`DROP INDEX \`REL_ee79137a2909faa188c20a7041\` ON \`profile\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP INDEX \`IDX_c2ff3f61c281ece7f3ab5a2c20\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`next_holderId\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP INDEX \`IDX_ee79137a2909faa188c20a7041\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`current_holderId\``);
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`nextHolderId\` varchar(36) NULL`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`currentHolderId\` varchar(36) NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_b5bfc34771c02a8078b9bf8944\` ON \`profile\` (\`currentHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_49d2dcf6c8bd789ca99df7dc0d\` ON \`profile\` (\`nextHolderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_9f765a0fef405dfafbd1b5f6c0\` ON \`posMaster\` (\`current_holderId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_22499e79738c6873fc7ede3f6d\` ON \`posMaster\` (\`next_holderId\`)`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_b5bfc34771c02a8078b9bf89445\` FOREIGN KEY (\`currentHolderId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`profile\` ADD CONSTRAINT \`FK_49d2dcf6c8bd789ca99df7dc0d4\` FOREIGN KEY (\`nextHolderId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}