-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.js
163 lines (160 loc) · 3.23 KB
/
api.js
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
const axios = require('axios');
module.exports = ({ host, key }) => ({
async getDocuments() {
const { data } = await axios.get(`${host}/rest/menu/documents`, {
headers: {
Authorization: key
}
});
return data;
},
async getDocument(id) {
const { data } = await axios.get(`${host}/rest/menu/documents/${id}`, {
headers: {
Authorization: key
}
});
return data;
},
async getMenu(id) {
const { data } = await axios.get(`${host}/rest/menu/list`, {
headers: {
Authorization: key
}
});
return data;
},
async getSuggestions(document, field, search) {
const { data } = await axios.get(`${host}/rest/data/${document}/lookup/${field}`, {
headers: {
Authorization: key
},
params: {
page: 1,
start: 0,
limit: 10,
search
}
});
return data;
},
async getIdFromCode(document, code) {
const { data } = await axios.get(`${host}/rest/data/${document}/find`, {
headers: {
Authorization: key
},
params: {
limit: 1,
filter: { match: 'and', conditions: [{ term: 'code', operator: 'equals', value: Number(code) }] },
fields: '_id, _updatedAt'
}
});
if (data.success === true && data.total === 1) {
const {
data: [{ _id, _updatedAt }]
} = data;
return { _id, _updatedAt: { $date: _updatedAt } };
}
return {};
},
async getIdFromId(document, id) {
const { data } = await axios.get(`${host}/rest/data/${document}/${id}`, {
headers: {
Authorization: key
},
params: {
fields: '_id, _updatedAt'
}
});
if (data.success === true && data.total === 1) {
const {
data: [{ _id, _updatedAt }]
} = data;
return { _id, _updatedAt: { $date: _updatedAt } };
}
return {};
},
async update(document, ids, data) {
const { data: result } = await axios.put(
`${host}/rest/data/${document}`,
{
data,
ids
},
{
headers: {
Authorization: key
}
}
);
return result;
},
async create(document, body) {
const { data: result } = await axios.post(`${host}/rest/data/${document}`, body, {
headers: {
Authorization: key
}
});
return result;
},
async getSuggestionsForDocument(document, field, search) {
const { data } = await axios.get(`${host}/rest/data/${document}/find`, {
headers: {
Authorization: key
},
params: {
limit: 20,
filter: { match: 'and', conditions: [{ term: field, operator: 'contains', value: search }] },
fields: `_id, ${field}`,
sort: [{ property: field, direction: 'ASC' }]
}
});
return data;
},
async getNextOnQueue(queueId) {
const { data } = await axios.get(`${host}/rest/data/Queue/queue/next/${queueId}`, {
headers: {
Authorization: key
}
});
return data;
},
async createContact(contactData) {
const { data } = await axios.post(
`${host}/rest/process/submit`,
{
data: [
{
name: 'contact',
data: contactData
}
]
},
{
headers: {
Authorization: key
}
}
);
return data;
},
async createOpportunity(opportunityData) {
const { data } = await axios.post(
`${host}/rest/process/submit`,
{
data: [
{
name: 'opportunity',
data: opportunityData
}
]
},
{
headers: {
Authorization: key
}
}
);
return data;
}
});