Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-04-25 17:48:39 +07:00
commit e1d0ebf308
2 changed files with 75 additions and 1 deletions

View file

@ -28,6 +28,7 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition";
import { Like } from "typeorm/browser";
@Route("api/v1/org/child1")
@Tags("OrgChild1")
@Security("bearerAuth")
@ -134,6 +135,24 @@ export class OrgChild1Controller {
"รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว",
);
}
const chkShort = await this.child1Repository.findOne({
where: {
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
if(requestBody.orgChild1Code == rootIdExits.orgRootCode){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน");
}
if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน");
}
const order: any = await this.child1Repository.findOne({
where: {
orgRootId: requestBody.orgRootId,
@ -194,7 +213,7 @@ export class OrgChild1Controller {
requestBody.orgChild1Rank == null ||
!validOrgChild1Ranks.includes(requestBody.orgChild1Rank.toUpperCase())
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild1Rank");
}
const child1 = await this.child1Repository.findOne({ where: { id } });
@ -212,6 +231,25 @@ export class OrgChild1Controller {
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.child1Repository.findOne({
where: {
id: Not(id),
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
if(requestBody.orgChild1Code == rootIdExits.orgRootCode){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้ซ้ำกับรหัสหน่วยงาน");
}
if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน");
}
child1.lastUpdateUserId = request.user.sub;
child1.lastUpdateFullName = request.user.name;
child1.lastUpdatedAt = new Date();

View file

@ -116,6 +116,13 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.orgRootRepository.findOne({
where: { orgRevisionId: requestBody.orgRevisionId, orgRootShortName: requestBody.orgRootShortName },
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId },
});
@ -198,10 +205,39 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.orgRootRepository.findOne({
where: { orgRevisionId: requestBody.orgRevisionId, orgRootShortName: requestBody.orgRootShortName },
});
if (chkCode?.id != id && chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
}
const chkCodeChild1 = await this.orgChild1Repository.findOne({
where:{
orgRevisionId : requestBody.orgRevisionId,
orgRootId: id,
orgChild1Code: requestBody.orgRootCode,
}
});
if(chkCodeChild1 != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้ซ้ำกับรหัสส่วนราชการ");
}
const chkShortChild1 = await this.orgChild1Repository.findOne({
where:{
orgRevisionId : requestBody.orgRevisionId,
orgRootId: id,
orgChild1ShortName: requestBody.orgRootShortName,
}
});
if(chkShortChild1 != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อส่วนราชการ");
}
orgRoot.lastUpdateUserId = request.user.sub;
orgRoot.lastUpdateFullName = request.user.name;
orgRoot.lastUpdatedAt = new Date();