From 12f91b8b81418946cd899f3eeba9c389ae62dd40 Mon Sep 17 00:00:00 2001 From: Martin Porwoll Date: Sat, 21 Feb 2026 00:01:11 +0000 Subject: [PATCH] feat: add service and FAQ API methods Add createServiceApi (getServices, getServiceBySlug, getServiceCategories) and createFaqApi (getFaqs, getFaqsByCategory) modules following existing factory pattern. Wire into createPayloadClient as client.services and client.faqs. Co-Authored-By: Claude Opus 4.6 --- src/api-client/faqs.ts | 33 +++++++++++++++++++++++ src/api-client/index.ts | 8 ++++++ src/api-client/services.ts | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/api-client/faqs.ts create mode 100644 src/api-client/services.ts diff --git a/src/api-client/faqs.ts b/src/api-client/faqs.ts new file mode 100644 index 0000000..451c916 --- /dev/null +++ b/src/api-client/faqs.ts @@ -0,0 +1,33 @@ +/** + * FAQ API functions + */ +import type { Faq } from '../types/collections' +import type { PaginatedResponse, CollectionQueryParams } from '../types/api' +import type { PayloadClient } from './client' + +export function createFaqApi(client: PayloadClient) { + return { + /** + * Get all FAQs for the current tenant + */ + async getFaqs(options?: CollectionQueryParams): Promise> { + return client.getCollection('faqs', { + ...options, + limit: options?.limit ?? 100, + sort: options?.sort ?? 'order', + }) + }, + + /** + * Get FAQs filtered by category string (e.g. "allgemein", "kardiologie") + */ + async getFaqsByCategory(category: string, options?: Pick): Promise> { + return client.getCollection('faqs', { + ...options, + where: { 'category][equals': category }, + limit: 100, + sort: 'order', + }) + }, + } +} diff --git a/src/api-client/index.ts b/src/api-client/index.ts index 4e3596a..90c8ef7 100644 --- a/src/api-client/index.ts +++ b/src/api-client/index.ts @@ -18,6 +18,8 @@ import { createPageApi } from './pages' import { createPostApi } from './posts' import { createNavigationApi } from './navigation' import { createSettingsApi } from './settings' +import { createServiceApi } from './services' +import { createFaqApi } from './faqs' export type { PayloadClientConfig } from './client' export { PayloadClient, PayloadAPIError } from './client' @@ -41,6 +43,12 @@ export function createPayloadClient(config: PayloadClientConfig) { /** Site settings, SEO, cookie config */ settings: createSettingsApi(client), + /** Service & service category queries */ + services: createServiceApi(client), + + /** FAQ queries */ + faqs: createFaqApi(client), + /** * Generic collection query — use for collections not covered above * diff --git a/src/api-client/services.ts b/src/api-client/services.ts new file mode 100644 index 0000000..ba08fed --- /dev/null +++ b/src/api-client/services.ts @@ -0,0 +1,54 @@ +/** + * Service & Service Category API functions + */ +import type { Service, ServiceCategory } from '../types/collections' +import type { PaginatedResponse, CollectionQueryParams } from '../types/api' +import type { PayloadClient } from './client' + +export interface ServiceQueryOptions extends CollectionQueryParams { + category?: number | string + isFeatured?: boolean +} + +export function createServiceApi(client: PayloadClient) { + return { + /** + * Get all active services, optionally filtered by category + */ + async getServices(options?: ServiceQueryOptions): Promise> { + const where: Record = {} + if (options?.category) where['category][equals'] = options.category + if (options?.isFeatured) where['isFeatured][equals'] = true + + return client.getCollection('services', { + ...options, + sort: options?.sort ?? 'order', + where: { ...where, ...options?.where }, + }) + }, + + /** + * Get a single service by slug + */ + async getServiceBySlug(slug: string, options?: Pick): Promise { + const result = await client.getCollection('services', { + ...options, + depth: options?.depth ?? 3, + where: { 'slug][equals': slug }, + limit: 1, + }) + return result.docs[0] ?? null + }, + + /** + * Get all service categories + */ + async getServiceCategories(options?: Pick): Promise> { + return client.getCollection('service-categories', { + ...options, + limit: 100, + sort: 'order', + }) + }, + } +}