2021-06-07 14:40:51 +03:00
|
|
|
const { Op } = require('sequelize');
|
|
|
|
const Config = require('../models/Config');
|
|
|
|
|
|
|
|
const initConfig = async () => {
|
|
|
|
// Config keys
|
2021-06-09 01:59:39 +03:00
|
|
|
const keys = ['WEATHER_API_KEY', 'lat', 'long', 'isCelsius', 'customTitle'];
|
|
|
|
const values = ['', 0, 0, true, 'Flame'];
|
2021-06-07 14:40:51 +03:00
|
|
|
|
|
|
|
// Get config values
|
|
|
|
const configPairs = await Config.findAll({
|
|
|
|
where: {
|
|
|
|
key: {
|
|
|
|
[Op.or]: keys
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Get key from each pair
|
|
|
|
const configKeys = configPairs.map((pair) => pair.key);
|
|
|
|
|
|
|
|
// Create missing pairs
|
|
|
|
keys.forEach(async (key, idx) => {
|
|
|
|
if (!configKeys.includes(key)) {
|
|
|
|
await Config.create({
|
|
|
|
key,
|
|
|
|
value: values[idx],
|
|
|
|
valueType: typeof values[idx]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log('Initial config created');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = initConfig;
|