add isDeputy
This commit is contained in:
parent
96edba3c08
commit
7aeafcd723
4 changed files with 83 additions and 0 deletions
|
|
@ -72,6 +72,7 @@ export class OrgRootController extends Controller {
|
|||
orgRootPhoneIn: orgRoot.orgRootPhoneIn,
|
||||
orgRootFax: orgRoot.orgRootFax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
isDeputy: orgRoot.isDeputy,
|
||||
orgCode: orgRoot.orgRootCode + "00",
|
||||
};
|
||||
return new HttpSuccess(getOrgRoot);
|
||||
|
|
@ -102,6 +103,24 @@ export class OrgRootController extends Controller {
|
|||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_ORG");
|
||||
|
||||
if (requestBody.isDeputy == true) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
relations: ["orgRoots"],
|
||||
});
|
||||
if (orgRevision != null) {
|
||||
await Promise.all(
|
||||
orgRevision.orgRoots
|
||||
.filter((x: OrgRoot) => x.isDeputy == true)
|
||||
.map(async (item: OrgRoot) => {
|
||||
item.isDeputy = false;
|
||||
await this.orgRootRepository.save(item);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
|
||||
|
|
@ -193,6 +212,23 @@ export class OrgRootController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRo otRank");
|
||||
}
|
||||
|
||||
if (requestBody.isDeputy == true) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
relations: ["orgRoots"],
|
||||
});
|
||||
if (orgRevision != null) {
|
||||
await Promise.all(
|
||||
orgRevision.orgRoots
|
||||
.filter((x: OrgRoot) => x.isDeputy == true)
|
||||
.map(async (item: OrgRoot) => {
|
||||
item.isDeputy = false;
|
||||
await this.orgRootRepository.save(item);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -732,6 +732,7 @@ export class OrganizationController extends Controller {
|
|||
// )
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.isDeputy",
|
||||
"orgRoot.orgRootName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgRoot.orgRootCode",
|
||||
|
|
@ -906,6 +907,7 @@ export class OrganizationController extends Controller {
|
|||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgRoot.responsibility,
|
||||
isOfficer: false,
|
||||
isDeputy: orgRoot.isDeputy,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
|
|
@ -1552,6 +1554,7 @@ export class OrganizationController extends Controller {
|
|||
})
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.isDeputy",
|
||||
"orgRoot.orgRootName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgRoot.orgRootCode",
|
||||
|
|
@ -1685,6 +1688,7 @@ export class OrganizationController extends Controller {
|
|||
orgTreeFax: orgRoot.orgRootFax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
isDeputy: orgRoot.isDeputy,
|
||||
responsibility: orgRoot.responsibility,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
|
|
@ -2322,6 +2326,7 @@ export class OrganizationController extends Controller {
|
|||
)
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.isDeputy",
|
||||
"orgRoot.orgRootName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgRoot.orgRootCode",
|
||||
|
|
@ -2495,6 +2500,7 @@ export class OrganizationController extends Controller {
|
|||
orgTreeFax: orgRoot.orgRootFax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
isDeputy:orgRoot.isDeputy,
|
||||
responsibility: orgRoot.responsibility,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
|
|
@ -6606,6 +6612,24 @@ export class OrganizationController extends Controller {
|
|||
const check = orgRevision.orgChild1s.find((x) => x.isOfficer == true);
|
||||
return new HttpSuccess(check != null);
|
||||
}
|
||||
/**
|
||||
* API เช็ค org ในระบบ
|
||||
*
|
||||
* @summary - เช็ค org ในระบบ (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Get("check/root/{id}")
|
||||
async findIsDeputyRoot(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["orgRoots"],
|
||||
});
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const check = orgRevision.orgRoots.find((x) => x.isDeputy == true);
|
||||
return new HttpSuccess(check != null);
|
||||
}
|
||||
public async listAuthSysOrgFuncByRevisionIdN(
|
||||
request: RequestWithUser,
|
||||
system: string,
|
||||
|
|
|
|||
|
|
@ -105,6 +105,12 @@ export class OrgRoot extends EntityBase {
|
|||
})
|
||||
responsibility: string;
|
||||
|
||||
@Column({
|
||||
comment: "เป็นปลัด",
|
||||
default: false,
|
||||
})
|
||||
isDeputy: boolean;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง orgRevision",
|
||||
|
|
@ -164,6 +170,9 @@ export class CreateOrgRoot {
|
|||
|
||||
@Column("uuid")
|
||||
orgRevisionId: string;
|
||||
|
||||
@Column()
|
||||
isDeputy: boolean;
|
||||
}
|
||||
|
||||
export type UpdateOrgRoot = Partial<CreateOrgRoot> & { orgRootRank?: OrgRootRank };
|
||||
|
|
|
|||
14
src/migration/1729505298515-update_root_add_isdeputy.ts
Normal file
14
src/migration/1729505298515-update_root_add_isdeputy.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRootAddIsdeputy1729505298515 implements MigrationInterface {
|
||||
name = 'UpdateRootAddIsdeputy1729505298515'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`orgRoot\` ADD \`isDeputy\` tinyint NOT NULL COMMENT 'เป็นปลัด' DEFAULT 0`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`orgRoot\` DROP COLUMN \`isDeputy\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue