-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
68 lines (54 loc) · 1.87 KB
/
Copy pathapi.ts
File metadata and controls
68 lines (54 loc) · 1.87 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
import { useFetchClient } from '@strapi/strapi/admin';
const BASE = '/strapi-plugin-form-builder-cms';
export function useFormsApi() {
const { get, post, put, del } = useFetchClient();
return {
async getForms() {
const { data } = await get(`${BASE}/forms`);
return data;
},
async getForm(id: number) {
const { data } = await get(`${BASE}/forms/${id}`);
return data;
},
async createForm(body: any) {
const { data } = await post(`${BASE}/forms`, body);
return data;
},
async updateForm(id: number, body: any) {
const { data } = await put(`${BASE}/forms/${id}`, body);
return data;
},
async deleteForm(id: number) {
await del(`${BASE}/forms/${id}`);
},
async duplicateForm(id: number) {
const { data } = await post(`${BASE}/forms/${id}/duplicate`, {});
return data;
},
async getSubmissions(formId: number, query: Record<string, any> = {}) {
const params = new URLSearchParams(query as any).toString();
const { data } = await get(`${BASE}/submissions/${formId}${params ? `?${params}` : ''}`);
return data;
},
async getSubmission(id: number) {
const { data } = await get(`${BASE}/submissions/entry/${id}`);
return data;
},
async updateSubmissionStatus(id: number, status: string) {
const { data } = await put(`${BASE}/submissions/${id}/status`, { status });
return data;
},
async deleteSubmission(id: number) {
await del(`${BASE}/submissions/${id}`);
},
async getStats(formId: number) {
const { data } = await get(`${BASE}/submissions/${formId}/stats`);
return data;
},
async exportSubmissions(formId: number): Promise<string> {
const { data } = await get(`${BASE}/submissions/${formId}/export`);
return typeof data === 'string' ? data : String(data ?? '');
},
};
}