Demo

RequestDto & ResponseDto

POST / PUT body များကို RequestDto ဖြင့် ထုပ်ပိုးပါ။ axios response.data ကို ResponseDto<T> အဖြစ် cast လုပ်ပြီး၊ GET fetchFn / list API များမှ payload ကို ပြန်ပေးရပါသည်။

RequestDto & ResponseDto

POST / PUT body များကို RequestDto ဖြင့် ထုပ်ပိုးပါ။ axios response.data ကို ResponseDto<T> အဖြစ် cast လုပ်ပြီး၊ GET fetchFn / list API များမှ payload ကို ပြန်ပေးရပါသည်။

  • Frontend ResponseDto သည် client အတွက် ရိုးရှင်းသော ပုံစံ (payload + status) ဖြစ်ပါသည်
  • List / detail fetchFn မှ payload ကို အမြဲပြန်ပေးပါ — call site တွင် data?.payload ကို မဖတ်ရပါ
TSXfeature.api.ts
1import { RequestDto, ResponseDto } from "@quan-erp/shared-frontend-core"; 2import { withApiMetadataFetchFn } from "@quan-erp/shared-types"; 3import { getAxiosClient } from "../../lib/axios"; 4import metadata from "../../../module.metadata.json" with { type: "json" }; 5 6const PLUGIN_PREFIX = `/${metadata.name}`; 7 8export const getItemsApi = withApiMetadataFetchFn({ 9 api: { method: "GET", url: `${PLUGIN_PREFIX}/items` }, 10 fetchFn: async (skip: number, limit: number): Promise<ItemDto[]> => { 11 const response = await getAxiosClient().get(`${PLUGIN_PREFIX}/items`, { 12 params: { skip, limit }, 13 }); 14 const data: ResponseDto<ItemDto[]> = response.data; 15 if (data.status === "error") throw new Error(data.message); 16 return data.payload; 17 }, 18}); 19 20export const createItemApi = withApiMetadataFetchFn({ 21 api: { method: "POST", url: `${PLUGIN_PREFIX}/items` }, 22 fetchFn: async (payload: CreateItemDto): Promise<ItemDto> => { 23 const response = await getAxiosClient().post( 24 `${PLUGIN_PREFIX}/items`, 25 new RequestDto(payload), 26 ); 27 const data: ResponseDto<ItemDto> = response.data; 28 if (data.status === "error") throw new Error(data.message); 29 return data.payload; 30 }, 31});