2024-03-19 12:54:10 +00:00
|
|
|
import type {DataProvider, UpdateParams, UpdateResponse, HttpError} from "@refinedev/core";
|
2024-03-19 11:20:11 +00:00
|
|
|
import {SdkProvider} from "~/data/sdk-provider.js";
|
|
|
|
|
2024-03-19 12:54:10 +00:00
|
|
|
type AccountParams = {
|
|
|
|
email?: string;
|
|
|
|
password?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountData = AccountParams;
|
|
|
|
|
2024-03-19 11:20:11 +00:00
|
|
|
export const accountProvider: SdkProvider = {
|
2024-03-19 12:54:10 +00:00
|
|
|
getList: () => {
|
2024-03-19 22:47:33 +00:00
|
|
|
console.log("Not implemented");
|
|
|
|
return Promise.resolve({
|
|
|
|
data: [],
|
|
|
|
});
|
2024-03-19 12:54:10 +00:00
|
|
|
},
|
|
|
|
getOne: () => {
|
2024-03-19 22:47:33 +00:00
|
|
|
console.log("Not implemented");
|
|
|
|
return Promise.resolve({
|
|
|
|
data: {},
|
|
|
|
});
|
2024-03-19 12:54:10 +00:00
|
|
|
},
|
|
|
|
// @ts-ignore
|
|
|
|
async update<TVariables extends AccountParams = AccountParams>(
|
|
|
|
params: UpdateParams<AccountParams>,
|
|
|
|
): Promise<UpdateResponse<AccountData>> {
|
|
|
|
if (params.variables.email && params.variables.password) {
|
2024-03-19 13:12:21 +00:00
|
|
|
const ret = await accountProvider.sdk?.account().updateEmail(params.variables.email, params.variables.password);
|
2024-03-19 12:54:10 +00:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
if (ret instanceof Error) {
|
2024-03-20 20:08:40 +00:00
|
|
|
return Promise.reject(ret satisfies HttpError)
|
2024-03-19 12:54:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
data:
|
|
|
|
{
|
|
|
|
email: params.variables.email,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return an empty response if params.variables is undefined
|
|
|
|
return {
|
|
|
|
data: {} as AccountParams,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
create: () => {
|
2024-03-19 22:47:33 +00:00
|
|
|
console.log("Not implemented");
|
|
|
|
return Promise.resolve({
|
|
|
|
data: {},
|
|
|
|
});
|
2024-03-19 12:54:10 +00:00
|
|
|
},
|
|
|
|
deleteOne: () => {
|
2024-03-19 22:47:33 +00:00
|
|
|
console.log("Not implemented");
|
|
|
|
return Promise.resolve({
|
|
|
|
data: {},
|
|
|
|
});
|
2024-03-19 12:54:10 +00:00
|
|
|
},
|
|
|
|
getApiUrl: () => "",
|
2024-03-19 11:20:11 +00:00
|
|
|
}
|