This commit is contained in:
parent
7b22fb2a2d
commit
82d81334f5
1 changed files with 12 additions and 6 deletions
|
|
@ -3588,6 +3588,8 @@ export class CommandController extends Controller {
|
||||||
positionArea?: string | null;
|
positionArea?: string | null;
|
||||||
positionType: string | null;
|
positionType: string | null;
|
||||||
positionLevel: string | null;
|
positionLevel: string | null;
|
||||||
|
positionTypeId?: string | null;
|
||||||
|
positionLevelId?: string | null;
|
||||||
posmasterId: string;
|
posmasterId: string;
|
||||||
positionId: string;
|
positionId: string;
|
||||||
posExecutiveId?: string | null;
|
posExecutiveId?: string | null;
|
||||||
|
|
@ -3809,6 +3811,10 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
let positionNew: Position | null = null;
|
let positionNew: Position | null = null;
|
||||||
|
|
||||||
|
// Resolve ID: ใช้ positionTypeId/positionLevelId ก่อน ถ้าไม่มี fallback เป็น positionType/positionLevel
|
||||||
|
const posTypeId = item.positionTypeId || item.positionType;
|
||||||
|
const posLevelId = item.positionLevelId || item.positionLevel;
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
// CONDITION 1: เช็คจาก positionId ตรง
|
// CONDITION 1: เช็คจาก positionId ตรง
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
|
|
@ -3829,13 +3835,13 @@ export class CommandController extends Controller {
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
// CONDITION 2: Match 7 ฟิลด์ (ถ้า Condition 1 ไม่ match)
|
// CONDITION 2: Match 7 ฟิลด์ (ถ้า Condition 1 ไม่ match)
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
if (!positionNew && item.positionName && item.positionType && item.positionLevel) {
|
if (!positionNew && item.positionName && posTypeId && posLevelId) {
|
||||||
// สร้าง where clause แบบ dynamic - ใส่เฉพาะฟิลด์ที่มีค่า
|
// สร้าง where clause แบบ dynamic - ใส่เฉพาะฟิลด์ที่มีค่า
|
||||||
const whereCondition: any = {
|
const whereCondition: any = {
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
positionName: item.positionName,
|
positionName: item.positionName,
|
||||||
posTypeId: item.positionType, // positionType = posTypeId
|
posTypeId: posTypeId,
|
||||||
posLevelId: item.positionLevel, // positionLevel = posLevelId
|
posLevelId: posLevelId,
|
||||||
};
|
};
|
||||||
|
|
||||||
// เพิ่มเฉพาะฟิลด์ที่มีค่า (ไม่ใช่ null, undefined, หรือ string ว่าง)
|
// เพิ่มเฉพาะฟิลด์ที่มีค่า (ไม่ใช่ null, undefined, หรือ string ว่าง)
|
||||||
|
|
@ -3866,13 +3872,13 @@ export class CommandController extends Controller {
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
// CONDITION 3: Match 3 ฟิลด์ (ถ้า Condition 2 ไม่ match)
|
// CONDITION 3: Match 3 ฟิลด์ (ถ้า Condition 2 ไม่ match)
|
||||||
// ═══════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════
|
||||||
if (!positionNew && item.positionName && item.positionType && item.positionLevel) {
|
if (!positionNew && item.positionName && posTypeId && posLevelId) {
|
||||||
const positionBy3Fields = await this.positionRepository.findOne({
|
const positionBy3Fields = await this.positionRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
positionName: item.positionName,
|
positionName: item.positionName,
|
||||||
posTypeId: item.positionType,
|
posTypeId: posTypeId,
|
||||||
posLevelId: item.positionLevel,
|
posLevelId: posLevelId,
|
||||||
},
|
},
|
||||||
relations: ["posExecutive"],
|
relations: ["posExecutive"],
|
||||||
order: { orderNo: "ASC" }
|
order: { orderNo: "ASC" }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue