#2505
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s

This commit is contained in:
Adisak 2026-05-25 18:19:34 +07:00
parent 7b22fb2a2d
commit 82d81334f5

View file

@ -3588,6 +3588,8 @@ export class CommandController extends Controller {
positionArea?: string | null;
positionType: string | null;
positionLevel: string | null;
positionTypeId?: string | null;
positionLevelId?: string | null;
posmasterId: string;
positionId: string;
posExecutiveId?: string | null;
@ -3809,6 +3811,10 @@ export class CommandController extends Controller {
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 ตรง
// ═══════════════════════════════════════════════════════════
@ -3829,13 +3835,13 @@ export class CommandController extends Controller {
// ═══════════════════════════════════════════════════════════
// CONDITION 2: Match 7 ฟิลด์ (ถ้า Condition 1 ไม่ match)
// ═══════════════════════════════════════════════════════════
if (!positionNew && item.positionName && item.positionType && item.positionLevel) {
if (!positionNew && item.positionName && posTypeId && posLevelId) {
// สร้าง where clause แบบ dynamic - ใส่เฉพาะฟิลด์ที่มีค่า
const whereCondition: any = {
posMasterId: posMaster.id,
positionName: item.positionName,
posTypeId: item.positionType, // positionType = posTypeId
posLevelId: item.positionLevel, // positionLevel = posLevelId
posTypeId: posTypeId,
posLevelId: posLevelId,
};
// เพิ่มเฉพาะฟิลด์ที่มีค่า (ไม่ใช่ null, undefined, หรือ string ว่าง)
@ -3866,13 +3872,13 @@ export class CommandController extends Controller {
// ═══════════════════════════════════════════════════════════
// 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({
where: {
posMasterId: posMaster.id,
positionName: item.positionName,
posTypeId: item.positionType,
posLevelId: item.positionLevel,
posTypeId: posTypeId,
posLevelId: posLevelId,
},
relations: ["posExecutive"],
order: { orderNo: "ASC" }