fix OrgController
This commit is contained in:
parent
22324853db
commit
e05d4f8d8e
10 changed files with 58 additions and 90 deletions
|
|
@ -19,6 +19,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
|
||||
@Route("organization")
|
||||
@Tags("OrgRoot")
|
||||
|
|
@ -26,6 +27,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
export class OrgRootController extends Controller {
|
||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ Root
|
||||
|
|
@ -39,7 +41,6 @@ export class OrgRootController extends Controller {
|
|||
orgRootName: "string", //ชื่อหน่วยงาน
|
||||
orgRootShortName: "string", //อักษรย่อ
|
||||
orgRootCode: "string", //รหัสหน่วยงาน
|
||||
// orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgRootFax: "string", //หมายเลขโทรสาร
|
||||
|
|
@ -53,6 +54,10 @@ export class OrgRootController extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
});
|
||||
|
||||
const orgRoot = Object.assign(new OrgRoot(), requestBody);
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -64,19 +69,17 @@ export class OrgRootController extends Controller {
|
|||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
orgRoot.orgRootName = requestBody.orgRootName;
|
||||
orgRoot.orgRootShortName = requestBody.orgRootShortName;
|
||||
orgRoot.orgRootCode = requestBody.orgRootCode;
|
||||
// orgRoot.orgRootOrder = requestBody.orgRootOrder;
|
||||
orgRoot.orgRootPhoneEx = requestBody.orgRootPhoneEx;
|
||||
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
||||
orgRoot.orgRootFax = requestBody.orgRootFax;
|
||||
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
if (orgRevision) {
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
}else{
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี Revision");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
|
|
@ -97,7 +100,6 @@ export class OrgRootController extends Controller {
|
|||
orgRootName: "string", //ชื่อหน่วยงาน
|
||||
orgRootShortName: "string", //อักษรย่อ
|
||||
orgRootCode: "string", //รหัสหน่วยงาน
|
||||
// orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgRootFax: "string", //หมายเลขโทรสาร
|
||||
|
|
@ -119,20 +121,14 @@ export class OrgRootController extends Controller {
|
|||
const chkCode = await this.orgRootRepository.findOne({
|
||||
where: { orgRootCode: requestBody.orgRootCode },
|
||||
});
|
||||
if (chkCode?.id != id && chkCode != null ) {
|
||||
if (chkCode?.id != id && chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
orgRoot.orgRootName = requestBody.orgRootName;
|
||||
orgRoot.orgRootShortName = requestBody.orgRootShortName;
|
||||
orgRoot.orgRootCode = requestBody.orgRootCode;
|
||||
// orgRoot.orgRootOrder = requestBody.orgRootOrder;
|
||||
orgRoot.orgRootPhoneEx = requestBody.orgRootPhoneEx;
|
||||
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
||||
orgRoot.orgRootFax = requestBody.orgRootFax;
|
||||
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
||||
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
this.orgRootRepository.merge(orgRoot, requestBody);
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue