forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll-creation.js
51 lines (49 loc) · 1.38 KB
/
poll-creation.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
export async function pollCreation(idUser, poll) {
if (typeof poll !== 'object') {
return WAPI.scope(idUser, true, 404, 'poll must be an object');
}
if (!poll?.name) {
return WAPI.scope(idUser, true, 404, 'Missing object name');
}
if (!poll?.options) {
return WAPI.scope(idUser, true, 404, 'Missing object options');
}
if (
typeof poll.selectableOptionsCount !== 'number' ||
(poll.selectableOptionsCount !== 1 && poll.selectableOptionsCount !== 0)
) {
return WAPI.scope(
idUser,
true,
404,
'Error checking selectableOptionsCount!'
);
}
const options = poll.options;
if (Array.isArray(options) && options.length > 0) {
for (let index in options) {
if (typeof options[index] !== 'function') {
if (!options[index].name) {
return WAPI.scope(idUser, true, 404, 'Missing object name');
}
if (typeof options[index].name !== 'string') {
return WAPI.scope(idUser, true, 404, 'Passed string value in name');
}
}
}
}
const chat = await WAPI.sendExist(idUser);
if (chat && chat.status !== 404 && chat.id) {
await Store.Survey.sendPollCreation({
chat: chat,
poll: poll,
quotedMsg: null
});
return { error: false, lastReceivedKey: chat.lastReceivedKey };
} else {
if (!chat.error) {
chat.error = true;
}
return chat;
}
}