Prevent stale cell update overwrites
This commit is contained in:
@@ -182,30 +182,10 @@ export class CircuitWriteService {
|
||||
|
||||
const sectionId = input.sectionId ?? current.sectionId;
|
||||
const equipmentIdentifier = input.equipmentIdentifier ?? current.equipmentIdentifier;
|
||||
const sortOrder = input.sortOrder ?? current.sortOrder;
|
||||
await this.assertSectionInList(sectionId, current.circuitListId);
|
||||
await this.assertUniqueEquipmentIdentifier(current.circuitListId, equipmentIdentifier, circuitId);
|
||||
|
||||
await this.circuitRepository.update(circuitId, {
|
||||
sectionId,
|
||||
equipmentIdentifier,
|
||||
displayName: input.displayName ?? current.displayName ?? undefined,
|
||||
sortOrder,
|
||||
protectionType: input.protectionType ?? current.protectionType ?? undefined,
|
||||
protectionRatedCurrent: input.protectionRatedCurrent ?? current.protectionRatedCurrent ?? undefined,
|
||||
protectionCharacteristic:
|
||||
input.protectionCharacteristic ?? current.protectionCharacteristic ?? undefined,
|
||||
cableType: input.cableType ?? current.cableType ?? undefined,
|
||||
cableCrossSection: input.cableCrossSection ?? current.cableCrossSection ?? undefined,
|
||||
cableLength: input.cableLength ?? current.cableLength ?? undefined,
|
||||
rcdAssignment: input.rcdAssignment ?? current.rcdAssignment ?? undefined,
|
||||
terminalDesignation: input.terminalDesignation ?? current.terminalDesignation ?? undefined,
|
||||
voltage: input.voltage ?? current.voltage ?? undefined,
|
||||
controlRequirement: input.controlRequirement ?? current.controlRequirement ?? undefined,
|
||||
status: input.status ?? current.status ?? undefined,
|
||||
isReserve: input.isReserve ?? Boolean(current.isReserve),
|
||||
remark: input.remark ?? current.remark ?? undefined,
|
||||
});
|
||||
await this.circuitRepository.updateFields(circuitId, input);
|
||||
return this.circuitRepository.findById(circuitId);
|
||||
}
|
||||
|
||||
@@ -255,7 +235,7 @@ export class CircuitWriteService {
|
||||
throw new Error("Invalid device row id.");
|
||||
}
|
||||
await this.assertValidLinkedProjectDevice(current.circuitId, input.linkedProjectDeviceId);
|
||||
let overriddenFields = input.overriddenFields ?? current.overriddenFields ?? undefined;
|
||||
let overriddenFields = input.overriddenFields;
|
||||
if (current.linkedProjectDeviceId && input.overriddenFields === undefined) {
|
||||
const overrides = new Set(parseOverriddenFields(current.overriddenFields));
|
||||
const inputValues = input as Record<string, unknown>;
|
||||
@@ -270,24 +250,9 @@ export class CircuitWriteService {
|
||||
}
|
||||
overriddenFields = serializeOverriddenFields(overrides);
|
||||
}
|
||||
await this.deviceRowRepository.update(rowId, {
|
||||
linkedProjectDeviceId: input.linkedProjectDeviceId ?? current.linkedProjectDeviceId ?? undefined,
|
||||
name: input.name ?? current.name,
|
||||
displayName: input.displayName ?? current.displayName,
|
||||
phaseType: input.phaseType ?? current.phaseType ?? undefined,
|
||||
connectionKind: input.connectionKind ?? current.connectionKind ?? undefined,
|
||||
costGroup: input.costGroup ?? current.costGroup ?? undefined,
|
||||
category: input.category ?? current.category ?? undefined,
|
||||
level: input.level ?? current.level ?? undefined,
|
||||
roomId: input.roomId ?? current.roomId ?? undefined,
|
||||
roomNumberSnapshot: input.roomNumberSnapshot ?? current.roomNumberSnapshot ?? undefined,
|
||||
roomNameSnapshot: input.roomNameSnapshot ?? current.roomNameSnapshot ?? undefined,
|
||||
quantity: input.quantity ?? current.quantity,
|
||||
powerPerUnit: input.powerPerUnit ?? current.powerPerUnit,
|
||||
simultaneityFactor: input.simultaneityFactor ?? current.simultaneityFactor,
|
||||
cosPhi: input.cosPhi ?? current.cosPhi ?? undefined,
|
||||
remark: input.remark ?? current.remark ?? undefined,
|
||||
overriddenFields,
|
||||
await this.deviceRowRepository.updateFields(rowId, {
|
||||
...input,
|
||||
...(overriddenFields !== undefined ? { overriddenFields } : {}),
|
||||
});
|
||||
return this.deviceRowRepository.findById(rowId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user