diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 3f1f1858..e164f973 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -44,6 +44,7 @@ import { checkExceptCommandType, checkCommandType, removePostMasterAct, + logPositionIsSelectedChange, } from "../interfaces/utils"; import { Position } from "../entities/Position"; import { PosMaster } from "../entities/PosMaster"; @@ -3751,6 +3752,13 @@ export class CommandController extends Controller { }, }); 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; await this.positionRepository.save(positionOld); } @@ -3762,10 +3770,23 @@ export class CommandController extends Controller { }, }); if (checkPosition.length > 0) { - const clearPosition = checkPosition.map((positions) => ({ - ...positions, - positionIsSelected: false, - })); + console.log( + `[positionIsSelected-DEBUG] Command change: clearing ${checkPosition.length} positions (posMasterId: ${posMaster.id}, userId: ${request.user.sub}, endpoint: updateMaster)` + ); + + 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); } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index efcd1497..2f23bdaa 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -38,7 +38,7 @@ import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { AuthRole } from "../entities/AuthRole"; import { RequestWithUser } from "../middlewares/user"; 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 { PosMasterAssign } from "../entities/PosMasterAssign"; import { Assign } from "../entities/Assign"; @@ -1427,7 +1427,17 @@ export class PositionController extends Controller { requestBody.positions.map(async (x: any) => { const match = posMaster.positions.find((p: any) => p.id == x.id); 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; return match; } else { @@ -4034,7 +4044,18 @@ export class PositionController extends Controller { 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) => { + 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, { positionIsSelected: false, }); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 347f28af..be2f3bf9 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -751,4 +751,23 @@ export function resolveNodeId(data: any) { data.rootDnaId ?? 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(), + }); + } } \ No newline at end of file