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,
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);
}

View file

@ -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,
});

View file

@ -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(),
});
}
}