-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathreport-published.js
52 lines (42 loc) · 1.62 KB
/
report-published.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
const fs = require('fs')
const fetch = require('node-fetch')
const devBuild = (process.env.NODE_ENV || '').trim().toLowerCase() !== 'production'
const apiRoot = devBuild ? 'http://localhost:5000/v2' : 'https://api.vlctechhub.org/v2'
fs.readFile('dist/.events-published.json', async (err, data) => {
try {
if (err) throw err
const publishedEvents = JSON.parse(data).map(event => ({ id: event.id }))
const response = await fetch(`${apiRoot}/events/posted`, {
method: 'patch',
headers: { 'Content-type': 'application/json', Accept: 'application/json', 'Accept-Charset': 'utf-8' },
body: JSON.stringify({ events: publishedEvents })
})
if (response.status !== 204) {
console.error(`Invalid response status ${response.status}.`)
const json = await response.json()
throw json.error
}
console.log('Events have been succesfully reported.')
} catch (err) {
console.error(err)
}
})
fs.readFile('dist/.jobs-published.json', async (err, data) => {
try {
if (err) throw err
const publishedJobs = JSON.parse(data).map(job => ({ id: job.id }))
const response = await fetch(`${apiRoot}/jobs/posted`, {
method: 'patch',
headers: { 'Content-type': 'application/json', Accept: 'application/json', 'Accept-Charset': 'utf-8' },
body: JSON.stringify({ jobs: publishedJobs })
})
if (response.status !== 204) {
console.error(`Invalid response status ${response.status}.`)
const json = await response.json()
throw json.error
}
console.log('Job offers have been succesfully reported.')
} catch (err) {
console.error(err)
}
})