-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathactionTransport.js
More file actions
44 lines (34 loc) · 1.01 KB
/
Copy pathactionTransport.js
File metadata and controls
44 lines (34 loc) · 1.01 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
import { executeAction } from '@/api/modules/module.js'
const extractExtend = (extend) => {
if (!extend) {
return undefined
}
if (typeof extend === 'object' && extend.ext !== undefined) {
return extend.ext
}
return extend
}
export const createActionPayload = ({ action, value, extend, apiUrl, extra = {} }) => {
const payload = {
action,
...extra
}
if (value !== undefined) {
payload.value = typeof value === 'object' ? JSON.stringify(value) : value
}
const normalizedExtend = extractExtend(extend)
if (normalizedExtend !== undefined && normalizedExtend !== null && normalizedExtend !== '') {
payload.extend = normalizedExtend
}
if (apiUrl) {
payload.apiUrl = apiUrl
}
return payload
}
export const callActionEndpoint = async ({ module, apiUrl, extend, action, value, extra }) => {
if (!module && !apiUrl) {
return null
}
const payload = createActionPayload({ action, value, extend, apiUrl, extra })
return executeAction(module || 'default', payload)
}