-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscreener.ts
More file actions
199 lines (170 loc) · 5.23 KB
/
screener.ts
File metadata and controls
199 lines (170 loc) · 5.23 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { env } from "@/config/environment";
import { authDelete, authGet, authPatch, authPost } from "@/api/auth";
import type { BenefitDetail, FormPath, ScreenerResult } from "@/types";
const apiUrl = env.apiUrl;
export const fetchProjects = async () => {
const url = apiUrl + "/screeners";
try {
const response = await authGet(url);
if (!response.ok) {
throw new Error(`Fetch failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching projects:", error);
throw error; // rethrow so you can handle it in your component if needed
}
};
export const fetchProject = async (screenerId) => {
const url = apiUrl + "/screener/" + screenerId;
try {
const response = await authGet(url);
if (!response.ok) {
throw new Error(`Fetch failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching screener:", error);
throw error; // rethrow so you can handle it in your component if needed
}
};
export const createNewScreener = async (request: {
screenerName: string;
description?: string;
}) => {
const url = apiUrl + "/screener";
try {
const response = await authPost(url.toString(), request);
if (!response.ok) {
throw new Error(`Post failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error creating new project:", error);
throw error; // rethrow so you can handle it in your component if needed
}
};
export const updateScreener = async (
screenerId: string,
request: { screenerName: string },
) => {
const url = new URL(`${apiUrl}/screener/${screenerId}`);
try {
const response = await authPatch(url.toString(), request);
if (!response.ok) {
const err = await response.json();
throw new Error(err);
}
} catch (error) {
console.error("Error updating project:", error);
throw error;
}
};
export const deleteScreener = async (screenerData) => {
const url = apiUrl + "/screener/delete?screenerId=" + screenerData.id;
try {
const response = await authDelete(url);
if (!response.ok) {
throw new Error(`Update failed with status: ${response.status}`);
}
} catch (error) {
console.error("Error updating project:", error);
throw error;
}
};
export const saveFormSchema = async (screenerId: string, schema) => {
const requestData: any = {};
requestData.schema = schema;
const url = new URL(`${apiUrl}/save-form-schema`);
url.searchParams.append("screenerId", screenerId);
try {
const response = await authPost(url.toString(), requestData);
if (!response.ok) {
throw new Error(`Post failed with status: ${response.status}`);
}
} catch (error) {
console.error("Error saving form schema:", error);
throw error; // rethrow so you can handle it in your component if needed
}
};
export const publishScreener = async (screenerId: string): Promise<void> => {
const url = apiUrl + "/publish";
try {
const response = await authPost(url, { screenerId: screenerId });
if (!response.ok) {
throw new Error(`Submit failed with status: ${response.status}`);
}
} catch (error) {
console.error("Error submitting form:", error);
throw error;
}
};
export const addCustomBenefit = async (
screenerId: string,
benefit: BenefitDetail,
) => {
const url = apiUrl + "/screener/" + screenerId + "/benefit";
try {
const response = await authPost(url, benefit);
if (!response.ok) {
throw new Error(`Create benefit failed with status: ${response.status}`);
}
} catch (error) {
console.error("Error creating benefit:", error);
throw error;
}
};
export const removeCustomBenefit = async (
screenerId: string,
benefitId: string,
) => {
const url = apiUrl + "/screener/" + screenerId + "/benefit/" + benefitId;
try {
const response = await authDelete(url);
if (!response.ok) {
throw new Error(
`Delete of benefit failed with status: ${response.status}`,
);
}
} catch (error) {
console.error("Error deleting custom benefit:", error);
throw error;
}
};
export interface FormPathsResponse {
paths: FormPath[];
}
export const fetchFormPaths = async (screenerId: string): Promise<FormPathsResponse> => {
const url = apiUrl + "/screener/" + screenerId + "/form-paths";
try {
const response = await authGet(url);
if (!response.ok) {
throw new Error(`Fetch form paths failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching form paths:", error);
throw error;
}
};
export const evaluateScreener = async (
screenerId: string,
inputData: any,
): Promise<ScreenerResult> => {
const url = apiUrl + "/decision/v2?screenerId=" + screenerId;
try {
const response = await authPost(url, inputData);
if (!response.ok) {
throw new Error(`Evaluation failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error evaluating:", error);
throw error;
}
};