All files / libs/data-correction/overwrites/components/src/lib/overwrite-modal OverwriteModal.utils.ts

69.35% Statements 43/62
40% Branches 2/5
50% Functions 2/4
69.35% Lines 43/62

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 631x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x                 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x   1x 1x  
import {
  type CustomObjectOverwriteChanged,
  type DataOverwriteCreationRequestDetails,
  type KpiOverwriteChanged,
  type KpiOverwriteCreationRequestDetails,
  type OverwriteChanged,
  type RowTableOverwriteChanged,
  type RowTableOverwriteCreationRequestDetails,
} from './overwrite.types';
import { OverwriteContext, type OverwriteModalFormValues } from './OverwriteModal';
 
const createRowChangeForRowTable = (
  row: RowTableOverwriteCreationRequestDetails,
  values: OverwriteModalFormValues,
): RowTableOverwriteChanged => ({
  fieldMachineName: row.field,
  rowId: row.rowId,
  newValue: values.newValue,
  currency: values.currency,
  isApplyToOverall: values.isApplyToOverall,
});
 
const createRowChangeForCustomObject = (
  row: DataOverwriteCreationRequestDetails,
  values: OverwriteModalFormValues,
): CustomObjectOverwriteChanged => ({
  rowId: row.rowId,
  fieldMachineName: row.field,
  newValue: values.newValue,
  currency: values.currency,
  isApplyToOverall: values.isApplyToOverall,
});
 
const createRowChangeForKpi = (
  row: KpiOverwriteCreationRequestDetails,
  values: OverwriteModalFormValues,
): KpiOverwriteChanged => ({
  fieldMachineName: row.field,
  newValue: values.newValue,
  currency: values.currency,
  isApplyToOverall: values.isApplyToOverall,
});
 
export const createRowChange = (
  row:
    | DataOverwriteCreationRequestDetails
    | KpiOverwriteCreationRequestDetails
    | RowTableOverwriteCreationRequestDetails,
  values: OverwriteModalFormValues,
  type: OverwriteContext,
): OverwriteChanged => {
  switch (type) {
    case OverwriteContext.KPI:
      return createRowChangeForKpi(row as KpiOverwriteCreationRequestDetails, values);
    case OverwriteContext.ROWTABLE:
      return createRowChangeForRowTable(row as RowTableOverwriteCreationRequestDetails, values);
    case OverwriteContext.DATA:
      return createRowChangeForCustomObject(row as DataOverwriteCreationRequestDetails, values);
    default:
      throw new Error(`Unsupported overwrite context: ${type}`);
  }
};