Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
9def90b0aa
1 changed files with 88 additions and 46 deletions
|
|
@ -267,73 +267,115 @@ export class PositionController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("position")
|
@Get("position")
|
||||||
async findPosition(@Query("keyword") keyword: string, @Query("type") type: string) {
|
async findPosition(@Query("keyword") keyword: string, @Query("type") type: string){
|
||||||
// { id: "positionName", name: "ตำแหน่งในสายงาน" }
|
|
||||||
// { id: "positionField", name: "สายงาน" }
|
|
||||||
// { id: "positionType", name: "ประเภทตำแหน่ง" }
|
|
||||||
// { id: "positionLevel", name: "ระดับตำแหน่ง" }
|
|
||||||
// { id: "positionExecutive", name: "ตำแหน่งทางการบริหาร" }
|
|
||||||
// { id: "positionExecutiveField", name: "ด้านทางการบริหาร" }
|
|
||||||
// { id: "positionArea", name: "ด้าน/สาขา" }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let findPosDict: any;
|
let findPosDict: any;
|
||||||
console.log("type: ", type);
|
switch(type){
|
||||||
console.log("keyword: ", keyword);
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case "positionName":
|
case "positionName":
|
||||||
findPosDict = await this.posDictRepository.find({
|
findPosDict = await this.posDictRepository.find({ where: { posDictName: Like(`%${keyword}%`) } });
|
||||||
where: { posDictName: Like(`%${keyword}%`) },
|
|
||||||
});
|
|
||||||
if (!findPosDict) {
|
if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionField":
|
case "positionField":
|
||||||
findPosDict = await this.posDictRepository.find({
|
findPosDict = await this.posDictRepository.find({ where: { posDictField: Like(`%${keyword}%`) } });
|
||||||
where: { posDictField: Like(`%${keyword}%`) },
|
|
||||||
});
|
|
||||||
if (!findPosDict) {
|
if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionType":
|
case "positionType":
|
||||||
findPosDict = await this.posDictRepository.find({
|
const findTypes: PosType[] = await this.posTypeRepository.find({ where: { posTypeName: Like(`%${keyword}%`) } });
|
||||||
where: { posTypeId: Like(`%${keyword}%`) },
|
if(!findTypes){
|
||||||
});
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posType");
|
||||||
if (!findPosDict) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
|
||||||
}
|
}
|
||||||
|
for (const types of findTypes) {
|
||||||
|
findPosDict = await this.posDictRepository.find({ where: { posTypeId: types.id } });
|
||||||
|
if (!findPosDict) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionLevel":
|
case "positionLevel":
|
||||||
findPosDict = await this.posDictRepository.find({
|
const findLevel: PosLevel[] = await this.posLevelRepository.find({ where: { posLevelName: Like(`%${keyword}%`) } })
|
||||||
where: { posLevelId: Like(`%${keyword}%`) },
|
if(!findLevel){
|
||||||
});
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posLevel");
|
||||||
if (!findPosDict) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const types of findLevel) {
|
||||||
|
findPosDict = await this.posDictRepository.find({ where: { posLevelId: types.id } });
|
||||||
|
if (!findPosDict) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionExecutive":
|
case "positionExecutive":
|
||||||
findPosDict = await this.posDictRepository.find({
|
const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({ where: { posExecutiveName: Like(`%${keyword}%`) } })
|
||||||
where: { posExecutiveId: Like(`%${keyword}%`) },
|
if(!findExecutive){
|
||||||
});
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword + " ใน posExecutive");
|
||||||
if (!findPosDict) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const types of findExecutive) {
|
||||||
|
findPosDict = await this.posDictRepository.find({ where: { posExecutiveId: types.id } });
|
||||||
|
if (!findPosDict) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionExecutiveField":
|
case "positionExecutiveField":
|
||||||
findPosDict = await this.posDictRepository.find({
|
findPosDict = await this.posDictRepository.find({ where: { posDictExecutiveField: Like(`%${keyword}%`) } });
|
||||||
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
|
||||||
});
|
|
||||||
if (!findPosDict) {
|
if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "positionArea":
|
case "positionArea":
|
||||||
findPosDict = await this.posDictRepository.find({
|
findPosDict = await this.posDictRepository.find({ where: { posDictArea: Like(`%${keyword}%`) } });
|
||||||
where: { posDictArea: Like(`%${keyword}%`) },
|
|
||||||
});
|
|
||||||
if (!findPosDict) {
|
if (!findPosDict) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล "+ keyword);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
findPosDict = await this.posDictRepository.find();
|
||||||
|
if (!findPosDict) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return new HttpSuccess(findPosDict);
|
|
||||||
} catch (error) {
|
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"] });
|
||||||
|
|
||||||
|
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) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue