ts-ignore
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ResourceOverride } from "./utils/overrides";
|
import { ResourceOverride } from "./types/overrides";
|
||||||
|
|
||||||
export const configuration: Record<string, ResourceOverride> = {
|
export const configuration: Record<string, ResourceOverride> = {
|
||||||
expenses: {
|
expenses: {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export function useResource<T = any>(config: ResourceConfig) {
|
|||||||
useQuery({
|
useQuery({
|
||||||
queryKey: [name, "list", params],
|
queryKey: [name, "list", params],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
// @ts-ignore
|
||||||
const res = await api.get<T[]>(endpoint, { params });
|
const res = await api.get<T[]>(endpoint, { params });
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
@@ -22,6 +23,7 @@ export function useResource<T = any>(config: ResourceConfig) {
|
|||||||
queryKey: [name, "detail", id],
|
queryKey: [name, "detail", id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!id) return null;
|
if (!id) return null;
|
||||||
|
// @ts-ignore
|
||||||
const res = await api.get<T>(`${endpoint}/${id}`);
|
const res = await api.get<T>(`${endpoint}/${id}`);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
@@ -32,6 +34,7 @@ export function useResource<T = any>(config: ResourceConfig) {
|
|||||||
const useCreate = () =>
|
const useCreate = () =>
|
||||||
useMutation({
|
useMutation({
|
||||||
mutationFn: async (data: Partial<T>) => {
|
mutationFn: async (data: Partial<T>) => {
|
||||||
|
// @ts-ignore
|
||||||
const res = await api.post<T>(endpoint, data);
|
const res = await api.post<T>(endpoint, data);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
@@ -44,6 +47,7 @@ export function useResource<T = any>(config: ResourceConfig) {
|
|||||||
const useUpdate = () =>
|
const useUpdate = () =>
|
||||||
useMutation({
|
useMutation({
|
||||||
mutationFn: async ({ id, data }: { id: string; data: Partial<T> }) => {
|
mutationFn: async ({ id, data }: { id: string; data: Partial<T> }) => {
|
||||||
|
// @ts-ignore
|
||||||
const res = await api.put<T>(`${endpoint}/${id}`, data);
|
const res = await api.put<T>(`${endpoint}/${id}`, data);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
@@ -71,6 +75,7 @@ export function useResource<T = any>(config: ResourceConfig) {
|
|||||||
const getListQueryOptions = (params?: any) => ({
|
const getListQueryOptions = (params?: any) => ({
|
||||||
queryKey: [name, "list", params],
|
queryKey: [name, "list", params],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
// @ts-ignore
|
||||||
const res = await api.get<T[]>(endpoint, { params });
|
const res = await api.get<T[]>(endpoint, { params });
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ export async function loadConfigFromOpenApi(baseUrl: string): Promise<AppConfig>
|
|||||||
const listOp = paths[listPath]?.get;
|
const listOp = paths[listPath]?.get;
|
||||||
if (!listOp) continue;
|
if (!listOp) continue;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const responseSchema = listOp.responses?.["200"]?.content?.["application/json"]?.schema;
|
const responseSchema = listOp.responses?.["200"]?.content?.["application/json"]?.schema;
|
||||||
let schemaObj = responseSchema;
|
let schemaObj = responseSchema;
|
||||||
if (responseSchema?.type === "array" && responseSchema.items) {
|
if (responseSchema?.type === "array" && responseSchema.items) {
|
||||||
@@ -161,10 +162,13 @@ export async function loadConfigFromOpenApi(baseUrl: string): Promise<AppConfig>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const serverBaseUrl = import.meta.env.VITE_API_BASE_URL || (api.servers?.[0]?.url ?? "")
|
||||||
|
// @ts-ignore
|
||||||
|
const authBaseUrl = import.meta.env.VITE_AUTH_BASE_URL || ""
|
||||||
return {
|
return {
|
||||||
baseUrl:
|
baseUrl: serverBaseUrl,
|
||||||
import.meta.env.VITE_API_BASE_URL || (api.servers?.[0]?.url ?? ""),
|
authBaseUrl: authBaseUrl,
|
||||||
authBaseUrl: import.meta.env.VITE_AUTH_BASE_URL || "",
|
|
||||||
resources,
|
resources,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user