From f32e1ceec4dce9f815541d042ef769f7f146931b Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Sun, 5 Oct 2025 12:59:35 +0700 Subject: [PATCH] chore(FE-41): use BaseApiService class --- src/services/api/master-data.ts | 89 ++------------------------------- 1 file changed, 4 insertions(+), 85 deletions(-) diff --git a/src/services/api/master-data.ts b/src/services/api/master-data.ts index e1748c59..25bceae0 100644 --- a/src/services/api/master-data.ts +++ b/src/services/api/master-data.ts @@ -1,6 +1,4 @@ -import axios from 'axios'; -import { httpClient, httpClientFetcher } from '@/services/http/client'; -import { BaseApiResponse } from '@/types/api/api-general'; +import { BaseApiService } from '@/services/api/base'; import { CreateUomPayload, Uom, @@ -17,98 +15,19 @@ import { UpdateLocationPayload, } from '@/types/api/master-data/location'; -export class MasterDataApi { - basePath: string; - - constructor(basePath: string) { - this.basePath = basePath; - } - - async getAllFetcher(endpoint: string): Promise> { - return await httpClientFetcher>(endpoint); - } - - async getSingle(id: number) { - try { - const getSinglePath = `${this.basePath}/${id}`; - const getSingleRes = await httpClient>(getSinglePath); - - return getSingleRes; - } catch (error) { - if (axios.isAxiosError>(error)) { - return error.response?.data; - } - - return undefined; - } - } - - async create(payload: CreatePayloadGeneric) { - try { - const createRes = await httpClient>(this.basePath, { - method: 'POST', - body: payload, - }); - - return createRes; - } catch (error: unknown) { - if (axios.isAxiosError>(error)) { - return error.response?.data; - } - - return undefined; - } - } - - async update(id: number, payload: UpdatePayloadGeneric) { - try { - const updatePath = `${this.basePath}/${id}`; - const updateRes = await httpClient>(updatePath, { - method: 'PATCH', - body: payload, - }); - - return updateRes; - } catch (error: unknown) { - if (axios.isAxiosError>(error)) { - return error.response?.data; - } - - return undefined; - } - } - - async delete(id: number) { - try { - const deletePath = `${this.basePath}/${id}`; - const deleteRes = await httpClient(deletePath, { - method: 'DELETE', - }); - - return deleteRes; - } catch (error) { - if (axios.isAxiosError(error)) { - return error.response?.data; - } - - return undefined; - } - } -} - -export const UomApi = new MasterDataApi< +export const UomApi = new BaseApiService< Uom, CreateUomPayload, UpdateUomPayload >('/master-data/uoms'); -export const AreaApi = new MasterDataApi< +export const AreaApi = new BaseApiService< Area, CreateAreaPayload, UpdateAreaPayload >('/master-data/areas'); -export const LocationApi = new MasterDataApi< +export const LocationApi = new BaseApiService< Location, CreateLocationPayload, UpdateLocationPayload