add log check isSelected in position
Some checks failed
Build & Deploy on Dev / build (push) Failing after 39s

This commit is contained in:
Warunee Tamkoo 2026-05-23 00:23:55 +07:00
parent 0c7c8e9fd3
commit e0f2513ba4
3 changed files with 67 additions and 6 deletions

View file

@ -44,6 +44,7 @@ import {
checkExceptCommandType, checkExceptCommandType,
checkCommandType, checkCommandType,
removePostMasterAct, removePostMasterAct,
logPositionIsSelectedChange,
} from "../interfaces/utils"; } from "../interfaces/utils";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
@ -3751,6 +3752,13 @@ export class CommandController extends Controller {
}, },
}); });
if (positionOld != null) { if (positionOld != null) {
logPositionIsSelectedChange(positionOld.id, positionOld.positionIsSelected, false, {
posMasterId: posMasterOld?.id,
userId: request.user.sub,
endpoint: "updateMaster",
action: "command_change_reset_old_position",
});
positionOld.positionIsSelected = false; positionOld.positionIsSelected = false;
await this.positionRepository.save(positionOld); await this.positionRepository.save(positionOld);
} }
@ -3762,10 +3770,23 @@ export class CommandController extends Controller {
}, },
}); });
if (checkPosition.length > 0) { if (checkPosition.length > 0) {
const clearPosition = checkPosition.map((positions) => ({ console.log(
...positions, `[positionIsSelected-DEBUG] Command change: clearing ${checkPosition.length} positions (posMasterId: ${posMaster.id}, userId: ${request.user.sub}, endpoint: updateMaster)`
positionIsSelected: false, );
}));
const clearPosition = checkPosition.map((positions) => {
logPositionIsSelectedChange(positions.id, positions.positionIsSelected, false, {
posMasterId: posMaster.id,
userId: request.user.sub,
endpoint: "updateMaster",
action: "command_change_clear_positions",
});
return {
...positions,
positionIsSelected: false,
};
});
await this.positionRepository.save(clearPosition); await this.positionRepository.save(clearPosition);
} }

View file

@ -38,7 +38,7 @@ import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { AuthRole } from "../entities/AuthRole"; import { AuthRole } from "../entities/AuthRole";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { resolveNodeLevel, setLogDataDiff } from "../interfaces/utils"; import { resolveNodeLevel, setLogDataDiff, logPositionIsSelectedChange } from "../interfaces/utils";
import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting"; import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
import { PosMasterAssign } from "../entities/PosMasterAssign"; import { PosMasterAssign } from "../entities/PosMasterAssign";
import { Assign } from "../entities/Assign"; import { Assign } from "../entities/Assign";
@ -1427,7 +1427,17 @@ export class PositionController extends Controller {
requestBody.positions.map(async (x: any) => { requestBody.positions.map(async (x: any) => {
const match = posMaster.positions.find((p: any) => p.id == x.id); const match = posMaster.positions.find((p: any) => p.id == x.id);
if (match) { if (match) {
match.positionIsSelected = x.positionIsSelected ?? false; const oldValue = match.positionIsSelected;
const newValue = x.positionIsSelected ?? false;
logPositionIsSelectedChange(match.id, oldValue, newValue, {
posMasterId: posMaster.id,
userId: request.user.sub,
endpoint: "updateMaster",
action: "update_position",
});
match.positionIsSelected = newValue;
match.orderNo = x.orderNo ?? null; match.orderNo = x.orderNo ?? null;
return match; return match;
} else { } else {
@ -4034,7 +4044,18 @@ export class PositionController extends Controller {
statusReport: "PENDING", statusReport: "PENDING",
}); });
console.log(
`[positionIsSelected-DEBUG] Deleting holder, resetting ALL positions to false (posMasterId: ${id}, userId: ${request.user.sub}, endpoint: deleteHolder)`
);
dataMaster.positions.forEach(async (position) => { dataMaster.positions.forEach(async (position) => {
logPositionIsSelectedChange(position.id, position.positionIsSelected, false, {
posMasterId: id,
userId: request.user.sub,
endpoint: "deleteHolder",
action: "delete_holder_reset_positions",
});
await this.positionRepository.update(position.id, { await this.positionRepository.update(position.id, {
positionIsSelected: false, positionIsSelected: false,
}); });

View file

@ -751,4 +751,23 @@ export function resolveNodeId(data: any) {
data.rootDnaId ?? data.rootDnaId ??
null null
); );
}
export function logPositionIsSelectedChange(
positionId: string,
oldValue: boolean,
newValue: boolean,
context: {
posMasterId?: string;
userId?: string;
endpoint?: string;
action?: string;
}
) {
if (oldValue !== newValue) {
console.log(`[positionIsSelected-DEBUG] Position ${positionId}: ${oldValue} -> ${newValue}`, {
...context,
timestamp: new Date().toISOString(),
});
}
} }