From e9ca789a1dfdc4fbe4c5d0ff044318480809d9a9 Mon Sep 17 00:00:00 2001 From: Michael Genson Date: Sat, 28 Mar 2026 16:42:09 +0000 Subject: [PATCH] allow passing axios config in CRUD --- frontend/lib/api/base/base-clients.ts | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/frontend/lib/api/base/base-clients.ts b/frontend/lib/api/base/base-clients.ts index 636747e02..161c7d55b 100644 --- a/frontend/lib/api/base/base-clients.ts +++ b/frontend/lib/api/base/base-clients.ts @@ -1,3 +1,4 @@ +import type { AxiosRequestConfig } from "axios"; import type { Recipe } from "../types/recipe"; import type { ApiRequestInstance, PaginationData } from "~/lib/api/types/non-generated"; import { type QueryValue, route } from "~/lib/api/base/route"; @@ -44,38 +45,38 @@ export abstract class BaseCRUDAPIReadOnly return this.itemRouteFn(itemId); } - async getAll(page = 1, perPage = -1, params = {} as Record) { + async getAll(page = 1, perPage = -1, params = {} as Record, config?: AxiosRequestConfig) { params = Object.fromEntries(Object.entries(params).filter(([_, v]) => v !== null && v !== undefined)); - return await this.requests.get>(route(this.baseRoute, { page, perPage, ...params })); + return await this.requests.get>(route(this.baseRoute, { page, perPage, ...params }), undefined, config); } - async getOne(itemId: string | number) { - return await this.requests.get(this.itemRoute(itemId)); + async getOne(itemId: string | number, config?: AxiosRequestConfig) { + return await this.requests.get(this.itemRoute(itemId), undefined, config); } } export abstract class BaseCRUDAPI extends BaseCRUDAPIReadOnly implements CrudAPIInterface { - async createOne(payload: CreateType) { - return await this.requests.post(this.baseRoute, payload); + async createOne(payload: CreateType, config?: AxiosRequestConfig) { + return await this.requests.post(this.baseRoute, payload, config); } - async updateOne(itemId: string | number, payload: UpdateType) { - return await this.requests.put(this.itemRoute(itemId), payload); + async updateOne(itemId: string | number, payload: UpdateType, config?: AxiosRequestConfig) { + return await this.requests.put(this.itemRoute(itemId), payload, config); } - async patchOne(itemId: string, payload: Partial) { - return await this.requests.patch>(this.itemRoute(itemId), payload); + async patchOne(itemId: string, payload: Partial, config?: AxiosRequestConfig) { + return await this.requests.patch>(this.itemRoute(itemId), payload, config); } - async deleteOne(itemId: string | number) { - return await this.requests.delete(this.itemRoute(itemId)); + async deleteOne(itemId: string | number, config?: AxiosRequestConfig) { + return await this.requests.delete(this.itemRoute(itemId), config); } - async duplicateOne(itemId: string | number, newName: string | undefined) { + async duplicateOne(itemId: string | number, newName: string | undefined, config?: AxiosRequestConfig) { return await this.requests.post(`${this.itemRoute(itemId)}/duplicate`, { name: newName, - }); + }, config); } }