Isolate device row transactions
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { circuitDeviceRows } from "../schema/circuit-device-rows.js";
|
||||
|
||||
export interface CircuitDeviceRowUpdateInput {
|
||||
linkedProjectDeviceId?: string;
|
||||
name: string;
|
||||
displayName: string;
|
||||
phaseType?: string;
|
||||
connectionKind?: string;
|
||||
costGroup?: string;
|
||||
category?: string;
|
||||
level?: string;
|
||||
roomId?: string;
|
||||
roomNumberSnapshot?: string;
|
||||
roomNameSnapshot?: string;
|
||||
quantity: number;
|
||||
powerPerUnit: number;
|
||||
simultaneityFactor: number;
|
||||
cosPhi?: number;
|
||||
remark?: string;
|
||||
overriddenFields?: string;
|
||||
}
|
||||
|
||||
export type CircuitDeviceRowPatchInput = Partial<CircuitDeviceRowUpdateInput> & {
|
||||
sortOrder?: number;
|
||||
};
|
||||
|
||||
export interface CircuitDeviceRowCreateInput extends CircuitDeviceRowUpdateInput {
|
||||
circuitId: string;
|
||||
linkedProjectDeviceId?: string;
|
||||
legacyConsumerId?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export function toCircuitDeviceRowUpdateValues(input: CircuitDeviceRowUpdateInput) {
|
||||
return {
|
||||
linkedProjectDeviceId: input.linkedProjectDeviceId ?? null,
|
||||
name: input.name,
|
||||
displayName: input.displayName,
|
||||
phaseType: input.phaseType ?? null,
|
||||
connectionKind: input.connectionKind ?? null,
|
||||
costGroup: input.costGroup ?? null,
|
||||
category: input.category ?? null,
|
||||
level: input.level ?? null,
|
||||
roomId: input.roomId ?? null,
|
||||
roomNumberSnapshot: input.roomNumberSnapshot ?? null,
|
||||
roomNameSnapshot: input.roomNameSnapshot ?? null,
|
||||
quantity: input.quantity,
|
||||
powerPerUnit: input.powerPerUnit,
|
||||
simultaneityFactor: input.simultaneityFactor,
|
||||
cosPhi: input.cosPhi ?? null,
|
||||
remark: input.remark ?? null,
|
||||
overriddenFields: input.overriddenFields ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function toCircuitDeviceRowPatchValues(input: CircuitDeviceRowPatchInput) {
|
||||
const values: Partial<typeof circuitDeviceRows.$inferInsert> = {};
|
||||
const has = (field: keyof CircuitDeviceRowPatchInput) =>
|
||||
Object.prototype.hasOwnProperty.call(input, field);
|
||||
|
||||
if (has("linkedProjectDeviceId")) {
|
||||
values.linkedProjectDeviceId = input.linkedProjectDeviceId ?? null;
|
||||
}
|
||||
if (input.name !== undefined) values.name = input.name;
|
||||
if (input.displayName !== undefined) values.displayName = input.displayName;
|
||||
if (has("phaseType")) values.phaseType = input.phaseType ?? null;
|
||||
if (has("connectionKind")) values.connectionKind = input.connectionKind ?? null;
|
||||
if (has("costGroup")) values.costGroup = input.costGroup ?? null;
|
||||
if (has("category")) values.category = input.category ?? null;
|
||||
if (has("level")) values.level = input.level ?? null;
|
||||
if (has("roomId")) values.roomId = input.roomId ?? null;
|
||||
if (has("roomNumberSnapshot")) {
|
||||
values.roomNumberSnapshot = input.roomNumberSnapshot ?? null;
|
||||
}
|
||||
if (has("roomNameSnapshot")) values.roomNameSnapshot = input.roomNameSnapshot ?? null;
|
||||
if (input.quantity !== undefined) values.quantity = input.quantity;
|
||||
if (input.powerPerUnit !== undefined) values.powerPerUnit = input.powerPerUnit;
|
||||
if (input.simultaneityFactor !== undefined) {
|
||||
values.simultaneityFactor = input.simultaneityFactor;
|
||||
}
|
||||
if (has("cosPhi")) values.cosPhi = input.cosPhi ?? null;
|
||||
if (has("remark")) values.remark = input.remark ?? null;
|
||||
if (has("overriddenFields")) values.overriddenFields = input.overriddenFields ?? null;
|
||||
if (input.sortOrder !== undefined) values.sortOrder = input.sortOrder;
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
export function toCircuitDeviceRowCreateValues(
|
||||
id: string,
|
||||
input: CircuitDeviceRowCreateInput
|
||||
) {
|
||||
return {
|
||||
id,
|
||||
circuitId: input.circuitId,
|
||||
legacyConsumerId: input.legacyConsumerId ?? null,
|
||||
sortOrder: input.sortOrder,
|
||||
...toCircuitDeviceRowUpdateValues(input),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user