เพิ่มlink relation
This commit is contained in:
parent
a41e33c0d4
commit
d74c3140fa
16 changed files with 416 additions and 139 deletions
|
|
@ -683,9 +683,9 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API สำหรับแสดงรายการการประชุม
|
||||
* API ประวัติหน่วยงาน
|
||||
*
|
||||
* @summary EV4_006 - รายการการประชุม (ADMIN)
|
||||
* @summary ORG_039 - ประวัติหน่วยงาน (ADMIN) #42
|
||||
*
|
||||
*/
|
||||
@Get("/history/publish")
|
||||
|
|
@ -700,20 +700,16 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child1Repository.find({
|
||||
where: { isAncestorDNA: orgChild1.isAncestorDNA },
|
||||
select: ["id", "orgRevisionId", "orgChild1Name", "lastUpdatedAt"],
|
||||
relations: ["orgRevision"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
for (let data of datas) {
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: data.orgRevisionId },
|
||||
});
|
||||
_data.push({
|
||||
id: data.id,
|
||||
orgRevisionName: revision?.orgRevisionName,
|
||||
orgChild1Name: data.orgChild1Name,
|
||||
lastUpdatedAt: data.lastUpdatedAt,
|
||||
});
|
||||
}
|
||||
const _data = datas.map((item) => ({
|
||||
id: item.id,
|
||||
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
|
||||
name: item.orgChild1Name,
|
||||
lastUpdatedAt: item.lastUpdatedAt,
|
||||
}));
|
||||
return new HttpSuccess(_data);
|
||||
} else if (type == 2) {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -723,20 +719,16 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child2Repository.find({
|
||||
where: { isAncestorDNA: orgChild2.isAncestorDNA },
|
||||
select: ["id", "orgRevisionId", "orgChild2Name", "lastUpdatedAt"],
|
||||
relations: ["orgRevision"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
for (let data of datas) {
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: data.orgRevisionId },
|
||||
});
|
||||
_data.push({
|
||||
id: data.id,
|
||||
orgRevisionName: revision?.orgRevisionName,
|
||||
name: data.orgChild2Name,
|
||||
lastUpdatedAt: data.lastUpdatedAt,
|
||||
});
|
||||
}
|
||||
const _data = datas.map((item) => ({
|
||||
id: item.id,
|
||||
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
|
||||
name: item.orgChild2Name,
|
||||
lastUpdatedAt: item.lastUpdatedAt,
|
||||
}));
|
||||
return new HttpSuccess(_data);
|
||||
} else if (type == 3) {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -746,20 +738,16 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child3Repository.find({
|
||||
where: { isAncestorDNA: orgChild3.isAncestorDNA },
|
||||
select: ["id", "orgRevisionId", "orgChild3Name", "lastUpdatedAt"],
|
||||
relations: ["orgRevision"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
for (let data of datas) {
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: data.orgRevisionId },
|
||||
});
|
||||
_data.push({
|
||||
id: data.id,
|
||||
orgRevisionName: revision?.orgRevisionName,
|
||||
name: data.orgChild3Name,
|
||||
lastUpdatedAt: data.lastUpdatedAt,
|
||||
});
|
||||
}
|
||||
const _data = datas.map((item) => ({
|
||||
id: item.id,
|
||||
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
|
||||
name: item.orgChild3Name,
|
||||
lastUpdatedAt: item.lastUpdatedAt,
|
||||
}));
|
||||
return new HttpSuccess(_data);
|
||||
} else if (type == 4) {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -769,20 +757,16 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.child4Repository.find({
|
||||
where: { isAncestorDNA: orgChild4.isAncestorDNA },
|
||||
select: ["id", "orgRevisionId", "orgChild4Name", "lastUpdatedAt"],
|
||||
relations: ["orgRevision"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
for (let data of datas) {
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: data.orgRevisionId },
|
||||
});
|
||||
_data.push({
|
||||
id: data.id,
|
||||
orgRevisionName: revision?.orgRevisionName,
|
||||
name: data.orgChild4Name,
|
||||
lastUpdatedAt: data.lastUpdatedAt,
|
||||
});
|
||||
}
|
||||
const _data = datas.map((item) => ({
|
||||
id: item.id,
|
||||
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
|
||||
name: item.orgChild4Name,
|
||||
lastUpdatedAt: item.lastUpdatedAt,
|
||||
}));
|
||||
return new HttpSuccess(_data);
|
||||
} else {
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -792,20 +776,16 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
const datas = await this.orgRootRepository.find({
|
||||
where: { isAncestorDNA: orgRoot.isAncestorDNA },
|
||||
select: ["id", "orgRevisionId", "orgRootName", "lastUpdatedAt"],
|
||||
relations: ["orgRevision"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
for (let data of datas) {
|
||||
const revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: data.orgRevisionId },
|
||||
});
|
||||
_data.push({
|
||||
id: data.id,
|
||||
orgRevisionName: revision?.orgRevisionName,
|
||||
name: data.orgRootName,
|
||||
lastUpdatedAt: data.lastUpdatedAt,
|
||||
});
|
||||
}
|
||||
const _data = datas.map((item) => ({
|
||||
id: item.id,
|
||||
orgRevisionName: item.orgRevision == null ? null : item.orgRevision.orgRevisionName,
|
||||
name: item.orgRootName,
|
||||
lastUpdatedAt: item.lastUpdatedAt,
|
||||
}));
|
||||
return new HttpSuccess(_data);
|
||||
}
|
||||
return new HttpSuccess(_data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,76 +267,98 @@ export class PositionController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("position")
|
||||
async findPosition(@Query("keyword") keyword: string, @Query("type") type: string){
|
||||
async findPosition(@Query("keyword") keyword: string, @Query("type") type: string) {
|
||||
try {
|
||||
let findPosDict: any;
|
||||
switch(type){
|
||||
switch (type) {
|
||||
case "positionName":
|
||||
findPosDict = await this.posDictRepository.find({ where: { posDictName: Like(`%${keyword}%`) } });
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictName: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionField":
|
||||
findPosDict = await this.posDictRepository.find({ where: { posDictField: Like(`%${keyword}%`) } });
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictField: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionType":
|
||||
const findTypes: PosType[] = await this.posTypeRepository.find({ where: { posTypeName: Like(`%${keyword}%`) } });
|
||||
if(!findTypes){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posType");
|
||||
const findTypes: PosType[] = await this.posTypeRepository.find({
|
||||
where: { posTypeName: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findTypes) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword + " ใน posType");
|
||||
}
|
||||
for (const types of findTypes) {
|
||||
findPosDict = await this.posDictRepository.find({ where: { posTypeId: types.id } });
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionLevel":
|
||||
const findLevel: PosLevel[] = await this.posLevelRepository.find({ where: { posLevelName: Like(`%${keyword}%`) } })
|
||||
if(!findLevel){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posLevel");
|
||||
const findLevel: PosLevel[] = await this.posLevelRepository.find({
|
||||
where: { posLevelName: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findLevel) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูล " + keyword + " ใน posLevel",
|
||||
);
|
||||
}
|
||||
|
||||
for (const types of findLevel) {
|
||||
findPosDict = await this.posDictRepository.find({ where: { posLevelId: types.id } });
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionExecutive":
|
||||
const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({ where: { posExecutiveName: Like(`%${keyword}%`) } })
|
||||
if(!findExecutive){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posExecutive");
|
||||
const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({
|
||||
where: { posExecutiveName: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findExecutive) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูล " + keyword + " ใน posExecutive",
|
||||
);
|
||||
}
|
||||
|
||||
for (const types of findExecutive) {
|
||||
findPosDict = await this.posDictRepository.find({ where: { posExecutiveId: types.id } });
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posExecutiveId: types.id },
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionExecutiveField":
|
||||
findPosDict = await this.posDictRepository.find({ where: { posDictExecutiveField: Like(`%${keyword}%`) } });
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
break;
|
||||
|
||||
case "positionArea":
|
||||
findPosDict = await this.posDictRepository.find({ where: { posDictArea: Like(`%${keyword}%`) } });
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictArea: Like(`%${keyword}%`) },
|
||||
});
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -348,34 +370,44 @@ export class PositionController extends Controller {
|
|||
break;
|
||||
}
|
||||
|
||||
if(!findPosDict){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||
if (!findPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
||||
}
|
||||
|
||||
const mapDataPosDict = await Promise.all(findPosDict.map(async (item: any) => {
|
||||
const posTypeName = await this.posTypeRepository.findOne({ where: { id: item.posTypeId }, select: ["posTypeName"] });
|
||||
const posLevelName = await this.posLevelRepository.findOne({ where: { id: item.posLevelId }, select: ["posLevelName"] });
|
||||
const posExecutiveName = await this.posExecutiveRepository.findOne({ where: { id: item.posExecutiveId }, select: ["posExecutiveName"] });
|
||||
const mapDataPosDict = await Promise.all(
|
||||
findPosDict.map(async (item: any) => {
|
||||
const posTypeName = await this.posTypeRepository.findOne({
|
||||
where: { id: item.posTypeId },
|
||||
select: ["posTypeName"],
|
||||
});
|
||||
const posLevelName = await this.posLevelRepository.findOne({
|
||||
where: { id: item.posLevelId },
|
||||
select: ["posLevelName"],
|
||||
});
|
||||
const posExecutiveName = await this.posExecutiveRepository.findOne({
|
||||
where: { id: item.posExecutiveId },
|
||||
select: ["posExecutiveName"],
|
||||
});
|
||||
|
||||
return {
|
||||
id: item.id,
|
||||
positionName: item.posDictName,
|
||||
positionField: item.posDictField,
|
||||
posTypeId: item.posTypeId,
|
||||
posTypeName: posTypeName ? posTypeName.posTypeName : null,
|
||||
posLevelId: item.posLevelId,
|
||||
posLevelName: posLevelName ? posLevelName.posLevelName : null,
|
||||
posExecutiveId: item.posExecutiveId,
|
||||
posExecutiveName: posExecutiveName ? posExecutiveName.posExecutiveName : null,
|
||||
positionExecutiveField: item.posDictExecutiveField,
|
||||
positionArea: item.posDictArea,
|
||||
positionIsSelected: false
|
||||
};
|
||||
}));
|
||||
return {
|
||||
id: item.id,
|
||||
positionName: item.posDictName,
|
||||
positionField: item.posDictField,
|
||||
posTypeId: item.posTypeId,
|
||||
posTypeName: posTypeName ? posTypeName.posTypeName : null,
|
||||
posLevelId: item.posLevelId,
|
||||
posLevelName: posLevelName ? posLevelName.posLevelName : null,
|
||||
posExecutiveId: item.posExecutiveId,
|
||||
posExecutiveName: posExecutiveName ? posExecutiveName.posExecutiveName : null,
|
||||
positionExecutiveField: item.posDictExecutiveField,
|
||||
positionArea: item.posDictArea,
|
||||
positionIsSelected: false,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(mapDataPosDict);
|
||||
}
|
||||
catch (error) {
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
@ -620,4 +652,50 @@ export class PositionController extends Controller {
|
|||
});
|
||||
return new HttpSuccess(posMaster.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดอัตรากำลัง
|
||||
*
|
||||
* @summary ORG_037 - รายละเอียดอัตรากำลัง (ADMIN) #36
|
||||
*
|
||||
*/
|
||||
@Get("master/{id}")
|
||||
async detail(@Path() id: string) {
|
||||
try {
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const positions = await this.posPositionRepository.find({
|
||||
where: { posMasterId: posMaster.id },
|
||||
});
|
||||
const formattedData = {
|
||||
id: posMaster.id,
|
||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
positions: 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,
|
||||
})),
|
||||
};
|
||||
return new HttpSuccess(formattedData);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue