mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-19 16:21:48 +03:00
33 lines
712 B
JavaScript
33 lines
712 B
JavaScript
const { Op } = require('sequelize');
|
|
const Config = require('../models/Config');
|
|
const { config } = require('./initialConfig.json');
|
|
|
|
const initConfig = async () => {
|
|
// Get config values
|
|
const configPairs = await Config.findAll({
|
|
where: {
|
|
key: {
|
|
[Op.or]: config.map(pair => pair.key)
|
|
}
|
|
}
|
|
})
|
|
|
|
// Get key from each pair
|
|
const configKeys = configPairs.map((pair) => pair.key);
|
|
|
|
// Create missing pairs
|
|
config.forEach(async ({ key, value}) => {
|
|
if (!configKeys.includes(key)) {
|
|
await Config.create({
|
|
key,
|
|
value,
|
|
valueType: typeof value
|
|
})
|
|
}
|
|
})
|
|
|
|
console.log('Initial config created');
|
|
return;
|
|
}
|
|
|
|
module.exports = initConfig; |