remove try catch
This commit is contained in:
parent
039b11d1c3
commit
e9ed8ff3f4
8 changed files with 1575 additions and 1744 deletions
|
|
@ -60,7 +60,6 @@ export class OrgChild1Controller {
|
|||
if (!orgChild1) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 1");
|
||||
}
|
||||
try {
|
||||
const getOrgChild1 = {
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgRootName: orgChild1.orgRoot.orgRootName,
|
||||
|
|
@ -77,9 +76,6 @@ export class OrgChild1Controller {
|
|||
orgCode: orgChild1.orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild1);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -136,7 +132,6 @@ export class OrgChild1Controller {
|
|||
},
|
||||
order: { orgChild1Order: "DESC" },
|
||||
});
|
||||
try {
|
||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||
child1.orgChild1Name = requestBody.orgChild1Name;
|
||||
child1.createdUserId = request.user.sub;
|
||||
|
|
@ -149,9 +144,6 @@ export class OrgChild1Controller {
|
|||
order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1;
|
||||
await this.child1Repository.save(child1);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -212,7 +204,6 @@ export class OrgChild1Controller {
|
|||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
try {
|
||||
child1.lastUpdateUserId = request.user.sub;
|
||||
child1.lastUpdateFullName = request.user.name;
|
||||
child1.lastUpdatedAt = new Date();
|
||||
|
|
@ -221,9 +212,6 @@ export class OrgChild1Controller {
|
|||
this.child1Repository.merge(child1, requestBody);
|
||||
await this.child1Repository.save(child1);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -261,7 +249,6 @@ export class OrgChild1Controller {
|
|||
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
|
||||
// );
|
||||
// }
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild1Id: id },
|
||||
});
|
||||
|
|
@ -276,8 +263,5 @@ export class OrgChild1Controller {
|
|||
await this.child2Repository.delete({ orgChild1Id: id });
|
||||
await this.child1Repository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ export class OrgChild2Controller extends Controller {
|
|||
if (!orgChild2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2");
|
||||
}
|
||||
try {
|
||||
const getOrgChild2 = {
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgRootName: orgChild2.orgRoot.orgRootName,
|
||||
|
|
@ -79,9 +78,6 @@ export class OrgChild2Controller extends Controller {
|
|||
orgCode: orgChild2.orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild2);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,7 +138,6 @@ export class OrgChild2Controller extends Controller {
|
|||
},
|
||||
order: { orgChild2Order: "DESC" },
|
||||
});
|
||||
try {
|
||||
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
|
||||
child2.orgChild2Name = requestBody.orgChild2Name;
|
||||
child2.createdUserId = request.user.sub;
|
||||
|
|
@ -156,9 +151,6 @@ export class OrgChild2Controller extends Controller {
|
|||
order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1;
|
||||
await this.child2Repository.save(child2);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,7 +215,6 @@ export class OrgChild2Controller extends Controller {
|
|||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
child2.lastUpdateUserId = request.user.sub;
|
||||
child2.lastUpdateFullName = request.user.name;
|
||||
child2.lastUpdatedAt = new Date();
|
||||
|
|
@ -233,9 +224,6 @@ export class OrgChild2Controller extends Controller {
|
|||
this.child2Repository.merge(child2, requestBody);
|
||||
await this.child2Repository.save(child2);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -275,7 +263,6 @@ export class OrgChild2Controller extends Controller {
|
|||
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
|
||||
// );
|
||||
// }
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild2Id: id },
|
||||
});
|
||||
|
|
@ -289,8 +276,5 @@ export class OrgChild2Controller extends Controller {
|
|||
await this.child3Repository.delete({ orgChild2Id: id });
|
||||
await this.child2Repository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ export class OrgChild3Controller {
|
|||
if (!orgChild3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
||||
}
|
||||
try {
|
||||
const getOrgChild3 = {
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgRootName: orgChild3.orgRoot.orgRootName,
|
||||
|
|
@ -75,9 +74,6 @@ export class OrgChild3Controller {
|
|||
orgCode: orgChild3.orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild3);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,7 +120,6 @@ export class OrgChild3Controller {
|
|||
},
|
||||
order: { orgChild3Order: "DESC" },
|
||||
});
|
||||
try {
|
||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||
child3.createdUserId = request.user.sub;
|
||||
|
|
@ -139,9 +134,6 @@ export class OrgChild3Controller {
|
|||
order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1;
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -192,7 +184,6 @@ export class OrgChild3Controller {
|
|||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.lastUpdatedAt = new Date();
|
||||
|
|
@ -203,9 +194,6 @@ export class OrgChild3Controller {
|
|||
this.child3Repository.merge(child3, requestBody);
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,7 +233,6 @@ export class OrgChild3Controller {
|
|||
// "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
|
||||
// );
|
||||
// }
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild3Id: id },
|
||||
});
|
||||
|
|
@ -258,8 +245,5 @@ export class OrgChild3Controller {
|
|||
await this.child4Repository.delete({ orgChild3Id: id });
|
||||
await this.child3Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||
}
|
||||
try {
|
||||
const getOrgChild4 = {
|
||||
orgChild4Id: orgChild4.id,
|
||||
orgRootName: orgChild4.orgRoot.orgRootName,
|
||||
|
|
@ -77,9 +76,6 @@ export class OrgChild4Controller extends Controller {
|
|||
orgCode: orgChild4.orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild4);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,7 +136,6 @@ export class OrgChild4Controller extends Controller {
|
|||
},
|
||||
order: { orgChild4Order: "DESC" },
|
||||
});
|
||||
try {
|
||||
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
||||
child4.orgChild4Name = requestBody.orgChild4Name;
|
||||
child4.createdUserId = request.user.sub;
|
||||
|
|
@ -157,9 +152,6 @@ export class OrgChild4Controller extends Controller {
|
|||
await this.child4Repository.save(child4);
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -224,7 +216,6 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
child4.lastUpdateUserId = request.user.sub;
|
||||
child4.lastUpdateFullName = request.user.name;
|
||||
child4.lastUpdatedAt = new Date();
|
||||
|
|
@ -236,9 +227,6 @@ export class OrgChild4Controller extends Controller {
|
|||
this.child4Repository.merge(child4, requestBody);
|
||||
await this.child4Repository.save(child4);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -270,7 +258,6 @@ export class OrgChild4Controller extends Controller {
|
|||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgChild4Id: id },
|
||||
});
|
||||
|
|
@ -282,8 +269,5 @@ export class OrgChild4Controller extends Controller {
|
|||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.child4Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ export class OrgRootController extends Controller {
|
|||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
try {
|
||||
const getOrgRoot = {
|
||||
orgRootId: orgRoot.id,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
|
|
@ -69,9 +68,6 @@ export class OrgRootController extends Controller {
|
|||
orgCode: orgRoot.orgRootCode + "00",
|
||||
};
|
||||
return new HttpSuccess(getOrgRoot);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,19 +130,14 @@ export class OrgRootController extends Controller {
|
|||
},
|
||||
order: { orgRootOrder: "DESC" },
|
||||
});
|
||||
try {
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.orgRootOrder =
|
||||
order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
|
||||
orgRoot.orgRootOrder = order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,7 +200,6 @@ export class OrgRootController extends Controller {
|
|||
"ไม่พบข้อมูลโครงสร้างระดับ Root ตามไอดีนี้ :" + id,
|
||||
);
|
||||
}
|
||||
try {
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
|
|
@ -217,9 +207,6 @@ export class OrgRootController extends Controller {
|
|||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -262,7 +249,6 @@ export class OrgRootController extends Controller {
|
|||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { orgRootId: id },
|
||||
});
|
||||
|
|
@ -279,8 +265,5 @@ export class OrgRootController extends Controller {
|
|||
await this.orgRootRepository.delete({ id });
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import {
|
|||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Example
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -44,7 +44,6 @@ export class PosExecutiveController extends Controller {
|
|||
requestBody: CreatePosExecutive,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
|
||||
const checkName = await this.posExecutiveRepository.findOne({
|
||||
where: { posExecutiveName: requestBody.posExecutiveName },
|
||||
});
|
||||
|
|
@ -53,7 +52,6 @@ export class PosExecutiveController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||
posExecutive.createdUserId = request.user.sub;
|
||||
posExecutive.createdFullName = request.user.name;
|
||||
|
|
@ -61,9 +59,6 @@ export class PosExecutiveController extends Controller {
|
|||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,7 +75,7 @@ export class PosExecutiveController extends Controller {
|
|||
requestBody: CreatePosExecutive,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}});
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({ where: { id: id } });
|
||||
if (!posExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
|
@ -93,15 +88,11 @@ export class PosExecutiveController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,13 +110,9 @@ export class PosExecutiveController extends Controller {
|
|||
if (!delPosExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.positionRepository.delete({ posExecutiveId: id });
|
||||
await this.posExecutiveRepository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -137,23 +124,14 @@ export class PosExecutiveController extends Controller {
|
|||
*/
|
||||
@Get("{id}")
|
||||
async detailPosExecutive(@Path() id: string) {
|
||||
|
||||
const posExecutive = await this.posExecutiveRepository.findOne({
|
||||
where: { id },
|
||||
select:[
|
||||
"id",
|
||||
"posExecutiveName",
|
||||
"posExecutivePriority"
|
||||
]
|
||||
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
||||
});
|
||||
if (!posExecutive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(posExecutive);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,7 +149,6 @@ export class PosExecutiveController extends Controller {
|
|||
},
|
||||
])
|
||||
async GetPosExecutive() {
|
||||
try {
|
||||
const posExecutive = await this.posExecutiveRepository.find({
|
||||
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
||||
});
|
||||
|
|
@ -179,8 +156,5 @@ export class PosExecutiveController extends Controller {
|
|||
return new HttpSuccess([]);
|
||||
}
|
||||
return new HttpSuccess(posExecutive);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ import { Not } from "typeorm";
|
|||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
|
||||
export class PosLevelController extends Controller {
|
||||
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
|
||||
|
|
@ -45,14 +43,12 @@ export class PosLevelController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post()
|
||||
@Example(
|
||||
{
|
||||
@Example({
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
posLevelAuthority: "HEAD",
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf"
|
||||
},
|
||||
)
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
})
|
||||
async createLevel(
|
||||
@Body()
|
||||
requestBody: CreatePosLevel,
|
||||
|
|
@ -62,19 +58,29 @@ export class PosLevelController extends Controller {
|
|||
if (!posLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
|
||||
id: requestBody.posTypeId }
|
||||
})
|
||||
if(!chkPosTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({
|
||||
where: {
|
||||
id: requestBody.posTypeId,
|
||||
},
|
||||
});
|
||||
if (!chkPosTypeId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
|
||||
);
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
|
||||
posLevelName: requestBody.posLevelName }
|
||||
})
|
||||
if(chkPosLevelName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
|
||||
posLevelName: requestBody.posLevelName,
|
||||
},
|
||||
});
|
||||
if (chkPosLevelName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
|
||||
|
|
@ -85,16 +91,12 @@ export class PosLevelController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
|
||||
}
|
||||
|
||||
try {
|
||||
posLevel.createdUserId = request.user.sub;
|
||||
posLevel.createdFullName = request.user.name;
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
return new HttpSuccess(posLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -105,12 +107,10 @@ export class PosLevelController extends Controller {
|
|||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Put("{id}")
|
||||
@Example(
|
||||
{
|
||||
@Example({
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
)
|
||||
})
|
||||
async editLevel(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosLevel,
|
||||
|
|
@ -121,20 +121,30 @@ export class PosLevelController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
|
||||
id: requestBody.posTypeId }
|
||||
})
|
||||
if(!chkPosTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({
|
||||
where: {
|
||||
id: requestBody.posTypeId,
|
||||
},
|
||||
});
|
||||
if (!chkPosTypeId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
|
||||
);
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posTypeId: requestBody.posTypeId,
|
||||
posLevelName: requestBody.posLevelName }
|
||||
})
|
||||
if(chkPosLevelName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
|
||||
posLevelName: requestBody.posLevelName,
|
||||
},
|
||||
});
|
||||
if (chkPosLevelName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
|
||||
if (
|
||||
|
|
@ -144,15 +154,11 @@ export class PosLevelController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
|
||||
}
|
||||
|
||||
try {
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
this.posLevelRepository.merge(posLevel, requestBody);
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
return new HttpSuccess(posLevel.id);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -168,12 +174,8 @@ export class PosLevelController extends Controller {
|
|||
if (!delPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.posLevelRepository.remove(delPosLevel);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,8 +186,7 @@ export class PosLevelController extends Controller {
|
|||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Get("{id}")
|
||||
@Example(
|
||||
{
|
||||
@Example({
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
|
|
@ -195,14 +196,12 @@ export class PosLevelController extends Controller {
|
|||
posTypeName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
async GetLevelDetail(@Path() id: string) {
|
||||
try {
|
||||
const getPosType = await this.posLevelRepository.findOne({
|
||||
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
|
||||
relations: ["posType"],
|
||||
where: { id: id }
|
||||
where: { id: id },
|
||||
});
|
||||
if (!getPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
|
|
@ -213,17 +212,14 @@ export class PosLevelController extends Controller {
|
|||
posLevelName: getPosType.posLevelName,
|
||||
posLevelRank: getPosType.posLevelRank,
|
||||
posLevelAuthority: getPosType.posLevelAuthority,
|
||||
posTypes:{
|
||||
posTypes: {
|
||||
id: getPosType.posType.id,
|
||||
posTypeName: getPosType.posType.posTypeName,
|
||||
posTypeRank: getPosType.posType.posTypeRank
|
||||
}
|
||||
}
|
||||
posTypeRank: getPosType.posType.posTypeRank,
|
||||
},
|
||||
};
|
||||
|
||||
return new HttpSuccess(mapPosLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -247,7 +243,6 @@ export class PosLevelController extends Controller {
|
|||
},
|
||||
])
|
||||
async GetPosLevel() {
|
||||
try {
|
||||
const posLevel = await this.posLevelRepository.find({
|
||||
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
|
||||
relations: ["posType"],
|
||||
|
|
@ -264,11 +259,8 @@ export class PosLevelController extends Controller {
|
|||
id: item.posType.id,
|
||||
posTypeName: item.posType.posTypeName,
|
||||
posTypeRank: item.posType.posTypeRank,
|
||||
}
|
||||
},
|
||||
}));
|
||||
return new HttpSuccess(mapPosLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,16 +128,12 @@ export class PositionController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posDict.createdUserId = request.user.sub;
|
||||
posDict.createdFullName = request.user.name;
|
||||
posDict.lastUpdateUserId = request.user.sub;
|
||||
posDict.lastUpdateFullName = request.user.name;
|
||||
await this.posDictRepository.save(posDict);
|
||||
return new HttpSuccess(posDict.id);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -216,15 +212,11 @@ export class PositionController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posDict.lastUpdateUserId = request.user.sub;
|
||||
posDict.lastUpdateFullName = request.user.name;
|
||||
this.posDictRepository.merge(posDict, requestBody);
|
||||
await this.posDictRepository.save(posDict);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,12 +232,8 @@ export class PositionController extends Controller {
|
|||
if (!delPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.posDictRepository.remove(delPosDict);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -256,7 +244,6 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Get("position")
|
||||
async findPosition(@Query("keyword") keyword?: string, @Query("type") type?: string) {
|
||||
try {
|
||||
let findPosDict: any;
|
||||
switch (type) {
|
||||
case "positionName":
|
||||
|
|
@ -363,9 +350,6 @@ export class PositionController extends Controller {
|
|||
);
|
||||
|
||||
return new HttpSuccess(mapDataPosDict);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -880,7 +864,6 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Get("position/{id}")
|
||||
async detailPosition(@Path() id: string) {
|
||||
try {
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
|
@ -915,9 +898,6 @@ export class PositionController extends Controller {
|
|||
})),
|
||||
};
|
||||
return new HttpSuccess(formattedData);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -936,13 +916,9 @@ export class PositionController extends Controller {
|
|||
if (!delPosMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.positionRepository.delete({ posMasterId: id });
|
||||
await this.posMasterRepository.delete({ id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -964,7 +940,6 @@ export class PositionController extends Controller {
|
|||
keyword?: string;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
let typeCondition: any = {};
|
||||
let checkChildConditions: any = {};
|
||||
let keywordAsInt: any;
|
||||
|
|
@ -1082,7 +1057,6 @@ export class PositionController extends Controller {
|
|||
},
|
||||
];
|
||||
|
||||
|
||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||
|
|
@ -1222,8 +1196,7 @@ export class PositionController extends Controller {
|
|||
isSit: posMaster.isSit,
|
||||
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel:
|
||||
level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
|
|
@ -1244,9 +1217,6 @@ export class PositionController extends Controller {
|
|||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1257,7 +1227,6 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Post("sort")
|
||||
async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }) {
|
||||
try {
|
||||
switch (requestBody.type) {
|
||||
case 0: {
|
||||
const rootId = await this.posMasterRepository.findOne({
|
||||
|
|
@ -1403,9 +1372,6 @@ export class PositionController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.type);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1466,7 +1432,6 @@ export class PositionController extends Controller {
|
|||
@Body() requestBody: { id: string; type: number; positionMaster: string[] },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const posMasters = await this.posMasterRepository.find({
|
||||
where: { id: In(requestBody.positionMaster) },
|
||||
});
|
||||
|
|
@ -1540,9 +1505,6 @@ export class PositionController extends Controller {
|
|||
await this.posMasterRepository.save(posMaster);
|
||||
});
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1553,7 +1515,6 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Post("summary")
|
||||
async PositionSummary(@Body() requestBody: { id: string; type: number; isNode: boolean }) {
|
||||
try {
|
||||
let summary: any;
|
||||
let totalPosition: any;
|
||||
let totalPositionCurrentUse: any;
|
||||
|
|
@ -2081,9 +2042,6 @@ export class PositionController extends Controller {
|
|||
totalPositionNextVacant: totalPositionNextVacant,
|
||||
};
|
||||
return new HttpSuccess(summary);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* API สร้างคนครองตำแหน่ง
|
||||
|
|
@ -2105,7 +2063,6 @@ export class PositionController extends Controller {
|
|||
"ไม่พบข้อมูลไอดีนี้ : " + requestBody.posMaster,
|
||||
);
|
||||
}
|
||||
try {
|
||||
dataMaster.positions.forEach(async (position) => {
|
||||
if (position.id === requestBody.position) {
|
||||
position.positionIsSelected = true;
|
||||
|
|
@ -2120,9 +2077,6 @@ export class PositionController extends Controller {
|
|||
await this.posMasterRepository.save(dataMaster);
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2141,7 +2095,6 @@ export class PositionController extends Controller {
|
|||
if (!dataMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.posMasterRepository.update(id, {
|
||||
isSit: false,
|
||||
next_holderId: null,
|
||||
|
|
@ -2154,9 +2107,6 @@ export class PositionController extends Controller {
|
|||
});
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2200,7 +2150,6 @@ export class PositionController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.posMasterRepository.update(
|
||||
{ orgRevisionId: findDraft.id, ancestorDNA: dataPublish.ancestorDNA },
|
||||
{ ancestorDNA: "" },
|
||||
|
|
@ -2212,9 +2161,6 @@ export class PositionController extends Controller {
|
|||
await this.posMasterRepository.save(dataPublish);
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue