This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
generated from x-govuk/nhsuk-prototype-rig-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-data.js
49 lines (42 loc) · 1.74 KB
/
create-data.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
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import _ from 'lodash'
import { faker } from '@faker-js/faker'
import getParticipant from './app/fakers/participant.js'
import schoolsSeed from './app/fakers/seeds/schools.json' assert { type: 'json'}
import getSession from './app/fakers/session.js'
import getSessionInProgress from './app/fakers/session-in-progress.js'
import getUser from './app/fakers/user.js'
import getVaccines from './app/fakers/vaccines.js'
// Participants
const participants = faker.helpers.multiple(getParticipant, { count: 50 })
// Schools
const schools = _.keyBy(schoolsSeed, 'urn')
// Sessions
const sessionsArray = faker.helpers.multiple(getSession, { count: 20 })
sessionsArray.push(getSessionInProgress('Flu'))
sessionsArray.push(getSessionInProgress('HPV'))
const sessions = _.keyBy(_.sortBy(sessionsArray, ['date']), 'id')
// Users
const usersArray = faker.helpers.multiple(getUser, { count: 20 })
const users = _.keyBy(usersArray, 'id')
// Vaccines
const vaccinesArray = getVaccines()
const vaccines = _.keyBy(vaccinesArray, 'id')
const generateDataFile = async (outputPath, data) => {
try {
const fileDir = path.join(import.meta.url, '..', path.dirname(outputPath))
await fs.mkdir(fileURLToPath(fileDir), { recursive: true })
const fileData = JSON.stringify(data, null, 2)
await fs.writeFile(outputPath, fileData)
console.log(`Data file generated: ${outputPath}`)
} catch (error) {
console.error(error)
}
}
generateDataFile('.data/schools.json', schools)
generateDataFile('.data/sessions.json', sessions)
generateDataFile('.data/participants.json', participants)
generateDataFile('.data/users.json', users)
generateDataFile('.data/vaccines.json', vaccines)