Files
openpanel/packages/devtools-ui/src/utils/me.ts
Stefan Pejcic 09f9f9502d packages
2024-11-07 19:03:37 +01:00

68 lines
1.2 KiB
TypeScript

import { REFINE_API_URL } from "./constants";
import type {
MeResponse,
MeUpdateVariables,
RaffleResponse,
} from "src/interfaces/api";
export const getMe = async () => {
try {
const response = await fetch(`${REFINE_API_URL}/users/me`);
if (response.ok) {
const data = (await response.json()) as MeResponse;
return data;
}
return null;
} catch (_) {
//
}
return null;
};
export const updateMe = async (variables: MeUpdateVariables) => {
try {
const { status } = await fetch(`${REFINE_API_URL}/users/me`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(variables),
});
if (status === 200) {
return true;
}
} catch (_) {
//
}
return false;
};
export const raffle = async (): Promise<RaffleResponse> => {
try {
const response = await fetch(`${REFINE_API_URL}/users/me/raffle`);
const data = (await response.json()) as RaffleResponse;
return data;
} catch (_) {
//
}
return { raffle: false };
};
export const acknowledgeRaffle = async () => {
try {
await fetch(`${REFINE_API_URL}/users/me/raffle/acknowledge`);
} catch (_) {
//
}
};