6515acb7f0
Error handling (Prompt 2): - src/services/errors.ts: AppError class, normalizeError(), throwServiceError() helper - 6 services wrapped with try/catch (property, match, need, shortlist, futureSignal, inquiry) - inquiryService aligned from custom ServiceResult<T> to standard ServiceResponse types - Results, MatchCenter, FutureAvailability pages show <ErrorState onRetry> on query failure AI modularisation (Prompt 3): - src/services/aiService.ts reduced from 755 → 19 lines (barrel re-export) - src/services/ai/IAIService.ts: typed interface + all response types - src/services/ai/mock/: needParser, compareBuilder, decisionBrief, listingParser, MockAIService - src/services/ai/openrouter/OpenRouterAIService.ts: model-agnostic skeleton - src/services/ai/prompts/: 4 prompt template files (needParsing, matchExplanation, compareSummary, decisionBrief) - src/services/ai/index.ts: factory selects Mock or OpenRouter via VITE_USE_REAL_AI flag - All existing import paths unchanged — zero call-site modifications Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { MockupShortlistProvider } from '../provider/MockupShortlistProvider'
|
|
import type { ShortlistFilters } from '../provider/IShortlistProvider'
|
|
import type { Shortlist, CreateShortlistInput, UpdateShortlistInput, ShortlistItemInput } from '../domain/shortlist'
|
|
import type { ListResponse, ItemResponse } from './types'
|
|
import { throwServiceError } from './errors'
|
|
|
|
const provider = MockupShortlistProvider
|
|
|
|
export const shortlistService = {
|
|
async getAll(filters?: ShortlistFilters): Promise<ListResponse<Shortlist>> {
|
|
try {
|
|
const data = await provider.getAll(filters)
|
|
return { data, meta: { total: data.length, page: 1, pageSize: data.length, hasMore: false } }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async getById(id: string): Promise<ItemResponse<Shortlist | null>> {
|
|
try {
|
|
const data = await provider.getById(id)
|
|
return { data }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async create(input: CreateShortlistInput): Promise<ItemResponse<Shortlist>> {
|
|
try {
|
|
const data = await provider.create(input)
|
|
return { data }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async update(id: string, input: UpdateShortlistInput): Promise<ItemResponse<Shortlist>> {
|
|
try {
|
|
const data = await provider.update(id, input)
|
|
return { data }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async addItem(id: string, item: ShortlistItemInput): Promise<ItemResponse<Shortlist>> {
|
|
try {
|
|
const data = await provider.addItem(id, item)
|
|
return { data }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async removeItem(id: string, resultId: string): Promise<ItemResponse<Shortlist>> {
|
|
try {
|
|
const data = await provider.removeItem(id, resultId)
|
|
return { data }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
async remove(id: string): Promise<ItemResponse<void>> {
|
|
try {
|
|
await provider.remove(id)
|
|
return { data: undefined }
|
|
} catch (err) {
|
|
throwServiceError(err)
|
|
}
|
|
},
|
|
}
|