ตัดการเพิ่มฟิว order ไปก่อนและฟิว code validate เฉพาะ root และ child 1

This commit is contained in:
AdisakKanthawilang 2024-01-26 11:36:21 +07:00
parent 2dc74fc7d2
commit aca680f4f4
10 changed files with 204 additions and 274 deletions

View file

@ -1,21 +1,21 @@
import { AppDataSource } from "../database/data-source";
import { AppDataSource } from "../database/data-source";
import { OrgChild1, CreateOrgChild1, UpdateOrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2";
import {
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
@ -41,57 +41,52 @@ export class OrgChild1Controller {
async save(
@Body() requestBody: CreateOrgChild1,
@Request() request: { user: Record<string, any> },
){
try {
const chkOrder = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Order:requestBody.orgChild1Order }});
if (chkOrder != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Code:requestBody.orgChild1Code }});
if (chkCode != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
child1.orgChild1Name = requestBody.orgChild1Name
child1.createdUserId = request.user.sub
child1.createdFullName = request.user.name
child1.createdAt = new Date()
child1.lastUpdateUserId = request.user.sub
child1.lastUpdateFullName= request.user.name
child1.lastUpdatedAt = new Date()
await this.child1Repository.save(child1);
return new HttpSuccess();
} catch (error) {
// return new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, String(error))
return error;
) {
try {
const chkCode = await this.child1Repository.findOne({
where: { orgRootId: requestBody.orgRootId, orgChild1Code: requestBody.orgChild1Code },
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
child1.orgChild1Name = requestBody.orgChild1Name;
child1.createdUserId = request.user.sub;
child1.createdFullName = request.user.name;
child1.createdAt = new Date();
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.lastUpdatedAt = new Date();
await this.child1Repository.save(child1);
return new HttpSuccess();
} catch (error) {
// return new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, String(error))
return error;
}
}
/**
* API 1
*
* @summary ORG_005 - 1 (ADMIN) #5
*
* @param {string} id id 1
* @param {string} id id 1
*/
@Put("{id}")
async Edit(
@Path() id: string,
@Path() id: string,
@Body() requestBody: UpdateOrgChild1,
@Request() request: { user: Record<string, any> },
) {
) {
try {
const chkOrder = await this.child1Repository.findOne({ where: { id: id, orgChild1Order:requestBody.orgChild1Order }});
if (chkOrder != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.child1Repository.findOne({ where: { id: id, orgChild1Code:requestBody.orgChild1Code }});
if (chkCode != null){
const chkCode = await this.child1Repository.findOne({
where: { id: id, orgChild1Code: requestBody.orgChild1Code },
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child1 = await this.child1Repository.findOne({ where: { id } });
if (!child1){
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
child1.lastUpdateUserId = request.user.sub;
@ -110,20 +105,21 @@ export class OrgChild1Controller {
*
* @summary ORG_006 - 1 (ADMIN) #6
*
* @param {string} id id 1
* @param {string} id id 1
*/
@Delete("{id}")
async delete(
@Path() id: string,
) {
async delete(@Path() id: string) {
try {
const child1 = await this.child1Repository.findOne({ where: { id } });
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
if(exitsChild2){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2");
if (exitsChild2) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2",
);
}
await this.child1Repository.remove(child1);
return new HttpSuccess();
@ -131,5 +127,4 @@ export class OrgChild1Controller {
return error;
}
}
}

View file

@ -41,7 +41,7 @@ export class OrgChild2Controller extends Controller {
orgChild2Name: "string", //ชื่อหน่วยงาน
orgChild2ShortName: "string", //อักษรย่อ
orgChild2Code: "string", //รหัสหน่วยงาน
orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
// orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild2Fax: "string", //หมายเลขโทรสาร
@ -62,23 +62,12 @@ export class OrgChild2Controller extends Controller {
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkOrder = await this.orgChild2Repository.findOne({
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 },
});
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.orgChild2Order = requestBody.orgChild2Order;
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
@ -113,7 +102,7 @@ export class OrgChild2Controller extends Controller {
orgChild2Name: "string", //ชื่อหน่วยงาน
orgChild2ShortName: "string", //อักษรย่อ
orgChild2Code: "string", //รหัสหน่วยงาน
orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
// orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild2Fax: "string", //หมายเลขโทรสาร
@ -135,23 +124,12 @@ export class OrgChild2Controller extends Controller {
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.orgChild2Order = requestBody.orgChild2Order;
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
@ -188,7 +166,10 @@ export class OrgChild2Controller extends Controller {
if (!orgChild3) {
await this.orgChild2Repository.remove(orgChild2);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ3",
);
}
return new HttpSuccess();

View file

@ -1,22 +1,22 @@
import { AppDataSource } from "../database/data-source";
import { AppDataSource } from "../database/data-source";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3, CreateOrgChild3, UpdateOrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import {
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
@ -29,116 +29,101 @@ import HttpError from "../interfaces/http-error";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class OrgChild3Controller {
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
/**
* API 3
*
* @summary ORG_010 - 3 (ADMIN) #10
*
*/
@Post()
async save(
@Body() requestBody: CreateOrgChild3,
@Request() request: { user: Record<string, any> },
){
try {
const chkOrder = await this.child3Repository.findOne({ where: { orgChild2Id:requestBody.orgChild2Id, orgChild3Order:requestBody.orgChild3Order }});
if (chkOrder != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.child3Repository.findOne({ where: { orgChild2Id:requestBody.orgChild2Id, orgChild3Code:requestBody.orgChild3Code }});
if (chkCode != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
//BE ใช้ orgChild2Id หา orgChild1Id, orgRootId
const child2 = await this.child2Repository.findOne({ where: { id :requestBody.orgChild2Id }});
if(!child2){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
child3.orgChild3Name = requestBody.orgChild3Name
child3.createdUserId = request.user.sub
child3.createdFullName = request.user.name
child3.createdAt = new Date()
child3.lastUpdateUserId = request.user.sub
child3.lastUpdateFullName= request.user.name
child3.lastUpdatedAt = new Date()
child3.orgRootId = String(child2?.orgRootId),
child3.orgChild1Id = String(child2?.orgChild1Id),
await this.child3Repository.save(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
/**
* API 3
*
* @summary ORG_010 - 3 (ADMIN) #10
*
*/
@Post()
async save(
@Body() requestBody: CreateOrgChild3,
@Request() request: { user: Record<string, any> },
) {
try {
//BE ใช้ orgChild2Id หา orgChild1Id, orgRootId
const child2 = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id },
});
if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
child3.orgChild3Name = requestBody.orgChild3Name;
child3.createdUserId = request.user.sub;
child3.createdFullName = request.user.name;
child3.createdAt = new Date();
child3.lastUpdateUserId = request.user.sub;
child3.lastUpdateFullName = request.user.name;
child3.lastUpdatedAt = new Date();
(child3.orgRootId = String(child2?.orgRootId)),
(child3.orgChild1Id = String(child2?.orgChild1Id)),
await this.child3Repository.save(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
}
/**
* API 3
*
* @summary ORG_011 - 3 (ADMIN) #11
*
* @param {string} id id 3
*/
@Put("{id}")
async Edit(
@Path() id: string,
@Body() requestBody: UpdateOrgChild3,
@Request() request: { user: Record<string, any> },
){
try {
const chkOrder = await this.child3Repository.findOne({ where: { id: id, orgChild3Order:requestBody.orgChild3Order, }});
if (chkOrder != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.child3Repository.findOne({ where: { id: id, orgChild3Code:requestBody.orgChild3Code }});
if (chkCode != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
/**
* API 3
*
* @summary ORG_011 - 3 (ADMIN) #11
*
* @param {string} id id 3
*/
@Put("{id}")
async Edit(
@Path() id: string,
@Body() requestBody: UpdateOrgChild3,
@Request() request: { user: Record<string, any> },
) {
try {
const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
child3.lastUpdateUserId = request.user.sub;
child3.lastUpdateFullName = request.user.name;
child3.lastUpdatedAt = new Date();
this.child3Repository.merge(child3, requestBody);
await this.child3Repository.save(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
child3.lastUpdateUserId = request.user.sub;
child3.lastUpdateFullName = request.user.name;
child3.lastUpdatedAt = new Date();
this.child3Repository.merge(child3, requestBody);
await this.child3Repository.save(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
}
/**
* API 3
*
* @summary ORG_012 - 3 (ADMIN) #12
*
* @param {string} id id 3
*/
@Delete("{id}")
async delete(
@Path() id: string,
){
try {
const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
if(exitsChild4){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4");
}
await this.child3Repository.remove(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
/**
* API 3
*
* @summary ORG_012 - 3 (ADMIN) #12
*
* @param {string} id id 3
*/
@Delete("{id}")
async delete(@Path() id: string) {
try {
const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
if (exitsChild4) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
await this.child3Repository.remove(child3);
return new HttpSuccess();
} catch (error) {
return error;
}
}
}
}

View file

@ -40,7 +40,7 @@ export class OrgChild4Controller extends Controller {
orgChild4Name: "string", //ชื่อหน่วยงาน
orgChild4ShortName: "string", //อักษรย่อ
orgChild4Code: "string", //รหัสหน่วยงาน
orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
// orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild4Fax: "string", //หมายเลขโทรสาร
@ -51,11 +51,10 @@ export class OrgChild4Controller extends Controller {
async create(
@Body()
requestBody: CreateOrgChild4,
// @Request() request: { user: Record<string, any> },
@Request() request: { user: Record<string, any> },
) {
try {
console.log("child3Id:"+requestBody.orgChild3Id);
const orgChild3 = await this.orgChild3Repository.findOne({
where: { id: requestBody.orgChild3Id },
});
@ -63,23 +62,12 @@ export class OrgChild4Controller extends Controller {
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkOrder = await this.orgChild4Repository.findOne({
where: { orgChild3Id: requestBody.orgChild3Id, orgChild4Order: requestBody.orgChild4Order },
});
if (chkOrder != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.orgChild4Repository.findOne({
where: { orgChild3Id: requestBody.orgChild3Id, orgChild4Code: requestBody.orgChild4Code },
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
if (orgChild3) {
orgChild4.orgChild4Name = requestBody.orgChild4Name;
orgChild4.orgChild4ShortName = requestBody.orgChild4ShortName;
orgChild4.orgChild4Code = requestBody.orgChild4Code;
orgChild4.orgChild4Order = requestBody.orgChild4Order;
// orgChild4.orgChild4Order = requestBody.orgChild4Order;
orgChild4.orgChild4PhoneEx = requestBody.orgChild4PhoneEx;
orgChild4.orgChild4PhoneIn = requestBody.orgChild4PhoneIn;
orgChild4.orgChild4Fax = requestBody.orgChild4Fax;
@ -88,10 +76,10 @@ export class OrgChild4Controller extends Controller {
orgChild4.orgChild1Id = orgChild3.orgChild1Id;
orgChild4.orgChild2Id = orgChild3.orgChild2Id;
orgChild4.orgChild3Id = orgChild3.id;
// orgChild4.createdUserId = request.user.sub;
// orgChild4.createdFullName = request.user.name;
// orgChild4.lastUpdateUserId = request.user.sub;
// orgChild4.lastUpdateFullName = request.user.name;
orgChild4.createdUserId = request.user.sub;
orgChild4.createdFullName = request.user.name;
orgChild4.lastUpdateUserId = request.user.sub;
orgChild4.lastUpdateFullName = request.user.name;
await this.orgChild4Repository.save(orgChild4);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ3");
@ -116,7 +104,7 @@ export class OrgChild4Controller extends Controller {
orgChild4Name: "string", //ชื่อหน่วยงาน
orgChild4ShortName: "string", //อักษรย่อ
orgChild4Code: "string", //รหัสหน่วยงาน
orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
// orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild4Fax: "string", //หมายเลขโทรสาร
@ -138,23 +126,12 @@ export class OrgChild4Controller extends Controller {
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkOrder = await this.orgChild4Repository.findOne({
where: { orgChild4Order: requestBody.orgChild4Order },
});
if (chkOrder != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.orgChild4Repository.findOne({
where: { orgChild4Code: requestBody.orgChild4Code },
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
if (orgChild3) {
orgChild4.orgChild4Name = requestBody.orgChild4Name;
orgChild4.orgChild4ShortName = requestBody.orgChild4ShortName;
orgChild4.orgChild4Code = requestBody.orgChild4Code;
orgChild4.orgChild4Order = requestBody.orgChild4Order;
// orgChild4.orgChild4Order = requestBody.orgChild4Order;
orgChild4.orgChild4PhoneEx = requestBody.orgChild4PhoneEx;
orgChild4.orgChild4PhoneIn = requestBody.orgChild4PhoneIn;
orgChild4.orgChild4Fax = requestBody.orgChild4Fax;

View file

@ -38,7 +38,7 @@ export class OrgRootController extends Controller {
orgRootName: "string", //ชื่อหน่วยงาน
orgRootShortName: "string", //อักษรย่อ
orgRootCode: "string", //รหัสหน่วยงาน
orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
// orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgRootFax: "string", //หมายเลขโทรสาร
@ -56,12 +56,7 @@ export class OrgRootController extends Controller {
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkOrder = await this.orgRootRepository.findOne({
where: { orgRootOrder: requestBody.orgRootOrder },
});
if (chkOrder != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.orgRootRepository.findOne({
where: { orgRootCode: requestBody.orgRootCode },
});
@ -71,13 +66,13 @@ export class OrgRootController extends Controller {
orgRoot.orgRootName = requestBody.orgRootName;
orgRoot.orgRootShortName = requestBody.orgRootShortName;
orgRoot.orgRootCode = requestBody.orgRootCode;
orgRoot.orgRootOrder = requestBody.orgRootOrder;
// 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.createdUserId = request.user.sub;
orgRoot.createdFullName = request.user.name;
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
await this.orgRootRepository.save(orgRoot);
@ -101,7 +96,7 @@ export class OrgRootController extends Controller {
orgRootName: "string", //ชื่อหน่วยงาน
orgRootShortName: "string", //อักษรย่อ
orgRootCode: "string", //รหัสหน่วยงาน
orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
// orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgRootFax: "string", //หมายเลขโทรสาร
@ -119,23 +114,18 @@ export class OrgRootController extends Controller {
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkOrder = await this.orgRootRepository.findOne({
where: { orgRootOrder: requestBody.orgRootOrder },
});
if (chkOrder != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.orgRootRepository.findOne({
where: { orgRootCode: requestBody.orgRootCode },
});
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.orgRootOrder = requestBody.orgRootOrder;
orgRoot.orgRootPhoneEx = requestBody.orgRootPhoneEx;
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
orgRoot.orgRootFax = requestBody.orgRootFax;
@ -170,7 +160,10 @@ export class OrgRootController extends Controller {
if (!orgChild1) {
await this.orgRootRepository.remove(orgRoot);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
);
}
return new HttpSuccess();
@ -178,5 +171,4 @@ export class OrgRootController extends Controller {
return error;
}
}
}