no message

This commit is contained in:
Kittapath 2024-02-21 17:10:30 +07:00
parent 6b2f1c99d8
commit 4ea60efd1a

View file

@ -413,35 +413,35 @@ export class PositionController extends Controller {
orgRoot = await this.orgRootRepository.findOne({ orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
SName = orgRoot.shortName; 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; 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; 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; 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; SName = orgChild4.shortName;
if (!orgChild4) { if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
} else { } else {
@ -607,9 +607,9 @@ export class PositionController extends Controller {
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
}, },
relations: ['orgRoot'], relations: ["orgRoot"],
}); });
if (chk_SName0 != null){ if (chk_SName0 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -623,9 +623,9 @@ export class PositionController extends Controller {
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
}, },
relations: ['orgChild1'], relations: ["orgChild1"],
}); });
if (chk_SName1 != null){ if (chk_SName1 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -639,9 +639,9 @@ export class PositionController extends Controller {
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
}, },
relations: ['orgChild2'], relations: ["orgChild2"],
}); });
if (chk_SName2 != null){ if (chk_SName2 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -655,9 +655,9 @@ export class PositionController extends Controller {
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
}, },
relations: ['orgChild3'], relations: ["orgChild3"],
}); });
if (chk_SName3 != null){ if (chk_SName3 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -670,9 +670,9 @@ export class PositionController extends Controller {
orgChild4: { orgChild4ShortName: SName }, orgChild4: { orgChild4ShortName: SName },
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
}, },
relations: ['orgChild4'], relations: ["orgChild4"],
}); });
if (chk_SName4 != null){ if (chk_SName4 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -689,9 +689,9 @@ export class PositionController extends Controller {
const position = Object.assign(new Position()); const position = Object.assign(new Position());
position.positionName = x.posDictName; position.positionName = x.posDictName;
position.positionField = x.posDictField; position.positionField = x.posDictField;
position.posTypeId = x.posTypeId; position.posTypeId = x.posTypeId == "" ? null : x.posTypeId;
position.posLevelId = x.posLevelId; position.posLevelId = x.posLevelId == "" ? null : x.posLevelId;
position.posExecutiveId = x.posExecutiveId; position.posExecutiveId = x.posExecutiveId == "" ? null : x.posExecutiveId;
position.positionExecutiveField = x.posDictExecutiveField; position.positionExecutiveField = x.posDictExecutiveField;
position.positionArea = x.posDictArea; position.positionArea = x.posDictArea;
position.isSpecial = x.isSpecial; position.isSpecial = x.isSpecial;
@ -761,35 +761,35 @@ export class PositionController extends Controller {
orgRoot = await this.orgRootRepository.findOne({ orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
SName = orgRoot.shortName; 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; 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; 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; 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; SName = orgChild4.shortName;
if (!orgChild4) { if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
} else { } else {
@ -909,11 +909,11 @@ export class PositionController extends Controller {
orgChild1: { orgChild1ShortName: SName }, orgChild1: { orgChild1ShortName: SName },
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id) id: Not(posMaster.id),
}, },
relations: ['orgChild1'], relations: ["orgChild1"],
}); });
if (chk_SName1 != null){ if (chk_SName1 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -926,11 +926,11 @@ export class PositionController extends Controller {
orgChild2: { orgChild2ShortName: SName }, orgChild2: { orgChild2ShortName: SName },
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id) id: Not(posMaster.id),
}, },
relations: ['orgChild2'], relations: ["orgChild2"],
}); });
if (chk_SName2 != null){ if (chk_SName2 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -943,11 +943,11 @@ export class PositionController extends Controller {
orgChild3: { orgChild3ShortName: SName }, orgChild3: { orgChild3ShortName: SName },
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id) id: Not(posMaster.id),
}, },
relations: ['orgChild3'], relations: ["orgChild3"],
}); });
if (chk_SName3 != null){ if (chk_SName3 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -959,11 +959,11 @@ export class PositionController extends Controller {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
orgChild4: { orgChild4ShortName: SName }, orgChild4: { orgChild4ShortName: SName },
posMasterNo: requestBody.posMasterNo, posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id) id: Not(posMaster.id),
}, },
relations: ['orgChild4'], relations: ["orgChild4"],
}); });
if (chk_SName4 != null){ if (chk_SName4 != null) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
@ -976,24 +976,27 @@ export class PositionController extends Controller {
posMaster.lastUpdateFullName = request.user.name; posMaster.lastUpdateFullName = request.user.name;
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
await this.positionRepository.delete({ posMasterId: posMaster.id }); await this.positionRepository.delete({ posMasterId: posMaster.id });
requestBody.positions.forEach(async (x: any) => {
const position = Object.assign(new Position()); await Promise.all(
position.positionName = x.posDictName; requestBody.positions.map(async (x: any) => {
position.positionField = x.posDictField; const position = Object.assign(new Position());
position.posTypeId = x.posTypeId; position.positionName = x.posDictName;
position.posLevelId = x.posLevelId; position.positionField = x.posDictField;
position.posExecutiveId = x.posExecutiveId; position.posTypeId = x.posTypeId == "" ? null : x.posTypeId;
position.positionExecutiveField = x.posDictExecutiveField; position.posLevelId = x.posLevelId == "" ? null : x.posLevelId;
position.positionArea = x.posDictArea; position.posExecutiveId = x.posExecutiveId == "" ? null : x.posExecutiveId;
position.isSpecial = x.isSpecial; position.positionExecutiveField = x.posDictExecutiveField;
position.positionIsSelected = false; position.positionArea = x.posDictArea;
position.posMasterId = posMaster.id; position.isSpecial = x.isSpecial;
position.createdUserId = request.user.sub; position.positionIsSelected = false;
position.createdFullName = request.user.name; position.posMasterId = posMaster.id;
position.lastUpdateUserId = request.user.sub; position.createdUserId = request.user.sub;
position.lastUpdateFullName = request.user.name; position.createdFullName = request.user.name;
await this.positionRepository.save(position); position.lastUpdateUserId = request.user.sub;
}); position.lastUpdateFullName = request.user.name;
await this.positionRepository.save(position);
}),
);
return new HttpSuccess(posMaster.id); return new HttpSuccess(posMaster.id);
} }