-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate.js
31 lines (30 loc) · 826 Bytes
/
create.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
const _ = require('lodash')
const { request } = require('./bin/utils')
module.exports = async function create(argv) {
const { auth, count, hostname, protocol, value, type, platform, walletIds } = argv
const shards = 4
const limit = value * shards === parseInt(value * shards) ? value : ((parseInt(value * shards) + 1) / shards)
const options = {
hostname,
protocol,
path: `/v1/promotions`,
method: 'POST',
headers: {
Authorization: 'Bearer ' + auth
},
body: {
type,
numGrants: type === 'ugp' ? count : walletIds.length,
value: limit,
platform,
active: true,
}
}
if (type === 'ugp') {
return request(options).then((res) => ([res]))
} else {
return Promise.all(Array(count).fill().map(() => {
return request(options)
}))
}
}