task-b complate
This commit is contained in:
1
src/features/foundation/master-options/api/mutations.ts
Normal file
1
src/features/foundation/master-options/api/mutations.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
14
src/features/foundation/master-options/api/queries.ts
Normal file
14
src/features/foundation/master-options/api/queries.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { queryOptions } from '@tanstack/react-query';
|
||||
import { getMasterOptions } from './service';
|
||||
import type { MasterOptionsFilters } from './types';
|
||||
|
||||
export const masterOptionKeys = {
|
||||
all: ['foundation', 'master-options'] as const,
|
||||
list: (filters: MasterOptionsFilters) => [...masterOptionKeys.all, 'list', filters] as const
|
||||
};
|
||||
|
||||
export const masterOptionsQueryOptions = (filters: MasterOptionsFilters) =>
|
||||
queryOptions({
|
||||
queryKey: masterOptionKeys.list(filters),
|
||||
queryFn: () => getMasterOptions(filters)
|
||||
});
|
||||
18
src/features/foundation/master-options/api/service.ts
Normal file
18
src/features/foundation/master-options/api/service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
import type { MasterOptionsFilters, MasterOptionsResponse } from './types';
|
||||
|
||||
export async function getMasterOptions(
|
||||
filters: MasterOptionsFilters
|
||||
): Promise<MasterOptionsResponse> {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
if (filters.page) searchParams.set('page', String(filters.page));
|
||||
if (filters.limit) searchParams.set('limit', String(filters.limit));
|
||||
if (filters.search) searchParams.set('search', filters.search);
|
||||
if (filters.category) searchParams.set('category', filters.category);
|
||||
if (filters.sort) searchParams.set('sort', filters.sort);
|
||||
|
||||
const query = searchParams.toString();
|
||||
|
||||
return apiClient<MasterOptionsResponse>(`/foundation/master-options${query ? `?${query}` : ''}`);
|
||||
}
|
||||
32
src/features/foundation/master-options/api/types.ts
Normal file
32
src/features/foundation/master-options/api/types.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export interface MasterOptionItem {
|
||||
id: string;
|
||||
organization_id: string;
|
||||
category: string;
|
||||
code: string;
|
||||
label: string;
|
||||
value: string | null;
|
||||
parent_id: string | null;
|
||||
parent_label: string | null;
|
||||
sort_order: number;
|
||||
is_active: boolean;
|
||||
deleted_at: string | null;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface MasterOptionsFilters {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
search?: string;
|
||||
category?: string;
|
||||
sort?: string;
|
||||
}
|
||||
|
||||
export interface MasterOptionsResponse {
|
||||
success: boolean;
|
||||
time: string;
|
||||
message: string;
|
||||
total_items: number;
|
||||
offset: number;
|
||||
limit: number;
|
||||
items: MasterOptionItem[];
|
||||
}
|
||||
Reference in New Issue
Block a user