compose-payload.js
1.14 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
const paramsIsArray = (methodName, params) => `<?xml version="1.0"?>
<methodCall>
<methodName>${methodName}</methodName>
<params>
<param>
<value>
<struct>
${(params || []).map((param) => `
<member>
<name>${param.name}</name>
<value><${param.type || 'string'}>${param.value}</${param.type || 'string'}></value>
</member>
`).join('')}
</struct>
</value>
</param>
</params>
</methodCall>`;
const paramsIsNotArray = (methodName, params) => {
const paramsInArray = [];
// eslint-disable-next-line no-restricted-syntax
for (const [keyword, value] of Object.entries(params)) {
paramsInArray.push({
name: keyword,
value: (typeof value === 'object' && value.value) || value,
type: value.type || 'string',
});
}
return paramsIsArray(methodName, paramsInArray);
};
module.exports = (methodName, params) => (
Array.isArray(params)
? paramsIsArray(methodName, params)
: paramsIsNotArray(methodName, params)
);