-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathAddCountriesJob.ts
More file actions
24 lines (20 loc) · 764 Bytes
/
AddCountriesJob.ts
File metadata and controls
24 lines (20 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import enJson from 'i18n-iso-countries/langs/en.json' assert { type: 'json' }
import { connectDB, gracefulExit } from '../../index.js'
import MutableAreaDataSource from '../../../model/MutableAreaDataSource.js'
import { logger } from '../../../logger.js'
const onConnected = async (): Promise<void> => {
logger.info('Adding all countries (except USA)')
logger.info('For USA run: `yarn seed-usa`')
await insertAllCountries()
await gracefulExit()
}
const insertAllCountries = async (): Promise<void> => {
const areaDS = MutableAreaDataSource.getInstance()
await Promise.all(
Object.keys(enJson.countries).map(async code => {
if (code === 'US') return null
return await areaDS.addCountry(code)
})
)
}
void connectDB(onConnected)