edit posMaster
This commit is contained in:
parent
ff46ce568b
commit
ee6f2c8551
1 changed files with 168 additions and 18 deletions
|
|
@ -409,34 +409,40 @@ export class PositionController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
let orgRoot: any = null;
|
let orgRoot: any = null;
|
||||||
|
let SName: any = null;
|
||||||
if (requestBody.orgRootId != null)
|
if (requestBody.orgRootId != null)
|
||||||
orgRoot = await this.orgRootRepository.findOne({
|
orgRoot = await this.orgRootRepository.findOne({
|
||||||
where: { id: requestBody.orgRootId },
|
where: { id: requestBody.orgRootId },
|
||||||
});
|
});
|
||||||
|
SName = orgRoot.shortName;
|
||||||
if (!orgRoot) {
|
if (!orgRoot) {
|
||||||
let orgChild1: any = null;
|
let orgChild1: any = null;
|
||||||
if (requestBody.orgChild1Id != null)
|
if (requestBody.orgChild1Id != null)
|
||||||
orgChild1 = await this.child1Repository.findOne({
|
orgChild1 = await this.child1Repository.findOne({
|
||||||
where: { id: requestBody.orgChild1Id },
|
where: { id: requestBody.orgChild1Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild1.shortName;
|
||||||
if (!orgChild1) {
|
if (!orgChild1) {
|
||||||
let orgChild2: any = null;
|
let orgChild2: any = null;
|
||||||
if (requestBody.orgChild2Id != null)
|
if (requestBody.orgChild2Id != null)
|
||||||
orgChild2 = await this.child2Repository.findOne({
|
orgChild2 = await this.child2Repository.findOne({
|
||||||
where: { id: requestBody.orgChild2Id },
|
where: { id: requestBody.orgChild2Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild2.shortName;
|
||||||
if (!orgChild2) {
|
if (!orgChild2) {
|
||||||
let orgChild3: any = null;
|
let orgChild3: any = null;
|
||||||
if (requestBody.orgChild3Id != null)
|
if (requestBody.orgChild3Id != null)
|
||||||
orgChild3 = await this.child3Repository.findOne({
|
orgChild3 = await this.child3Repository.findOne({
|
||||||
where: { id: requestBody.orgChild3Id },
|
where: { id: requestBody.orgChild3Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild3.shortName;
|
||||||
if (!orgChild3) {
|
if (!orgChild3) {
|
||||||
let orgChild4: any = null;
|
let orgChild4: any = null;
|
||||||
if (requestBody.orgChild4Id != null)
|
if (requestBody.orgChild4Id != null)
|
||||||
orgChild4 = await this.child4Repository.findOne({
|
orgChild4 = await this.child4Repository.findOne({
|
||||||
where: { id: requestBody.orgChild4Id },
|
where: { id: requestBody.orgChild4Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild4.shortName;
|
||||||
if (!orgChild4) {
|
if (!orgChild4) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -480,9 +486,7 @@ export class PositionController extends Controller {
|
||||||
where: {
|
where: {
|
||||||
orgChild3Id: orgChild3.id,
|
orgChild3Id: orgChild3.id,
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -514,9 +518,7 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: orgChild2.id,
|
orgChild2Id: orgChild2.id,
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -549,9 +551,7 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: IsNull() || "",
|
orgChild2Id: IsNull() || "",
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -585,9 +585,7 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: IsNull() || "",
|
orgChild2Id: IsNull() || "",
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -603,6 +601,85 @@ export class PositionController extends Controller {
|
||||||
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chk_SName0 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgRoot: { orgRootShortName: SName },
|
||||||
|
orgChild1Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
},
|
||||||
|
relations: ['orgRoot'],
|
||||||
|
});
|
||||||
|
if (chk_SName0 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName1 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild1: { orgChild1ShortName: SName },
|
||||||
|
orgChild2Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
},
|
||||||
|
relations: ['orgChild1'],
|
||||||
|
});
|
||||||
|
if (chk_SName1 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName2 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild2: { orgChild2ShortName: SName },
|
||||||
|
orgChild3Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
},
|
||||||
|
relations: ['orgChild2'],
|
||||||
|
});
|
||||||
|
if (chk_SName2 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName3 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild3: { orgChild3ShortName: SName },
|
||||||
|
orgChild4Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
},
|
||||||
|
relations: ['orgChild3'],
|
||||||
|
});
|
||||||
|
if (chk_SName3 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName4 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild4: { orgChild4ShortName: SName },
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
},
|
||||||
|
relations: ['orgChild4'],
|
||||||
|
});
|
||||||
|
if (chk_SName4 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
posMaster.createdUserId = request.user.sub;
|
posMaster.createdUserId = request.user.sub;
|
||||||
posMaster.createdFullName = request.user.name;
|
posMaster.createdFullName = request.user.name;
|
||||||
posMaster.lastUpdateUserId = request.user.sub;
|
posMaster.lastUpdateUserId = request.user.sub;
|
||||||
|
|
@ -679,34 +756,40 @@ export class PositionController extends Controller {
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild4Id = null;
|
||||||
|
|
||||||
let orgRoot: any = null;
|
let orgRoot: any = null;
|
||||||
|
let SName: any = null;
|
||||||
if (requestBody.orgRootId != null)
|
if (requestBody.orgRootId != null)
|
||||||
orgRoot = await this.orgRootRepository.findOne({
|
orgRoot = await this.orgRootRepository.findOne({
|
||||||
where: { id: requestBody.orgRootId },
|
where: { id: requestBody.orgRootId },
|
||||||
});
|
});
|
||||||
|
SName = orgRoot.shortName;
|
||||||
if (!orgRoot) {
|
if (!orgRoot) {
|
||||||
let orgChild1: any = null;
|
let orgChild1: any = null;
|
||||||
if (requestBody.orgChild1Id != null)
|
if (requestBody.orgChild1Id != null)
|
||||||
orgChild1 = await this.child1Repository.findOne({
|
orgChild1 = await this.child1Repository.findOne({
|
||||||
where: { id: requestBody.orgChild1Id },
|
where: { id: requestBody.orgChild1Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild1.shortName;
|
||||||
if (!orgChild1) {
|
if (!orgChild1) {
|
||||||
let orgChild2: any = null;
|
let orgChild2: any = null;
|
||||||
if (requestBody.orgChild2Id != null)
|
if (requestBody.orgChild2Id != null)
|
||||||
orgChild2 = await this.child2Repository.findOne({
|
orgChild2 = await this.child2Repository.findOne({
|
||||||
where: { id: requestBody.orgChild2Id },
|
where: { id: requestBody.orgChild2Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild2.shortName;
|
||||||
if (!orgChild2) {
|
if (!orgChild2) {
|
||||||
let orgChild3: any = null;
|
let orgChild3: any = null;
|
||||||
if (requestBody.orgChild3Id != null)
|
if (requestBody.orgChild3Id != null)
|
||||||
orgChild3 = await this.child3Repository.findOne({
|
orgChild3 = await this.child3Repository.findOne({
|
||||||
where: { id: requestBody.orgChild3Id },
|
where: { id: requestBody.orgChild3Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild3.shortName;
|
||||||
if (!orgChild3) {
|
if (!orgChild3) {
|
||||||
let orgChild4: any = null;
|
let orgChild4: any = null;
|
||||||
if (requestBody.orgChild4Id != null)
|
if (requestBody.orgChild4Id != null)
|
||||||
orgChild4 = await this.child4Repository.findOne({
|
orgChild4 = await this.child4Repository.findOne({
|
||||||
where: { id: requestBody.orgChild4Id },
|
where: { id: requestBody.orgChild4Id },
|
||||||
});
|
});
|
||||||
|
SName = orgChild4.shortName;
|
||||||
if (!orgChild4) {
|
if (!orgChild4) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -714,9 +797,9 @@ export class PositionController extends Controller {
|
||||||
where: {
|
where: {
|
||||||
id: Not(posMaster.id),
|
id: Not(posMaster.id),
|
||||||
orgChild4Id: orgChild4.id,
|
orgChild4Id: orgChild4.id,
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
// posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
// posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -737,9 +820,9 @@ export class PositionController extends Controller {
|
||||||
id: Not(posMaster.id),
|
id: Not(posMaster.id),
|
||||||
orgChild3Id: orgChild3.id,
|
orgChild3Id: orgChild3.id,
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
// posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
// posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -760,9 +843,9 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: orgChild2.id,
|
orgChild2Id: orgChild2.id,
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
// posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
// posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -783,9 +866,9 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: IsNull() || "",
|
orgChild2Id: IsNull() || "",
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
// posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
// posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -806,9 +889,9 @@ export class PositionController extends Controller {
|
||||||
orgChild2Id: IsNull() || "",
|
orgChild2Id: IsNull() || "",
|
||||||
orgChild3Id: IsNull() || "",
|
orgChild3Id: IsNull() || "",
|
||||||
orgChild4Id: IsNull() || "",
|
orgChild4Id: IsNull() || "",
|
||||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
// posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||||
posMasterNo: requestBody.posMasterNo,
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
// posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (dataDup != null)
|
if (dataDup != null)
|
||||||
|
|
@ -820,6 +903,73 @@ export class PositionController extends Controller {
|
||||||
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chk_SName1 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild1: { orgChild1ShortName: SName },
|
||||||
|
orgChild2Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
id: Not(posMaster.id)
|
||||||
|
},
|
||||||
|
relations: ['orgChild1'],
|
||||||
|
});
|
||||||
|
if (chk_SName1 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName2 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild2: { orgChild2ShortName: SName },
|
||||||
|
orgChild3Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
id: Not(posMaster.id)
|
||||||
|
},
|
||||||
|
relations: ['orgChild2'],
|
||||||
|
});
|
||||||
|
if (chk_SName2 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName3 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild3: { orgChild3ShortName: SName },
|
||||||
|
orgChild4Id: IsNull(),
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
id: Not(posMaster.id)
|
||||||
|
},
|
||||||
|
relations: ['orgChild3'],
|
||||||
|
});
|
||||||
|
if (chk_SName3 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_SName4 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: posMaster.orgRevisionId,
|
||||||
|
orgChild4: { orgChild4ShortName: SName },
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
id: Not(posMaster.id)
|
||||||
|
},
|
||||||
|
relations: ['orgChild4'],
|
||||||
|
});
|
||||||
|
if (chk_SName4 != null){
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้
|
posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้
|
||||||
posMaster.createdFullName = request.user.name;
|
posMaster.createdFullName = request.user.name;
|
||||||
posMaster.lastUpdateUserId = request.user.sub;
|
posMaster.lastUpdateUserId = request.user.sub;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue