(filters: ListFilters)
| 328 | } |
| 329 | |
| 330 | async listProperties(filters: ListFilters): Promise<{ properties: CatalogProperty[]; next_cursor: string | null; total: number }> { |
| 331 | const conditions: string[] = []; |
| 332 | const params: any[] = []; |
| 333 | let paramIdx = 1; |
| 334 | |
| 335 | // Default: active properties only |
| 336 | conditions.push(`cp.status = $${paramIdx++}`); |
| 337 | params.push(filters.status ?? 'active'); |
| 338 | |
| 339 | if (filters.classification) { |
| 340 | conditions.push(`cp.classification = $${paramIdx++}`); |
| 341 | params.push(filters.classification); |
| 342 | } |
| 343 | |
| 344 | if (filters.source) { |
| 345 | conditions.push(`cp.source = $${paramIdx++}`); |
| 346 | params.push(filters.source); |
| 347 | } |
| 348 | |
| 349 | if (filters.search) { |
| 350 | conditions.push(`EXISTS ( |
| 351 | SELECT 1 FROM catalog_identifiers ci |
| 352 | WHERE ci.property_rid = cp.property_rid |
| 353 | AND ci.identifier_value ILIKE $${paramIdx++} ESCAPE '\\' |
| 354 | AND ci.disputed = FALSE |
| 355 | )`); |
| 356 | params.push(`%${filters.search.replace(/[%_\\]/g, '\\$&')}%`); |
| 357 | } |
| 358 | |
| 359 | if (filters.identifier_type) { |
| 360 | conditions.push(`EXISTS ( |
| 361 | SELECT 1 FROM catalog_identifiers ci |
| 362 | WHERE ci.property_rid = cp.property_rid |
| 363 | AND ci.identifier_type = $${paramIdx++} |
| 364 | AND ci.disputed = FALSE |
| 365 | )`); |
| 366 | params.push(filters.identifier_type); |
| 367 | } |
| 368 | |
| 369 | if (filters.cursor) { |
| 370 | conditions.push(`cp.property_rid > $${paramIdx++}`); |
| 371 | params.push(filters.cursor); |
| 372 | } |
| 373 | |
| 374 | const limit = Math.min(filters.limit ?? 100, 1000); |
| 375 | const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''; |
| 376 | |
| 377 | const countResult = await query<{ count: string }>( |
| 378 | `SELECT count(*) FROM catalog_properties cp ${where}`, |
| 379 | params |
| 380 | ); |
| 381 | |
| 382 | params.push(limit); |
| 383 | const result = await query<CatalogProperty>( |
| 384 | `SELECT cp.* FROM catalog_properties cp ${where} |
| 385 | ORDER BY cp.property_rid |
| 386 | LIMIT $${paramIdx}`, |
| 387 | params |
no outgoing calls
no test coverage detected