import type { ApiClient } from './ApiClient' import { BaseCrudApi } from './BaseCrudApi' import type { ListQuery } from './types' /** * CRUD base for resources that support soft-delete via an `archivedAt` timestamp * (PUT `${basePath}/${id}` with `{ archivedAt }`). Adds `archive`/`unarchive` on * top of {@link BaseCrudApi}. * * Only extend this for resources whose archive write mechanism is `archivedAt`. * Resources that archive through a different field (e.g. cards use `isArchived`) * or a dedicated endpoint (e.g. ticket-topics POST `/archive`) must NOT use this * base and should implement `archive`/`unarchive` themselves. */ export class ArchivableCrudApi< TResponse, TCreate, TUpdate extends { archivedAt?: string | null } = TCreate & { archivedAt?: string | null }, TQuery extends ListQuery = ListQuery, > extends BaseCrudApi { constructor(client: ApiClient, basePath: string) { super(client, basePath) this.archive = this.archive.bind(this) this.unarchive = this.unarchive.bind(this) } /** * Archives a resource (soft-delete) by setting `archivedAt` to the current time. * @permissions $resourceName.update */ archive(id: string, headers?: Record): Promise { return this.updateById(id, { archivedAt: new Date().toISOString() } as TUpdate, headers) } /** * Restores a previously archived resource by clearing `archivedAt`. * @permissions $resourceName.update */ unarchive(id: string, headers?: Record): Promise { return this.updateById(id, { archivedAt: null } as TUpdate, headers) } }