-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompany.ts
More file actions
102 lines (96 loc) · 3.45 KB
/
company.ts
File metadata and controls
102 lines (96 loc) · 3.45 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {
Company,
CompanyHasDataResponse,
CreateCompanyRequest,
GetClaimInProgressForCompanyResponse,
GetCompanyLocationsResponse,
UpdateCompanyRequest,
UpdateCompanyResponse,
} from "@/types/company";
import { authHeader, clientAuthWrapper, getClient } from "./client";
export const createCompany = async (payload: CreateCompanyRequest): Promise<Company> => {
const req = async (token: string): Promise<Company> => {
const client = getClient();
const { data, error, response } = await client.POST("/companies", {
headers: authHeader(token),
body: payload,
});
if (response.ok) {
return data!;
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<Company>()(req);
};
export const getCompanyLocations = async (): Promise<GetCompanyLocationsResponse> => {
const req = async (token: string): Promise<GetCompanyLocationsResponse> => {
const client = getClient();
const { data, error, response } = await client.GET("/companies/location-address", {
headers: authHeader(token),
});
if (response.ok) {
return data!;
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<GetCompanyLocationsResponse>()(req);
};
export const getCompany = async (): Promise<Company> => {
const req = async (token: string): Promise<Company> => {
const client = getClient();
const { data, error, response } = await client.GET("/companies", {
headers: authHeader(token),
});
if (response.ok) {
return data!;
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<Company>()(req);
};
export const getClaimInProgress = async (): Promise<GetClaimInProgressForCompanyResponse> => {
const req = async (token: string): Promise<GetClaimInProgressForCompanyResponse> => {
const client = getClient();
const { data, error, response } = await client.GET("/companies/claim-in-progress", {
headers: authHeader(token),
});
if (response.ok) {
return data!;
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<GetClaimInProgressForCompanyResponse>()(req);
};
export const companyHasData = async (): Promise<CompanyHasDataResponse> => {
const req = async (token: string): Promise<CompanyHasDataResponse> => {
const client = getClient();
const { data, error, response } = await client.GET("/companies/has-company-data", {
headers: authHeader(token),
});
if (response.ok) {
return data ?? { hasExternalData: false, hasFinancialData: false };
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<CompanyHasDataResponse>()(req);
};
export const updateCompany = async (payload: UpdateCompanyRequest): Promise<UpdateCompanyResponse> => {
const req = async (token: string): Promise<UpdateCompanyResponse> => {
const client = getClient();
const { data, error, response } = await client.PATCH("/companies", {
headers: authHeader(token),
body: payload,
});
if (response.ok) {
return data!;
} else {
throw Error(error?.error);
}
};
return clientAuthWrapper<UpdateCompanyResponse>()(req);
};