-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
user.ts
65 lines (54 loc) 路 1.52 KB
/
user.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { AxiosInstance } from "axios";
import { UUID } from "crypto";
import { UserStats } from "@/lib/types/User";
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",
}
export type UserIdentityUpdatableProperties = {
username: string;
company?: string;
onboarded: boolean;
company_size?: CompanySize;
usage_purpose?: UsagePurpose;
};
export type UserIdentity = {
id: UUID;
onboarded: boolean;
username: string;
};
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;
};
export const getUser = async (
axiosInstance: AxiosInstance
): Promise<UserStats> => (await axiosInstance.get<UserStats>("/user")).data;
export const deleteUserData = async (
axiosInstance: AxiosInstance
): Promise<void> => {
await axiosInstance.delete(`/user_data`);
};
export const getUserCredits = async (
axiosInstance: AxiosInstance
): Promise<number> => (await axiosInstance.get<number>("/user/credits")).data;