This repository was archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgenerateVouchers.js
59 lines (52 loc) · 1.54 KB
/
generateVouchers.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
//
// This script fixes the counter gap by inserting 40 memberships
// owned by Project R Genossenschaft
//
// usage
// cf_server node script/fixGap.js
//
require('dotenv').config()
const PgDb = require('../lib/pgdb')
const ABO_PRICE = 24000
PgDb.connect().then(async (pgdb) => {
const numVouchers = process.argv[2]
if (!numVouchers) {
throw new Error('number if vouchers is required as first argument')
}
// gather data
const pkg = await pgdb.public.packages.findOne({name: 'ABO'})
const pkgOption = await pgdb.public.packageOptions.findOne({packageId: pkg.id})
const membershipType = await pgdb.public.membershipTypes.findOne({name: 'ABO'})
const user = await pgdb.public.users.findOne({email: 'jefferson@project-r.construction'})
if (!user) {
console.error('jefferson not found')
}
const pledge = await pgdb.public.pledges.insertAndGet({
packageId: pkg.id,
userId: user.id,
status: 'SUCCESSFUL',
total: ABO_PRICE * numVouchers,
donation: 0,
sendConfirmMail: false
})
await pgdb.public.pledgeOptions.insert({
templateId: pkgOption.id,
pledgeId: pledge.id,
amount: numVouchers,
price: ABO_PRICE
})
for (let counter = 0; counter < numVouchers; counter++) {
await pgdb.public.memberships.insert({
userId: user.id,
pledgeId: pledge.id,
membershipTypeId: membershipType.id,
beginDate: new Date()
})
}
console.log(`memberships: ${await pgdb.public.memberships.count()}`)
}).then(() => {
process.exit()
}).catch(e => {
console.error(e)
process.exit(1)
})