checkpoint org_007-009
This commit is contained in:
parent
2d22aa9224
commit
55119a72f5
2 changed files with 107 additions and 118 deletions
|
|
@ -18,12 +18,16 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateOrgChild2, OrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
|
||||
@Route("organization")
|
||||
@Tags("OrgChild2")
|
||||
@Security("bearerAuth")
|
||||
export class OrgChild2Controller extends Controller {
|
||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ2 Child2
|
||||
|
|
@ -32,7 +36,7 @@ export class OrgChild2Controller extends Controller {
|
|||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Post("Child2")
|
||||
@Post("child2")
|
||||
@Example([
|
||||
{
|
||||
orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
|
|
@ -52,7 +56,7 @@ export class OrgChild2Controller extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgChild1 = await this.orgChild2Repository.findOne({
|
||||
const orgChild1 = await this.orgChild1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
const orgChild2 = Object.assign(new OrgChild2(), requestBody);
|
||||
|
|
@ -60,33 +64,34 @@ export class OrgChild2Controller extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Order: requestBody.orgChild2Order },
|
||||
where: { orgChild1Id: requestBody.orgChild1Id, orgChild2Order: requestBody.orgChild2Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Code: requestBody.orgChild2Code },
|
||||
where: { orgChild1Id: requestBody.orgChild1Id, orgChild2Code: requestBody.orgChild2Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if(orgChild1){
|
||||
orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild2Repository.save(orgChild2);
|
||||
}else{
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
|
||||
if (orgChild1) {
|
||||
orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.orgRootId = orgChild1.orgRootId;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild2Repository.save(orgChild2);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
@ -96,115 +101,99 @@ export class OrgChild2Controller extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* แก้ไขโครงสร้างระดับ Child2
|
||||
* แก้ไขโครงสร้างระดับ2 Child2
|
||||
*
|
||||
* @summary ORG_002 - แก้ไขโครงสร้างระดับ Child2 (ADMIN) #2
|
||||
* @summary ORG_008 - แก้ไขโครงสร้างระดับ2 (ADMIN) #8
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Put("Child2/{id}")
|
||||
// @Example([
|
||||
// {
|
||||
// orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
// orgChild2ShortName: "string", //อักษรย่อ
|
||||
// orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
// orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
// orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
// orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
// orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
// orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
// },
|
||||
// ])
|
||||
// async update(
|
||||
// @Path() id: string,
|
||||
// @Body()
|
||||
// requestBody: CreateOrgChild2,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
// ) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// const chkOrder = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Order: requestBody.orgChild2Order },
|
||||
// });
|
||||
// if (chkOrder != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
// const chkCode = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Code: requestBody.orgChild2Code },
|
||||
// });
|
||||
// if (chkCode != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
|
||||
// orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
// orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
// orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
// orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
// orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
// orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
// orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
// orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
// orgChild2.lastUpdateUserId = request.user.sub;
|
||||
// orgChild2.lastUpdateFullName = request.user.name;
|
||||
// await this.orgChild2Repository.save(orgChild2);
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
@Put("child2/{id}")
|
||||
@Example([
|
||||
{
|
||||
orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
orgChild2ShortName: "string", //อักษรย่อ
|
||||
orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
orgChild1Id: "Guid", //id Child1
|
||||
},
|
||||
])
|
||||
async update(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateOrgChild2,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgChild1 = await this.orgChild1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
if (!orgChild2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild2Order: requestBody.orgChild2Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild2Code: requestBody.orgChild2Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if (orgChild1) {
|
||||
orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild2Repository.save(orgChild2);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_003 - ลบโครงสร้างระดับ Child2 (ADMIN) #3
|
||||
* @summary ORG_009 - ลบโครงสร้างระดับ2 (ADMIN) #9
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Delete("Child2/{id}")
|
||||
// async delete(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// const orgChild1 = await await this.orgChild2Repository.findOne({ where: { id: id } });
|
||||
@Delete("Child2/{id}")
|
||||
async delete(@Path() id: string) {
|
||||
try {
|
||||
const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
const orgChild3 = await this.orgChild3Repository.findOne({ where: { id: id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
if (!orgChild2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
// if (!orgChild1) {
|
||||
// await this.orgChild2Repository.remove(orgChild2);
|
||||
// } else {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
// }
|
||||
if (!orgChild3) {
|
||||
await this.orgChild2Repository.remove(orgChild2);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
}
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* รายละเอียดโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_016 - รายละเอียดโครงสร้างระดับ Child2 (ADMIN) #16
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Get("Child2/{id}")
|
||||
// async detail(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess(orgChild2);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue