122 lines
3.2 KiB
TypeScript
122 lines
3.2 KiB
TypeScript
import { readFile, readdir } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
|
|
const DATA_DIR = join(import.meta.dirname, '..', '..', 'data')
|
|
|
|
export interface UserData {
|
|
email: string
|
|
username: string
|
|
password: string
|
|
registrationSelection: string
|
|
}
|
|
|
|
export interface ProfileData {
|
|
user: UserData
|
|
profile: {
|
|
slug: string
|
|
displayName: string
|
|
bio: string
|
|
workTypes: string[]
|
|
visibleOnVerticals: string[]
|
|
primaryVertical: string
|
|
locationCity: string
|
|
locationState?: string
|
|
locationCountry: string
|
|
locationLat: number
|
|
locationLng: number
|
|
hourlyRateCents: number
|
|
currency: string
|
|
age: number
|
|
heightCm: number
|
|
hairColor: string
|
|
eyeColor: string
|
|
bodyType: string
|
|
ethnicity: string
|
|
offersIncall: boolean
|
|
offersOutcall: boolean
|
|
primaryPhotoUrl: string
|
|
galleryUrls: string[]
|
|
rates: Record<string, number>
|
|
}
|
|
attributes: Record<string, unknown>
|
|
}
|
|
|
|
export interface AttributeDefinition {
|
|
code: string
|
|
name: string
|
|
entityType: string
|
|
dataType: string
|
|
isSearchable: boolean
|
|
isMultiple?: boolean
|
|
grouping: string
|
|
displayOrder: number
|
|
description?: string
|
|
enumValues?: Array<{ value: string; displayValue: string }>
|
|
minValue?: number
|
|
maxValue?: number
|
|
}
|
|
|
|
export interface CostData {
|
|
categories: Array<{
|
|
category: string
|
|
costType: string
|
|
amount?: number
|
|
baseAmount?: number
|
|
maxAmount?: number
|
|
currency: string
|
|
description: string
|
|
vendor: string | null
|
|
}>
|
|
monthsBack: number
|
|
}
|
|
|
|
async function loadJson<T>(path: string): Promise<T> {
|
|
try {
|
|
const content = await readFile(path, 'utf-8')
|
|
return JSON.parse(content) as T
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err)
|
|
throw new Error(`Failed to load JSON from ${path}: ${message}`)
|
|
}
|
|
}
|
|
|
|
export async function loadProviderUsers(): Promise<UserData[]> {
|
|
return loadJson<UserData[]>(join(DATA_DIR, 'users', 'providers.json'))
|
|
}
|
|
|
|
export async function loadProfiles(): Promise<ProfileData[]> {
|
|
try {
|
|
const dir = join(DATA_DIR, 'profiles')
|
|
const files = await readdir(dir)
|
|
const profiles: ProfileData[] = []
|
|
for (const file of files.filter(f => f.endsWith('.json')).sort()) {
|
|
profiles.push(await loadJson<ProfileData>(join(dir, file)))
|
|
}
|
|
return profiles
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err)
|
|
throw new Error(`Failed to load profiles: ${message}`)
|
|
}
|
|
}
|
|
|
|
export async function loadAttributeDefinitions(): Promise<AttributeDefinition[]> {
|
|
try {
|
|
const dir = join(DATA_DIR, 'attributes', 'definitions')
|
|
const files = await readdir(dir)
|
|
const defs: AttributeDefinition[] = []
|
|
for (const file of files.filter(f => f.endsWith('.json')).sort()) {
|
|
const fileDefs = await loadJson<AttributeDefinition[]>(join(dir, file))
|
|
defs.push(...fileDefs)
|
|
}
|
|
return defs
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err)
|
|
throw new Error(`Failed to load attribute definitions: ${message}`)
|
|
}
|
|
}
|
|
|
|
export async function loadCostData(): Promise<CostData> {
|
|
return loadJson<CostData>(join(DATA_DIR, 'analytics', 'costs.json'))
|
|
}
|
|
|
|
export { DATA_DIR }
|