All files / libs/payout-definition/state/src/lib queries.keys.ts

0% Statements 0/54
0% Branches 0/1
0% Functions 0/1
0% Lines 0/54

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                                                                                                             
import { type Plan, type Rule } from '@amalia/payout-definition/plans/types';

import { type PlansApiClient } from './plans/plans.api-client';

export const plansQueryKeys = {
  all: () => ['plans'] as const,
  allLists: () => [...plansQueryKeys.all(), 'list'] as const,
  list: (filters?: Parameters<(typeof PlansApiClient)['list']>[0]) =>
    [...plansQueryKeys.all(), 'list', filters] as const,
  template: {
    all: () => [...plansQueryKeys.all(), 'template'] as const,
    ofPlan: (planId: Plan['id']) => [...plansQueryKeys.template.all(), planId] as const,
  },
  details: (planId: Plan['id']) => [...plansQueryKeys.all(), 'details', planId] as const,

  // Note: I'm wondering if this should be in statements instead, like a get statements count by plan id?
  // Bc we invalidate all statements queries after a calculation and it impacts this query.
  allModifiers: () => [...plansQueryKeys.all(), 'modifiers'] as const,
  modifiers: (planId: Plan['id']) => [...plansQueryKeys.allModifiers(), planId] as const,
} as const;

export const plansMutationKeys = {
  all: () => ['plans'] as const,
  create: () => [...plansMutationKeys.all(), 'create'] as const,
  duplicate: () => [...plansMutationKeys.all(), 'duplicate'] as const,
  archive: () => [...plansMutationKeys.all(), 'archive'] as const,
  delete: () => [...plansMutationKeys.all(), 'delete'] as const,
  anyPatchVisibility: () => [...plansMutationKeys.all(), 'any-patch-visibility'] as const,
  patchVisibility: (planId: Plan['id']) => [...plansMutationKeys.anyPatchVisibility(), planId] as const,
  patch: (planId: Plan['id']) => [...plansMutationKeys.all(), 'patch', planId] as const,
  importFromOtherPlan: (planId: Plan['id']) => [...plansMutationKeys.all(), 'import-from-other-plan', planId] as const,
  computeTemplate: (planId: Plan['id']) => [...plansMutationKeys.all(), 'compute-template', planId] as const,
} as const;

export const rulesV2QueryKeys = {
  all: () => ['rules-v2'] as const,
  configurations: {
    all: () => [...rulesV2QueryKeys.all(), 'configurations'] as const,
    ofPlan: {
      all: (planId: Plan['id']) => [...rulesV2QueryKeys.configurations.all(), 'of-plan', planId] as const,
      list: (planId: Plan['id']) => [...rulesV2QueryKeys.configurations.ofPlan.all(planId), 'list'] as const,
      details: (planId: Plan['id'], ruleId: Rule['id']) =>
        [...rulesV2QueryKeys.configurations.ofPlan.all(planId), 'details', ruleId] as const,
    } as const,
  } as const,
} as const;

export const rulesV2MutationKeys = {
  all: () => ['rules-v2'] as const,
  configurations: {
    all: () => [...rulesV2MutationKeys.all(), 'configurations'] as const,
    updateRuleAssignment: () => [...rulesV2MutationKeys.configurations.all(), 'update-rule-assignment'] as const,
  } as const,
} as const;