ย้าตำแหน่งไม่คำนวนเลขตำแหน่งใหม่
This commit is contained in:
parent
013ccf60e6
commit
ea70cebc49
2 changed files with 264 additions and 260 deletions
|
|
@ -1433,150 +1433,151 @@ export class EmployeePositionController extends Controller {
|
||||||
...type4LastPosMasterNo,
|
...type4LastPosMasterNo,
|
||||||
];
|
];
|
||||||
|
|
||||||
let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
|
// let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
|
||||||
|
|
||||||
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
|
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
|
||||||
posMasters.forEach(async (posMaster: any) => {
|
await Promise.all(
|
||||||
let change = true;
|
posMasters.map(async (posMaster: any) => {
|
||||||
|
let change = true;
|
||||||
|
|
||||||
if (requestBody.type == 0) {
|
if (requestBody.type == 0) {
|
||||||
const org = await this.orgRootRepository.findOne({
|
const org = await this.orgRootRepository.findOne({
|
||||||
where: { id: requestBody.id },
|
where: { id: requestBody.id },
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
|
||||||
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgRootId == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id == null &&
|
);
|
||||||
posMaster.orgChild3Id == null &&
|
if (
|
||||||
posMaster.orgChild4Id == null
|
posMaster.orgRootId == org.id &&
|
||||||
)
|
posMaster.orgChild1Id == null &&
|
||||||
change = false;
|
posMaster.orgChild2Id == null &&
|
||||||
posMaster.orgRootId = org.id;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgChild1Id = null;
|
)
|
||||||
posMaster.orgChild2Id = null;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.id;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild1Id = null;
|
||||||
|
posMaster.orgChild2Id = null;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 1) {
|
||||||
if (requestBody.type == 1) {
|
const org = await this.child1Repository.findOne({
|
||||||
const org = await this.child1Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
|
||||||
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgChild1Id == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild2Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild3Id == null &&
|
);
|
||||||
posMaster.orgChild4Id == null
|
if (
|
||||||
)
|
posMaster.orgChild1Id == org.id &&
|
||||||
change = false;
|
posMaster.orgChild2Id == null &&
|
||||||
posMaster.orgRootId = org.orgRootId;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgChild1Id = org.id;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
)
|
||||||
posMaster.orgChild2Id = null;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild2Id = null;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 2) {
|
||||||
if (requestBody.type == 2) {
|
const org = await this.child2Repository.findOne({
|
||||||
const org = await this.child2Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
|
||||||
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgChild2Id == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild3Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild4Id == null
|
);
|
||||||
)
|
if (
|
||||||
change = false;
|
posMaster.orgChild2Id == org.id &&
|
||||||
posMaster.orgRootId = org.orgRootId;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgChild2Id = org.id;
|
)
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 3) {
|
||||||
if (requestBody.type == 3) {
|
const org = await this.child3Repository.findOne({
|
||||||
const org = await this.child3Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
|
||||||
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
|
throw new HttpError(
|
||||||
posMaster.orgRootId = org.orgRootId;
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id = org.orgChild2Id;
|
);
|
||||||
posMaster.orgChild3Id = org.id;
|
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.orgChild2Id;
|
||||||
|
posMaster.orgChild3Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 4) {
|
||||||
if (requestBody.type == 4) {
|
const org = await this.child4Repository.findOne({
|
||||||
const org = await this.child4Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
|
||||||
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (posMaster.orgChild4Id == org.id) change = false;
|
throw new HttpError(
|
||||||
posMaster.orgRootId = org.orgRootId;
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id = org.orgChild2Id;
|
);
|
||||||
posMaster.orgChild3Id = org.orgChild3Id;
|
if (posMaster.orgChild4Id == org.id) change = false;
|
||||||
posMaster.orgChild4Id = org.id;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.orgChild2Id;
|
||||||
|
posMaster.orgChild3Id = org.orgChild3Id;
|
||||||
|
posMaster.orgChild4Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (change == true) {
|
||||||
if (change == true) {
|
posMaster.posMasterOrder = maxPosMasterOrder += 1;
|
||||||
// posMaster.posMasterNo = maxPosMasterNo += 1;
|
posMaster.createdUserId = request.user.sub;
|
||||||
posMaster.posMasterOrder = maxPosMasterOrder += 1;
|
posMaster.createdFullName = request.user.name;
|
||||||
posMaster.createdUserId = request.user.sub;
|
posMaster.lastUpdateUserId = request.user.sub;
|
||||||
posMaster.createdFullName = request.user.name;
|
posMaster.lastUpdateFullName = request.user.name;
|
||||||
posMaster.lastUpdateUserId = request.user.sub;
|
await this.employeePosMasterRepository.save(posMaster);
|
||||||
posMaster.lastUpdateFullName = request.user.name;
|
}
|
||||||
await this.employeePosMasterRepository.save(posMaster);
|
}),
|
||||||
}
|
);
|
||||||
});
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1621,146 +1621,149 @@ export class PositionController extends Controller {
|
||||||
// let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
|
// let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
|
||||||
|
|
||||||
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
|
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
|
||||||
posMasters.forEach(async (posMaster: any) => {
|
await Promise.all(
|
||||||
let change = true;
|
posMasters.map(async (posMaster: any) => {
|
||||||
|
let change = true;
|
||||||
|
|
||||||
if (requestBody.type == 0) {
|
if (requestBody.type == 0) {
|
||||||
const org = await this.orgRootRepository.findOne({
|
const org = await this.orgRootRepository.findOne({
|
||||||
where: { id: requestBody.id },
|
where: { id: requestBody.id },
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
|
||||||
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgRootId == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id == null &&
|
);
|
||||||
posMaster.orgChild3Id == null &&
|
if (
|
||||||
posMaster.orgChild4Id == null
|
posMaster.orgRootId == org.id &&
|
||||||
)
|
posMaster.orgChild1Id == null &&
|
||||||
change = false;
|
posMaster.orgChild2Id == null &&
|
||||||
posMaster.orgRootId = org.id;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgChild1Id = null;
|
)
|
||||||
posMaster.orgChild2Id = null;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.id;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild1Id = null;
|
||||||
|
posMaster.orgChild2Id = null;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 1) {
|
||||||
if (requestBody.type == 1) {
|
const org = await this.child1Repository.findOne({
|
||||||
const org = await this.child1Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
|
||||||
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgChild1Id == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild2Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild3Id == null &&
|
);
|
||||||
posMaster.orgChild4Id == null
|
if (
|
||||||
)
|
posMaster.orgChild1Id == org.id &&
|
||||||
change = false;
|
posMaster.orgChild2Id == null &&
|
||||||
posMaster.orgRootId = org.orgRootId;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgChild1Id = org.id;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
)
|
||||||
posMaster.orgChild2Id = null;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild2Id = null;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 2) {
|
||||||
if (requestBody.type == 2) {
|
const org = await this.child2Repository.findOne({
|
||||||
const org = await this.child2Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
|
||||||
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (
|
throw new HttpError(
|
||||||
posMaster.orgChild2Id == org.id &&
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild3Id == null &&
|
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild4Id == null
|
);
|
||||||
)
|
if (
|
||||||
change = false;
|
posMaster.orgChild2Id == org.id &&
|
||||||
posMaster.orgRootId = org.orgRootId;
|
posMaster.orgChild3Id == null &&
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
posMaster.orgChild4Id == null
|
||||||
posMaster.orgChild2Id = org.id;
|
)
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
change = false;
|
||||||
posMaster.orgChild3Id = null;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild3Id = null;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 3) {
|
||||||
if (requestBody.type == 3) {
|
const org = await this.child3Repository.findOne({
|
||||||
const org = await this.child3Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
|
||||||
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
|
throw new HttpError(
|
||||||
posMaster.orgRootId = org.orgRootId;
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id = org.orgChild2Id;
|
);
|
||||||
posMaster.orgChild3Id = org.id;
|
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
posMaster.orgChild4Id = null;
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.orgChild2Id;
|
||||||
|
posMaster.orgChild3Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
posMaster.orgChild4Id = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (requestBody.type == 4) {
|
||||||
if (requestBody.type == 4) {
|
const org = await this.child4Repository.findOne({
|
||||||
const org = await this.child4Repository.findOne({
|
where: { id: requestBody.id },
|
||||||
where: { id: requestBody.id },
|
|
||||||
});
|
|
||||||
if (org != null) {
|
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
|
||||||
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
|
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (org != null) {
|
||||||
throw new HttpError(
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
HttpStatusCode.NOT_FOUND,
|
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
|
||||||
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
});
|
||||||
);
|
if (_posMaster != null)
|
||||||
if (posMaster.orgChild4Id == org.id) change = false;
|
throw new HttpError(
|
||||||
posMaster.orgRootId = org.orgRootId;
|
HttpStatusCode.NOT_FOUND,
|
||||||
posMaster.orgChild1Id = org.orgChild1Id;
|
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
|
||||||
posMaster.orgChild2Id = org.orgChild2Id;
|
);
|
||||||
posMaster.orgChild3Id = org.orgChild3Id;
|
|
||||||
posMaster.orgChild4Id = org.id;
|
if (posMaster.orgChild4Id == org.id) change = false;
|
||||||
posMaster.orgRevisionId = org.orgRevisionId;
|
posMaster.orgRootId = org.orgRootId;
|
||||||
|
posMaster.orgChild1Id = org.orgChild1Id;
|
||||||
|
posMaster.orgChild2Id = org.orgChild2Id;
|
||||||
|
posMaster.orgChild3Id = org.orgChild3Id;
|
||||||
|
posMaster.orgChild4Id = org.id;
|
||||||
|
posMaster.orgRevisionId = org.orgRevisionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (change == true) {
|
||||||
if (change == true) {
|
posMaster.posMasterOrder = maxPosMasterOrder += 1;
|
||||||
posMaster.posMasterOrder = maxPosMasterOrder += 1;
|
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;
|
posMaster.lastUpdateFullName = request.user.name;
|
||||||
posMaster.lastUpdateFullName = request.user.name;
|
await this.posMasterRepository.save(posMaster);
|
||||||
await this.posMasterRepository.save(posMaster);
|
}
|
||||||
}
|
}),
|
||||||
});
|
);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue