87 lines
3.0 KiB
TypeScript
87 lines
3.0 KiB
TypeScript
export interface CircuitCreatePersistenceInput {
|
|
circuitListId: string;
|
|
sectionId: string;
|
|
equipmentIdentifier: string;
|
|
displayName?: string;
|
|
sortOrder: number;
|
|
cableType?: string;
|
|
cableCrossSection?: string;
|
|
cableLength?: number;
|
|
voltage?: number;
|
|
controlRequirement?: string;
|
|
remark?: string;
|
|
rcdAssignment?: string;
|
|
terminalDesignation?: string;
|
|
status?: string;
|
|
isReserve?: boolean;
|
|
}
|
|
|
|
export interface CircuitPatchPersistenceInput {
|
|
sectionId?: string;
|
|
equipmentIdentifier?: string;
|
|
displayName?: string | null;
|
|
sortOrder?: number;
|
|
cableType?: string | null;
|
|
cableCrossSection?: string | null;
|
|
cableLength?: number | null;
|
|
voltage?: number | null;
|
|
controlRequirement?: string | null;
|
|
remark?: string | null;
|
|
rcdAssignment?: string | null;
|
|
terminalDesignation?: string | null;
|
|
status?: string | null;
|
|
isReserve?: boolean;
|
|
}
|
|
|
|
export function toCircuitCreateValues(id: string, input: CircuitCreatePersistenceInput) {
|
|
return {
|
|
id,
|
|
circuitListId: input.circuitListId,
|
|
sectionId: input.sectionId,
|
|
equipmentIdentifier: input.equipmentIdentifier,
|
|
displayName: input.displayName ?? null,
|
|
sortOrder: input.sortOrder,
|
|
cableType: input.cableType ?? null,
|
|
cableCrossSection: input.cableCrossSection ?? null,
|
|
cableLength: input.cableLength ?? null,
|
|
rcdAssignment: input.rcdAssignment ?? null,
|
|
terminalDesignation: input.terminalDesignation ?? null,
|
|
voltage: input.voltage ?? null,
|
|
controlRequirement: input.controlRequirement ?? null,
|
|
status: input.status ?? null,
|
|
isReserve: input.isReserve ? 1 : 0,
|
|
remark: input.remark ?? null,
|
|
};
|
|
}
|
|
|
|
export function toCircuitPatchValues(input: CircuitPatchPersistenceInput) {
|
|
const values: Partial<ReturnType<typeof toCircuitCreateValues>> = {};
|
|
const has = (field: keyof CircuitPatchPersistenceInput) =>
|
|
Object.prototype.hasOwnProperty.call(input, field);
|
|
|
|
if (input.sectionId !== undefined) values.sectionId = input.sectionId;
|
|
if (input.equipmentIdentifier !== undefined) {
|
|
values.equipmentIdentifier = input.equipmentIdentifier;
|
|
}
|
|
if (has("displayName")) values.displayName = input.displayName ?? null;
|
|
if (input.sortOrder !== undefined) values.sortOrder = input.sortOrder;
|
|
if (has("cableType")) values.cableType = input.cableType ?? null;
|
|
if (has("cableCrossSection")) {
|
|
values.cableCrossSection = input.cableCrossSection ?? null;
|
|
}
|
|
if (has("cableLength")) values.cableLength = input.cableLength ?? null;
|
|
if (has("rcdAssignment")) values.rcdAssignment = input.rcdAssignment ?? null;
|
|
if (has("terminalDesignation")) {
|
|
values.terminalDesignation = input.terminalDesignation ?? null;
|
|
}
|
|
if (has("voltage")) values.voltage = input.voltage ?? null;
|
|
if (has("controlRequirement")) {
|
|
values.controlRequirement = input.controlRequirement ?? null;
|
|
}
|
|
if (has("status")) values.status = input.status ?? null;
|
|
if (input.isReserve !== undefined) values.isReserve = input.isReserve ? 1 : 0;
|
|
if (has("remark")) values.remark = input.remark ?? null;
|
|
|
|
return values;
|
|
}
|