All files / src/modules/filters/config filter-schema.config.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 0/0
100% Lines 7/7

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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 8113x                   13x                           13x                               13x                 13x                 13x                           13x                
import { ListingType } from '@prisma/client';
 
export interface FilterSchema {
  key: string;
  type: 'number' | 'enum' | 'multi-enum' | 'boolean' | 'range' | 'geo';
  label: string;
  values?: string[];
  range?: [number, number];
}
 
const commonFilters: FilterSchema[] = [
  { key: 'priceMin', type: 'range', label: 'Price' },
  { key: 'priceMax', type: 'range', label: 'Price' },
  { key: 'currency', type: 'enum', label: 'Currency', values: ['USD', 'UZS'] },
  { key: 'transactionType', type: 'enum', label: 'Transaction Type' },
  { key: 'areaMin', type: 'range', label: 'Area (m²)' },
  { key: 'areaMax', type: 'range', label: 'Area (m²)' },
  { key: 'hasPhotos', type: 'boolean', label: 'Has Photos' },
  { key: 'isVerified', type: 'boolean', label: 'Verified Listing' },
  { key: 'installmentAvailable', type: 'boolean', label: 'Installments' },
  { key: 'createdWithin', type: 'enum', label: 'Created Within', values: ['24h', '3d', '7d', '30d'] },
  { key: 'location', type: 'geo', label: 'Location' },
];
 
const apartmentFilters: FilterSchema[] = [
  ...commonFilters,
  { key: 'rooms', type: 'multi-enum', label: 'Rooms', values: ['1', '2', '3', '4', '5+'] },
  { key: 'bathrooms', type: 'multi-enum', label: 'Bathrooms', values: ['1', '2', '3+'] },
  { key: 'floor', type: 'range', label: 'Floor' },
  { key: 'totalFloors', type: 'range', label: 'Total Floors' },
  { key: 'furnished', type: 'boolean', label: 'Furnished' },
  { key: 'renovated', type: 'boolean', label: 'Renovated' },
  { key: 'balcony', type: 'boolean', label: 'Has Balcony' },
  { key: 'elevator', type: 'boolean', label: 'Has Elevator' },
  { key: 'heating', type: 'enum', label: 'Heating Type' },
  { key: 'buildingType', type: 'enum', label: 'Building Type' },
  { key: 'ceilingHeight', type: 'range', label: 'Ceiling Height (m)' },
  { key: 'yearBuilt', type: 'range', label: 'Year Built' },
];
 
const houseFilters: FilterSchema[] = [
  ...apartmentFilters,
  { key: 'landAreaMin', type: 'range', label: 'Land Area (m²)' },
  { key: 'landAreaMax', type: 'range', label: 'Land Area (m²)' },
  { key: 'floorCount', type: 'range', label: 'Floor Count' },
  { key: 'garage', type: 'boolean', label: 'Has Garage' },
  { key: 'basement', type: 'boolean', label: 'Has Basement' },
];
 
const commercialFilters: FilterSchema[] = [
  ...commonFilters,
  { key: 'businessType', type: 'enum', label: 'Business Type', values: ['office', 'warehouse', 'retail'] },
  { key: 'isInBusinessCenter', type: 'boolean', label: 'In Business Center' },
  { key: 'hasSecurity', type: 'boolean', label: 'Has Security' },
  { key: 'hasCCTV', type: 'boolean', label: 'Has CCTV' },
  { key: 'entranceType', type: 'enum', label: 'Entrance Type', values: ['street', 'yard', 'shared'] },
];
 
const landFilters: FilterSchema[] = [
    { key: 'priceMin', type: 'range', label: 'Price' },
    { key: 'priceMax', type: 'range', label: 'Price' },
    { key: 'currency', type: 'enum', label: 'Currency', values: ['USD', 'UZS'] },
    { key: 'transactionType', type: 'enum', label: 'Transaction Type' },
    { key: 'landAreaMin', type: 'range', label: 'Area (m²)' },
    { key: 'landAreaMax', type: 'range', label: 'Area (m²)' },
    { key: 'purpose', type: 'enum', label: 'Purpose', values: ['residential', 'commercial', 'agricultural'] },
    { key: 'utilitiesAvailable', type: 'multi-enum', label: 'Utilities', values: ['gas', 'electricity', 'water', 'internet'] },
    { key: 'roadAccess', type: 'boolean', label: 'Road Access' },
    { key: 'isFenced', type: 'boolean', label: 'Is Fenced' },
    { key: 'location', type: 'geo', label: 'Location' },
];
 
export const filterSchemaConfig: Record<ListingType, FilterSchema[]> = {
  [ListingType.APARTMENT]: apartmentFilters,
  [ListingType.HOUSE]: houseFilters,
  [ListingType.COMMERCIAL]: commercialFilters,
  [ListingType.LAND]: landFilters,
  // Extend with other types from your Prisma schema if they exist
  [ListingType.VILLA]: houseFilters, // Example: Villa can reuse house filters
  [ListingType.STUDIO]: apartmentFilters, // Example: Studio can reuse apartment filters
};