-
Hello, I'm using Refine in my new project. However, I've encountered the following problem. export const resources = [
{
name: 'users',
list: '/users',
},
{
name: 'company-managements/companies',
list: '/company-managements/companies',
},
{
name: '/company-managements/companies/:companyId/departments',
list: '/company-managements/companies/:companyId/departments',
},
]; import { DataProvider } from '@refinedev/core';
import { createApi } from '@/lib/api/axios';
import { ApiResponse } from '@/types/common/api';
export const dataProvider = (url: string): DataProvider => {
const api = createApi();
return {
getList: async ({ resource, meta }) => {
if (resource === 'departments') {
const response = await api.get<ApiResponse<any[]>>(
`${url}/company-managements/companies/${meta?.companyId}/${resource}`
);
const { data } = response.data;
return {
data,
total: data.length,
};
}
const response = await api.get<ApiResponse<any[]>>(`${url}/${resource}`);
const { data } = response.data;
return {
data,
total: data.length,
};
},
getOne: async ({ resource, id }) => {
const response = await api.get<ApiResponse<any>>(
`${url}/${resource}/${id}`
);
return {
data: response.data.data,
};
},
getMany: async ({ resource, ids }) => {
const response = await api.get<ApiResponse<any[]>>(`${url}/${resource}`, {
params: { ids },
});
return {
data: response.data.data,
};
},
create: async ({ resource, variables }) => {
const response = await api.post<ApiResponse<any>>(
`${url}/${resource}`,
variables
);
return {
data: response.data.data,
};
},
update: async () => {
throw new Error('Not implemented');
},
deleteOne: async ({ resource, id }) => {
const response = await api.delete<ApiResponse<any>>(
`${url}/${resource}/${id}`
);
return {
data: response.data.data,
};
},
getApiUrl: () => url,
};
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @ms-bang, resource object also accepts
Then in your data provider, |
Beta Was this translation helpful? Give feedback.
Hello @ms-bang, resource object also accepts
parent
field, you can utilize that one.