Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-25 13:02:03 +07:00
commit 37b2d84c7e
6 changed files with 714 additions and 93 deletions

View file

@ -107,6 +107,7 @@ export class CommandController extends Controller {
@Query() year?: number,
@Query() status?: string | null,
) {
await new permission().PermissionList(request, "COMMAND");
let profilekArray: any = [];
let _profile = await this.profileRepository.findOne({
@ -286,6 +287,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionCreate(request, "COMMAND");
const command = Object.assign(new Command(), requestBody);
const commandType = await this.commandTypeRepository.findOne({
@ -319,7 +321,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab1/{id}")
async GetByIdTab1(@Path() id: string) {
async GetByIdTab1(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandType.commandTypeSys"],
@ -371,6 +374,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -392,7 +396,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab2/{id}")
async GetByIdTab2(@Path() id: string) {
async GetByIdTab2(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSalary", "commandRecives"],
@ -443,6 +448,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -468,8 +474,9 @@ export class CommandController extends Controller {
public async swapSalary(
@Path() direction: string,
commandReciveId: string,
@Request() req: RequestWithUser,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const source_item = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
});
@ -525,6 +532,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
});
@ -549,6 +557,7 @@ export class CommandController extends Controller {
*/
@Delete("tab2/{commandReciveId}")
async DeleteTab2(@Path() commandReciveId: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "COMMAND");
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
relations: ["command", "command.commandType"],
@ -591,7 +600,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab3/{id}")
async GetByIdTab3(@Path() id: string) {
async GetByIdTab3(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSends", "commandSends.commandSendCCs"],
@ -630,6 +640,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -697,6 +708,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -743,6 +755,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandSendRepository.findOne({ where: { id: commandSendId } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง");
@ -766,6 +779,7 @@ export class CommandController extends Controller {
requestBody: { commandNo?: string | null; commandYear?: number | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
});
@ -806,6 +820,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -832,6 +847,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -853,6 +869,7 @@ export class CommandController extends Controller {
*/
@Delete("{id}")
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
@ -888,7 +905,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab0/{id}")
async GetByIdTab0(@Path() id: string) {
async GetByIdTab0(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
});
@ -921,6 +939,7 @@ export class CommandController extends Controller {
requestBody: { sign: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -948,6 +967,7 @@ export class CommandController extends Controller {
requestBody: { sign: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -975,6 +995,7 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -1001,6 +1022,7 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives", "commandSends", "commandSends.commandSendCCs"],
@ -1158,6 +1180,7 @@ export class CommandController extends Controller {
*/
@Get("tab4/cover/{id}")
async GetByIdTab4Cover(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
@ -1231,6 +1254,7 @@ export class CommandController extends Controller {
*/
@Get("tab4/attachment/{id}")
async GetByIdTab4Attachment(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandRecives"],
@ -1535,6 +1559,7 @@ export class CommandController extends Controller {
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.commandId = item.commandId ?? _null;
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
const posMaster = await this.posMasterRepository.findOne({
@ -2951,4 +2976,192 @@ export class CommandController extends Controller {
await this.posMasterRepository.save(data);
return new HttpSuccess();
}
/**
* API tab0
*
* @summary API tab0
*
* @param {string} id Id
*/
@Get("register-tab0/{id}")
async GetByIdTab0Register(@Path() id: string) {
const command = await this.commandRepository.findOne({
where: { id },
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const _command = {
id: command.id,
isSignature: command.isSignature,
status: command.status,
isDraft: command.isDraft,
isSign: command.isSign,
isAttachment: command.isAttachment,
};
return new HttpSuccess(_command);
}
/**
* API tab4
*
* @summary API tab4
*
* @param {string} id Id
*/
@Get("register-tab4/cover/{id}")
async GetByIdTab4CoverRegister(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
let issue =
command.isBangkok == "OFFICE"
? "สำนักปลัดกรุงเทพมหานคร"
: command.isBangkok == "BANGKOK"
? "กรุงเทพมหานคร"
: null;
if (issue == null) {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
relations: ["posMasters", "posMasters.orgRoot"],
});
if (orgRevisionActive != null) {
const profile = await this.profileRepository.findOne({
where: {
keycloak: command.createdUserId.toString(),
},
});
if (profile != null) {
issue =
orgRevisionActive?.posMasters?.filter((x) => x.current_holderId == profile.id)[0]
?.orgRoot?.orgRootName || null;
}
}
}
if (issue == null) issue = "...................................";
const _command = {
issue: issue,
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
commandYear:
command.commandYear == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiYear(command.commandYear).toString()),
commandTitle: command.issue,
detailHeader: command.detailHeader,
detailBody: command.detailBody,
detailFooter: command.detailFooter,
commandDate:
command.commandAffectDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandAffectDate)),
commandExcecuteDate:
command.commandExcecuteDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
name: "...................................",
position: "...................................",
authorizedUserFullName: "...................................",
authorizedPosition: "...................................",
commandAffectDate: "...................................",
};
return new HttpSuccess({
template: command.commandType.fileCover,
reportName: "docx-report",
data: _command,
});
}
/**
* API tab4
*
* @summary API tab4
*
* @param {string} id Id
*/
@Get("register-tab4/attachment/{id}")
async GetByIdTab4AttachmentRegister(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
let _command: any = [];
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/attachment", {
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
})
.then(async (res) => {
_command = res;
})
.catch(() => {});
let issue =
command.isBangkok == "OFFICE"
? "สำนักปลัดกรุงเทพมหานคร"
: command.isBangkok == "BANGKOK"
? "กรุงเทพมหานคร"
: null;
if (issue == null) {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
relations: ["posMasters", "posMasters.orgRoot"],
});
if (orgRevisionActive != null) {
const profile = await this.profileRepository.findOne({
where: {
keycloak: command.createdUserId.toString(),
},
});
if (profile != null) {
issue =
orgRevisionActive?.posMasters?.filter((x) => x.current_holderId == profile.id)[0]
?.orgRoot?.orgRootName || null;
}
}
}
if (issue == null) issue = "...................................";
return new HttpSuccess({
template: command.commandType.fileAttachment,
reportName: "xlsx-report",
data: {
data: _command,
issuerOrganizationName: issue,
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
commandYear:
command.commandYear == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiYear(command.commandYear).toString()),
commandExcecuteDate:
command.commandExcecuteDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
},
});
}
}

View file

@ -3178,6 +3178,247 @@ export class PositionController extends Controller {
return new HttpSuccess();
}
/**
* API .
*
* @summary .
*
*/
@Post("placement/search-all")
async searchPlacementAll(
@Body()
body: {
node: number;
nodeId: string;
position?: string | null;
posType?: string | null;
posLevel?: string | null;
isAll: boolean;
isBlank: boolean;
},
) {
let typeCondition: any = {};
let conditionA = "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel";
let posType = await this.posTypeRepository.findOne({
where: { id: String(body.posType) },
});
let posLevel = await this.posLevelRepository.findOne({
where: { id: String(body.posLevel) },
});
if (body.isAll == false) {
if (body.node === 0) {
typeCondition = {
orgRootId: body.nodeId,
orgChild1Id: IsNull(),
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 1) {
typeCondition = {
orgChild1Id: body.nodeId,
orgChild2Id: IsNull(),
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 2) {
typeCondition = {
orgChild2Id: body.nodeId,
orgChild3Id: IsNull(),
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 3) {
typeCondition = {
orgChild3Id: body.nodeId,
orgChild4Id: IsNull(),
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 4) {
typeCondition = {
orgChild4Id: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
}
} else {
if (body.node === 0) {
typeCondition = {
orgRootId: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 1) {
typeCondition = {
orgChild1Id: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 2) {
typeCondition = {
orgChild2Id: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 3) {
typeCondition = {
orgChild3Id: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.node === 4) {
typeCondition = {
orgChild4Id: body.nodeId,
};
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
}
}
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere(
new Brackets((qb) => {
qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, {
posType: posType == null ? `%%` : `${posType.id}`,
posLevel: posLevel == null ? `%%` : `${posLevel.id}`,
});
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.getManyAndCount();
const formattedData = await Promise.all(
posMaster.map(async (posMaster) => {
let shortName = "";
if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id == null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null
) {
body.node = 0;
shortName = posMaster.orgRoot.orgRootShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null
) {
body.node = 1;
shortName = posMaster.orgChild1.orgChild1ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id == null
) {
body.node = 2;
shortName = posMaster.orgChild2.orgChild2ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id !== null
) {
body.node = 3;
shortName = posMaster.orgChild3.orgChild3ShortName;
} else if (
posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id !== null
) {
body.node = 4;
shortName = posMaster.orgChild4.orgChild4ShortName;
}
let node: any = null;
let nodeId: any = null;
if (posMaster.orgChild4Id != null) {
node = 4;
nodeId = posMaster.orgChild4Id;
} else if (posMaster.orgChild3Id != null) {
node = 3;
nodeId = posMaster.orgChild3Id;
} else if (posMaster.orgChild2Id != null) {
node = 2;
nodeId = posMaster.orgChild2Id;
} else if (posMaster.orgChild1Id != null) {
node = 1;
nodeId = posMaster.orgChild1Id;
} else if (posMaster.orgRootId != null) {
node = 0;
nodeId = posMaster.orgRootId;
}
return {
id: posMaster.id,
node: node,
nodeId: nodeId,
orgRootId: posMaster.orgRootId,
orgChild1Id: posMaster.orgChild1Id,
orgChild2Id: posMaster.orgChild2Id,
orgChild3Id: posMaster.orgChild3Id,
orgChild4Id: posMaster.orgChild4Id,
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
orgShortname: shortName,
isSit: posMaster.isSit,
fullNameCurrentHolder:
posMaster.current_holder == null
? null
: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
fullNameNextHolder:
posMaster.next_holder == null
? null
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
isPosition: posMaster.positions.filter((x) => x.positionName == body.position).length > 0,
positions: posMaster.positions.map((position) => ({
id: position.id,
positionName: position.positionName,
positionField: position.positionField,
posTypeId: position.posTypeId,
posTypeName: position.posType == null ? null : position.posType.posTypeName,
posLevelId: position.posLevelId,
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
posExecutiveId: position.posExecutiveId,
posExecutiveName:
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
positionExecutiveField: position.positionExecutiveField,
positionArea: position.positionArea,
positionIsSelected: position.positionIsSelected,
isSpecial: position.isSpecial,
})),
};
}),
);
return new HttpSuccess({ data: formattedData, total });
}
/**
* API .
*

View file

@ -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
@ -1231,7 +1233,7 @@ export class ProfileController extends Controller {
@Post("commander-director")
async getProfileCommanderDirector(
@Request() request: RequestWithUser,
@Body() body: { isDirector: boolean },
@Body() body: { isDirector: boolean; keyword: string; page: number; pageSize: number },
) {
const posMaster = await this.posMasterRepo.findOne({
where: {
@ -1240,95 +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 = await this.posMasterRepo.find({
where: {
orgRootId: posMaster.orgRootId || "",
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "current_holder.posLevel", "current_holder.posType"],
});
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);
} else {
const _posMaster = await this.posMasterRepo.find({
where: {
orgRootId: posMaster.orgRootId || "",
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "current_holder.posLevel", "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,
}));
return new HttpSuccess(data);
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 });
}
/**

View 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;
}

View 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`)))"]);
}
}

View file

@ -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`)))"]);
}
}