2023-08-01 10:24:57 +03:00
|
|
|
import { AxiosInstance } from "axios";
|
|
|
|
import { UUID } from "crypto";
|
|
|
|
|
2023-09-13 14:47:12 +03:00
|
|
|
import { UserStats } from "@/lib/types/User";
|
|
|
|
|
2024-03-21 22:10:54 +03:00
|
|
|
export enum CompanySize {
|
|
|
|
One = "1-10",
|
|
|
|
Two = "10-25",
|
|
|
|
Three = "25-50",
|
|
|
|
Four = "50-100",
|
|
|
|
Five = "100-500",
|
|
|
|
Six = "500-1000",
|
|
|
|
Seven = "1000-5000",
|
|
|
|
Eight = "+5000",
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum UsagePurpose {
|
|
|
|
Business = "Business",
|
|
|
|
NGO = "NGO",
|
|
|
|
Personal = "Personal",
|
|
|
|
Student = "Student",
|
|
|
|
Teacher = "Teacher",
|
|
|
|
}
|
|
|
|
|
2023-08-01 10:24:57 +03:00
|
|
|
export type UserIdentityUpdatableProperties = {
|
2024-03-21 22:10:54 +03:00
|
|
|
username: string;
|
|
|
|
company?: string;
|
|
|
|
onboarded: boolean;
|
|
|
|
company_size?: CompanySize;
|
|
|
|
usage_purpose?: UsagePurpose;
|
2023-08-01 10:24:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export type UserIdentity = {
|
2024-05-02 12:31:58 +03:00
|
|
|
id: UUID;
|
2024-03-21 22:10:54 +03:00
|
|
|
onboarded: boolean;
|
|
|
|
username: string;
|
2023-08-01 10:24:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const updateUserIdentity = async (
|
|
|
|
userUpdatableProperties: UserIdentityUpdatableProperties,
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<UserIdentity> =>
|
|
|
|
axiosInstance.put(`/user/identity`, userUpdatableProperties);
|
|
|
|
|
|
|
|
export const getUserIdentity = async (
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<UserIdentity> => {
|
|
|
|
const { data } = await axiosInstance.get<UserIdentity>(`/user/identity`);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|
2023-09-13 14:47:12 +03:00
|
|
|
|
|
|
|
export const getUser = async (
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<UserStats> => (await axiosInstance.get<UserStats>("/user")).data;
|
2024-04-27 14:44:48 +03:00
|
|
|
|
2024-05-02 12:31:58 +03:00
|
|
|
export const deleteUserData = async (
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<void> => {
|
|
|
|
await axiosInstance.delete(`/user_data`);
|
|
|
|
};
|
|
|
|
|
2024-04-27 14:44:48 +03:00
|
|
|
export const getUserCredits = async (
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<number> => (await axiosInstance.get<number>("/user/credits")).data;
|