mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 13:02:50 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { baseApi } from '@ema-platform/api';
|
|
|
|
export interface Item {
|
|
id: string;
|
|
name: string;
|
|
description: string | null;
|
|
status: 'DRAFT' | 'ACTIVE' | 'ARCHIVED';
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface PaginatedResponse<T> {
|
|
data: T[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
}
|
|
|
|
const itemApi = baseApi.injectEndpoints({
|
|
endpoints: (builder) => ({
|
|
getItems: builder.query<PaginatedResponse<Item>, { page?: number; limit?: number }>({
|
|
query: ({ page = 1, limit = 20 } = {}) => ({
|
|
url: '/items',
|
|
params: { page, limit },
|
|
}),
|
|
providesTags: ['Api'],
|
|
}),
|
|
createItem: builder.mutation<Item, { name: string; description?: string }>({
|
|
query: (body) => ({ url: '/items', method: 'POST', body }),
|
|
invalidatesTags: ['Api'],
|
|
}),
|
|
deleteItem: builder.mutation<void, string>({
|
|
query: (id) => ({ url: `/items/${id}`, method: 'DELETE' }),
|
|
invalidatesTags: ['Api'],
|
|
}),
|
|
}),
|
|
overrideExisting: false,
|
|
});
|
|
|
|
export const { useGetItemsQuery, useCreateItemMutation, useDeleteItemMutation } = itemApi;
|