Skip to content

Nested Shapes #218

@paribaker

Description

@paribaker

I see we have tests for this but i am having issues with the toApi method and the shapes I had to use snake_case for this

import { z } from 'zod'
import { baseModelShape } from '../base-model'
import { GetInferredFromRaw } from '@thinknimble/tn-models'
import { antitrustStanceLabelMap, consumerGoodsSubIndustryLabelMap, departmentLabelMap, entertainmentSubIndustryLabelMap, ethnicityLabelMap, financialServicesSubIndustryLabelMap, genderLabelMap, governmentExperienceLabelMap, govtPositionLevelLabelMap, healthcareSubIndustryLabelMap, householdIncomeLabelMap, householdNetWorthLabelMap, independentLeanLabelMap, industryLabelMap, investableAssetsLabelMap, investorsNicheLabelMap, luxurySpendingLabelMap, marketingSubIndustryLabelMap, policyAreaLabelMap, policyExperienceLabelMap, policyFunctionLabelMap, politicalAffiliationLabelMap, politicalPositioningLabelMap, positionLevelLabelMap, professionalServicesSubIndustryLabelMap, sizeOfOrganizationLabelMap, steerDemocratLabelMap, steerRepublicanLabelMap, techExpertiseLabelMap, technologySubIndustryLabelMap, timeInPolicyRoleLabelMap } from '../participant/models'

// Define the advanced filter structure to match what the frontend expects
const selectOptionShape = {
  value: z.string(),
  label: z.string(),
}

const filterConditionShape = {
  id: z.string(),
  type: z.enum(['search', 'attribute', 'lockout']),
  logical_operator: z.enum(['AND', 'OR']),
  searchTerm: z.string().default(''),
  field: z.string().optional(),
  operator: z.string(),
  value: z.array(z.object(selectOptionShape)).optional(),
  attributeEntity: z.object(selectOptionShape).nullable().optional(),
  lockoutType: z.string().optional(),
  lockoutEntity: z.object(selectOptionShape).nullable().optional(),
  lockoutPeriod: z.string().optional(),
}

const filterGroupShape ={
  id: z.string(),
  logical_operator: z.string(), // hack tnmodels issue
  conditions: z.array(z.object(filterConditionShape)),
 
}

export const participantSearchFilterShape = {
  ...baseModelShape,
  user: z.string().uuid().nullable().optional(),
  project: z.string().uuid().nullable().optional(),
  title: z.string().optional(),
  filters: z.array(z.object(filterGroupShape)).optional().default([]),
}

export const participantFiltersFilterShape = {
  project: z.string().array(),
}
export const createParticipantSearchFilterShape = {
  ...participantSearchFilterShape,
  id: z.string().optional(),
}
export type ParticipantFiltersFilter = GetInferredFromRaw<typeof participantFiltersFilterShape>
export type ParticipantSearchFilters = GetInferredFromRaw<typeof participantSearchFilterShape>

// Export the inferred types for use in components
export type FilterCondition = GetInferredFromRaw<typeof filterConditionShape>
export type FilterGroup = GetInferredFromRaw<typeof filterGroupShape>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions