mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-23 13:29:35 +02:00
Changed initial files creation process
This commit is contained in:
parent
591824dd0c
commit
459523dfd2
9 changed files with 109 additions and 38 deletions
39
utils/init/initConfig.js
Normal file
39
utils/init/initConfig.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
const { Op } = require('sequelize');
|
||||
const Config = require('../../models/Config');
|
||||
const { config } = require('./initialConfig.json');
|
||||
|
||||
const Logger = require('../Logger');
|
||||
const logger = new Logger();
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
logger.log('Initial config created');
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
module.exports = initConfig;
|
Loading…
Add table
Add a link
Reference in a new issue