no message
This commit is contained in:
parent
dc88a80904
commit
d083689f68
4 changed files with 256 additions and 215 deletions
|
|
@ -64,6 +64,7 @@ import permission from "../interfaces/permission";
|
|||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import axios from "axios";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { viewCommanderDirector } from "../entities/view/viewCommanderDirector";
|
||||
@Route("api/v1/org/profile")
|
||||
@Tags("Profile")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -103,6 +104,7 @@ export class ProfileController extends Controller {
|
|||
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
|
||||
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
|
||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private viewCommanderDirectorRepository = AppDataSource.getRepository(viewCommanderDirector);
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ข้าราชการ
|
||||
|
|
@ -1229,9 +1231,9 @@ export class ProfileController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("commander-director")
|
||||
async getProfileCommanderDirector(
|
||||
public async getProfileCommanderDirector(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() body: { isDirector: boolean; page: number; pageSize: number; keyword: string },
|
||||
@Body() body: { isDirector: boolean; keyword: string; page: number; pageSize: number },
|
||||
) {
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
|
|
@ -1240,221 +1242,75 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
|
||||
|
||||
let condition: any = {
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
};
|
||||
if (body.isDirector == true) {
|
||||
const [_posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.where({
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||
isDirector: true,
|
||||
current_holderId: Not(IsNull()),
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, ' ', current_holder.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.select([
|
||||
"posMaster.current_holderId",
|
||||
"current_holder.prefix",
|
||||
"current_holder.firstName",
|
||||
"current_holder.lastName",
|
||||
"current_holder.citizenId",
|
||||
"current_holder.position",
|
||||
"current_holder.posLevel",
|
||||
"posLevel.posLevelName",
|
||||
"current_holder.posType",
|
||||
"posType.posTypeName",
|
||||
"posMaster.isDirector",
|
||||
])
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const posMasterActs = await this.posMasterActRepository.find({
|
||||
where: {
|
||||
posMasterId: In(_posMaster.map((x) => x.id)),
|
||||
posMasterChild: {
|
||||
current_holderId: Not(In(_posMaster.map((x) => x.current_holderId))),
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"posMaster",
|
||||
"posMaster.current_holder",
|
||||
"posMasterChild",
|
||||
"posMasterChild.current_holder",
|
||||
"posMasterChild.current_holder.posLevel",
|
||||
"posMasterChild.current_holder.posType",
|
||||
],
|
||||
});
|
||||
let data = _posMaster.map((_data) => ({
|
||||
id: _data.current_holderId || null,
|
||||
prefix: _data.current_holder?.prefix || "",
|
||||
firstName: _data.current_holder?.firstName || "",
|
||||
lastName: _data.current_holder?.lastName || "",
|
||||
citizenId: _data.current_holder?.citizenId || "",
|
||||
position: _data.current_holder?.position || "",
|
||||
posLevel:
|
||||
_data.current_holder?.posLevel == null
|
||||
? null
|
||||
: _data.current_holder?.posLevel?.posLevelName || "",
|
||||
posType:
|
||||
_data.current_holder?.posType == null
|
||||
? null
|
||||
: _data.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: _data.isDirector || false,
|
||||
actFullName: null,
|
||||
}));
|
||||
posMasterActs.map((x) => {
|
||||
let item: any = {
|
||||
id: x.posMasterChild?.current_holderId || null,
|
||||
prefix: x.posMasterChild?.current_holder?.prefix || "",
|
||||
firstName: x.posMasterChild?.current_holder?.firstName || "",
|
||||
lastName: x.posMasterChild?.current_holder?.lastName || "",
|
||||
citizenId: x.posMasterChild?.current_holder?.citizenId || "",
|
||||
position: x.posMasterChild?.current_holder?.position || "",
|
||||
posLevel: x.posMasterChild?.current_holder?.posLevel?.posLevelName || "",
|
||||
posType: x.posMasterChild?.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: x.posMasterChild?.isDirector || true,
|
||||
actFullName: `${x.posMaster?.current_holder?.prefix || ""}${x.posMaster?.current_holder?.firstName || ""} ${x.posMaster?.current_holder?.lastName || ""}`,
|
||||
};
|
||||
data.push(item);
|
||||
});
|
||||
return new HttpSuccess({ data, total });
|
||||
} else {
|
||||
const [_posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.where({
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||
current_holderId: Not(IsNull()),
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, ' ', current_holder.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.select([
|
||||
"posMaster.current_holderId",
|
||||
"current_holder.prefix",
|
||||
"current_holder.firstName",
|
||||
"current_holder.lastName",
|
||||
"current_holder.citizenId",
|
||||
"current_holder.position",
|
||||
"current_holder.posLevel",
|
||||
"posLevel.posLevelName",
|
||||
"current_holder.posType",
|
||||
"posType.posTypeName",
|
||||
"posMaster.isDirector",
|
||||
])
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
let data = _posMaster.map((_data) => ({
|
||||
id: _data.current_holderId || null,
|
||||
prefix: _data.current_holder?.prefix || "",
|
||||
firstName: _data.current_holder?.firstName || "",
|
||||
lastName: _data.current_holder?.lastName || "",
|
||||
citizenId: _data.current_holder?.citizenId || "",
|
||||
position: _data.current_holder?.position || "",
|
||||
posLevel:
|
||||
_data.current_holder?.posLevel == null
|
||||
? null
|
||||
: _data.current_holder?.posLevel?.posLevelName || "",
|
||||
posType:
|
||||
_data.current_holder?.posType == null
|
||||
? null
|
||||
: _data.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: _data.isDirector || false,
|
||||
actFullName: null,
|
||||
}));
|
||||
return new HttpSuccess({ data, total });
|
||||
condition = {
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
isDirector: true,
|
||||
};
|
||||
}
|
||||
const [lists, total] = await AppDataSource.getRepository(viewCommanderDirector)
|
||||
.createQueryBuilder("viewCommanderDirector")
|
||||
.andWhere(condition)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(viewCommanderDirector.prefix,viewCommanderDirector.firstName,' ',viewCommanderDirector.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.posLevel LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.posType LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.actFullName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
68
src/entities/view/viewCommanderDirector.ts
Normal file
68
src/entities/view/viewCommanderDirector.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { ViewColumn, ViewEntity } from "typeorm";
|
||||
|
||||
@ViewEntity({
|
||||
expression: `SELECT
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`Id\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\` AS \`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\` AS \`firstName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\` AS \`lastName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`position\` AS \`position\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
NULL AS \`actFullName\`
|
||||
FROM
|
||||
(((\`bma_ehr_organization_demo\`.\`posMaster\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))
|
||||
UNION SELECT
|
||||
\`profileChild\`.\`id\` AS \`Id\`,
|
||||
\`profileChild\`.\`prefix\` AS \`prefix\`,
|
||||
\`profileChild\`.\`firstName\` AS \`firstName\`,
|
||||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
\`posMasterChild\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
CONCAT(\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\`,
|
||||
' ',
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM
|
||||
((((((\`bma_ehr_organization_demo\`.\`posMasterAct\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` \`posMasterChild\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterId\` = \`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))`,
|
||||
})
|
||||
export class viewCommanderDirector {
|
||||
@ViewColumn()
|
||||
id: string;
|
||||
@ViewColumn()
|
||||
prefix: string;
|
||||
@ViewColumn()
|
||||
firstName: string;
|
||||
@ViewColumn()
|
||||
lastName: string;
|
||||
@ViewColumn()
|
||||
citizenId: string;
|
||||
@ViewColumn()
|
||||
position: string;
|
||||
@ViewColumn()
|
||||
posLevel: string;
|
||||
@ViewColumn()
|
||||
posType: string;
|
||||
@ViewColumn()
|
||||
isDirector: boolean;
|
||||
@ViewColumn()
|
||||
orgRootId: string;
|
||||
@ViewColumn()
|
||||
actFullName: string;
|
||||
}
|
||||
55
src/migration/1729753908963-update_root_add_isdeputy3.ts
Normal file
55
src/migration/1729753908963-update_root_add_isdeputy3.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRootAddIsdeputy31729753908963 implements MigrationInterface {
|
||||
name = 'UpdateRootAddIsdeputy31729753908963'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_commander_director","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_commander_director\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_commander_director\` AS SELECT
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`Id\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\` AS \`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\` AS \`firstName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\` AS \`lastName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`position\` AS \`position\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
NULL AS \`actFullName\`
|
||||
FROM
|
||||
(\`bma_ehr_organization_demo\`.\`posMaster\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))
|
||||
UNION SELECT
|
||||
\`profileChild\`.\`id\` AS \`Id\`,
|
||||
\`profileChild\`.\`prefix\` AS \`prefix\`,
|
||||
\`profileChild\`.\`firstName\` AS \`firstName\`,
|
||||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
\`posMasterChild\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
CONCAT(\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\`,
|
||||
' ',
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM
|
||||
((((\`bma_ehr_organization_demo\`.\`posMasterAct\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` \`posMasterChild\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterId\` = \`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))
|
||||
`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_commander_director","SELECT \n `bma_ehr_organization_demo`.`profile`.`id` AS `Id`,\n `bma_ehr_organization_demo`.`profile`.`prefix` AS `prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName` AS `firstName`,\n `bma_ehr_organization_demo`.`profile`.`lastName` AS `lastName`,\n `bma_ehr_organization_demo`.`profile`.`citizenId` AS `citizenId`,\n `bma_ehr_organization_demo`.`profile`.`position` AS `position`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n NULL AS `actFullName`\n FROM\n (`bma_ehr_organization_demo`.`posMaster`\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`))) \n UNION SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n `posMasterChild`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n CONCAT(`bma_ehr_organization_demo`.`profile`.`prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName`,\n ' ',\n `bma_ehr_organization_demo`.`profile`.`lastName`) AS `actFullName`\n FROM\n ((((`bma_ehr_organization_demo`.`posMasterAct`\n JOIN `bma_ehr_organization_demo`.`posMaster` `posMasterChild` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posMaster` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterId` = `bma_ehr_organization_demo`.`posMaster`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_commander_director","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_commander_director\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_commander_director\` AS SELECT \`profile\`.\`id\` AS \`id\`,\`profile\`.\`prefix\` AS \`prefix\`,\`profile\`.\`firstName\` AS \`firstName\`,\`profile\`.\`lastName\` AS \`lastName\`,\`profile\`.\`citizenId\` AS \`citizenId\`,\`profile\`.\`position\` AS \`position\`,\`posMaster\`.\`isDirector\` AS \`isDirector\`,\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,NULL AS \`actFullName\`
|
||||
FROM (\`posMaster\` JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))
|
||||
UNION SELECT \`profileChild\`.\`id\` AS \`id\`,\`profileChild\`.\`prefix\` AS \`prefix\`,\`profileChild\`.\`firstName\` AS \`firstName\`,\`profileChild\`.\`lastName\` AS \`lastName\`,\`profileChild\`.\`citizenId\` AS \`citizenId\`,\`profileChild\`.\`position\` AS \`position\`,\`posMasterChild\`.\`isDirector\` AS \`isDirector\`,\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,CONCAT(\`profile\`.\`prefix\`,\`profile\`.\`firstName\`,' ',\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM((((\`posMasterAct\` JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_commander_director","SELECT `profile`.`id` AS `id`,`profile`.`prefix` AS `prefix`,`profile`.`firstName` AS `firstName`,`profile`.`lastName` AS `lastName`,`profile`.`citizenId` AS `citizenId`,`profile`.`position` AS `position`,`posMaster`.`isDirector` AS `isDirector`,`posMaster`.`orgRootId` AS `orgRootId`,NULL AS `actFullName`\n FROM (`posMaster` JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`))) \n UNION SELECT `profileChild`.`id` AS `id`,`profileChild`.`prefix` AS `prefix`,`profileChild`.`firstName` AS `firstName`,`profileChild`.`lastName` AS `lastName`,`profileChild`.`citizenId` AS `citizenId`,`profileChild`.`position` AS `position`,`posMasterChild`.`isDirector` AS `isDirector`,`posMaster`.`orgRootId` AS `orgRootId`,CONCAT(`profile`.`prefix`,`profile`.`firstName`,' ',`profile`.`lastName`) AS `actFullName`\n FROM((((`posMasterAct` JOIN `posMaster` `posMasterChild` ON ((`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`))) JOIN `profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`))) JOIN `posMaster` ON ((`posMasterAct`.`posMasterId` = `posMaster`.`id`))) JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddTableViewCommanderDirector1729754336397 implements MigrationInterface {
|
||||
name = 'AddTableViewCommanderDirector1729754336397'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_commander_director","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_commander_director\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_commander_director\` AS SELECT
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`Id\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\` AS \`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\` AS \`firstName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\` AS \`lastName\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`position\` AS \`position\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
NULL AS \`actFullName\`
|
||||
FROM
|
||||
(((\`bma_ehr_organization_demo\`.\`posMaster\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))
|
||||
UNION SELECT
|
||||
\`profileChild\`.\`id\` AS \`Id\`,
|
||||
\`profileChild\`.\`prefix\` AS \`prefix\`,
|
||||
\`profileChild\`.\`firstName\` AS \`firstName\`,
|
||||
\`profileChild\`.\`lastName\` AS \`lastName\`,
|
||||
\`profileChild\`.\`citizenId\` AS \`citizenId\`,
|
||||
\`profileChild\`.\`position\` AS \`position\`,
|
||||
\`posMasterChild\`.\`isDirector\` AS \`isDirector\`,
|
||||
\`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`,
|
||||
\`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`,
|
||||
\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
|
||||
CONCAT(\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\`,
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`firstName\`,
|
||||
' ',
|
||||
\`bma_ehr_organization_demo\`.\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM
|
||||
((((((\`bma_ehr_organization_demo\`.\`posMasterAct\`
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` \`posMasterChild\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`posMaster\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterId\` = \`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`)))
|
||||
JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_commander_director","SELECT \n `bma_ehr_organization_demo`.`profile`.`id` AS `Id`,\n `bma_ehr_organization_demo`.`profile`.`prefix` AS `prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName` AS `firstName`,\n `bma_ehr_organization_demo`.`profile`.`lastName` AS `lastName`,\n `bma_ehr_organization_demo`.`profile`.`citizenId` AS `citizenId`,\n `bma_ehr_organization_demo`.`profile`.`position` AS `position`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n NULL AS `actFullName`\n FROM\n (((`bma_ehr_organization_demo`.`posMaster`\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`bma_ehr_organization_demo`.`profile`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`bma_ehr_organization_demo`.`profile`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`))) \n UNION SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n `posMasterChild`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n CONCAT(`bma_ehr_organization_demo`.`profile`.`prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName`,\n ' ',\n `bma_ehr_organization_demo`.`profile`.`lastName`) AS `actFullName`\n FROM\n ((((((`bma_ehr_organization_demo`.`posMasterAct`\n JOIN `bma_ehr_organization_demo`.`posMaster` `posMasterChild` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`profileChild`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`profileChild`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posMaster` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterId` = `bma_ehr_organization_demo`.`posMaster`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_commander_director","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_commander_director\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_commander_director\` AS SELECT \`profile\`.\`id\` AS \`id\`,\`profile\`.\`prefix\` AS \`prefix\`,\`profile\`.\`firstName\` AS \`firstName\`,\`profile\`.\`lastName\` AS \`lastName\`,\`profile\`.\`citizenId\` AS \`citizenId\`,\`profile\`.\`position\` AS \`position\`,\`posMaster\`.\`isDirector\` AS \`isDirector\`,\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,NULL AS \`actFullName\`
|
||||
FROM (\`posMaster\` JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))
|
||||
UNION SELECT \`profileChild\`.\`id\` AS \`id\`,\`profileChild\`.\`prefix\` AS \`prefix\`,\`profileChild\`.\`firstName\` AS \`firstName\`,\`profileChild\`.\`lastName\` AS \`lastName\`,\`profileChild\`.\`citizenId\` AS \`citizenId\`,\`profileChild\`.\`position\` AS \`position\`,\`posMasterChild\`.\`isDirector\` AS \`isDirector\`,\`posMaster\`.\`orgRootId\` AS \`orgRootId\`,CONCAT(\`profile\`.\`prefix\`,\`profile\`.\`firstName\`,' ',\`profile\`.\`lastName\`) AS \`actFullName\`
|
||||
FROM((((\`posMasterAct\` JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_commander_director","SELECT `profile`.`id` AS `id`,`profile`.`prefix` AS `prefix`,`profile`.`firstName` AS `firstName`,`profile`.`lastName` AS `lastName`,`profile`.`citizenId` AS `citizenId`,`profile`.`position` AS `position`,`posMaster`.`isDirector` AS `isDirector`,`posMaster`.`orgRootId` AS `orgRootId`,NULL AS `actFullName`\n FROM (`posMaster` JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`))) \n UNION SELECT `profileChild`.`id` AS `id`,`profileChild`.`prefix` AS `prefix`,`profileChild`.`firstName` AS `firstName`,`profileChild`.`lastName` AS `lastName`,`profileChild`.`citizenId` AS `citizenId`,`profileChild`.`position` AS `position`,`posMasterChild`.`isDirector` AS `isDirector`,`posMaster`.`orgRootId` AS `orgRootId`,CONCAT(`profile`.`prefix`,`profile`.`firstName`,' ',`profile`.`lastName`) AS `actFullName`\n FROM((((`posMasterAct` JOIN `posMaster` `posMasterChild` ON ((`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`))) JOIN `profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`))) JOIN `posMaster` ON ((`posMasterAct`.`posMasterId` = `posMaster`.`id`))) JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))"]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue