-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupload-tickets.js
41 lines (34 loc) · 1.1 KB
/
upload-tickets.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
const fetch = require('node-fetch')
const fs = require('fs')
async function uploadTickets(env, password) {
// set-up the API URL
let url
if (env === 'testing') {
url = 'http://localhost:3333'
}
else {
url = `https://${ env === 'staging' ? 'staging.' : '' }2021.cascadiajs.com`
}
// read the proper file
let ticketsData = JSON.parse(fs.readFileSync(`./data/${ env }/tickets.json`).toString())
// log-in
const params = new URLSearchParams()
params.append('password', password)
let login = await fetch(`${url}/login`, {method: 'POST', body: params, redirect: 'manual'})
// get the session cookie
let cookie = login.headers.get('set-cookie')
// upload the speakers
let tickets = await fetch(`${url}/tickets`, {
method: 'POST',
headers: {cookie, 'Content-Type': 'application/json'},
body: JSON.stringify(ticketsData),
})
const result = await tickets.json()
console.log(result)
}
function main() {
let env = process.argv[2]
let password = process.argv[3]
uploadTickets(env, password)
}
main()