/** * Types and utilities for handling GET query parameters and responses */ export enum Operator { eq = "eq", lt = "lt", lte = "lte", gt = "gt", gte = "gte", } export type LogicalCondition = { field: string; value: string; operator: Operator; }; export type InCondition = { field: string; value: Array }; /** * QueryParams is specifically used for the get API, defining pagination and filters */ export interface QueryParams { limit?: number; nextPage?: string; previousPage?: string; filter?: { in?: InCondition[]; and?: LogicalCondition[]; or?: LogicalCondition[]; }; } export interface Pagination { count: number; limit: number; nextPage?: string; previousPage?: string; } export interface PaginatedAPIResponse { data: T[]; paging: Pagination; } /** * Builds a logical condition string from an array of conditions * @param conditions Array of logical conditions * @param operator The logical operator to use ('and' or 'or') * @returns A string representation of the logical conditions */ export const buildLogicalCondition = ( conditions: LogicalCondition[], operator: "and" | "or" ): string => { return conditions .map( (condition) => `${condition.field} ${condition.operator} '${condition.value}'` ) .join(` ${operator} `); };