1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00

Added option to pin new apps/categories by default

This commit is contained in:
unknown 2021-06-09 10:58:45 +02:00
parent 43e110d378
commit 8b87ad92f1
5 changed files with 111 additions and 14 deletions

View file

@ -1,16 +1,13 @@
const { Op } = require('sequelize');
const Config = require('../models/Config');
const { config } = require('./initialConfig.json');
const initConfig = async () => {
// Config keys
const keys = ['WEATHER_API_KEY', 'lat', 'long', 'isCelsius', 'customTitle'];
const values = ['', 0, 0, true, 'Flame'];
// Get config values
const configPairs = await Config.findAll({
where: {
key: {
[Op.or]: keys
[Op.or]: config.map(pair => pair.key)
}
}
})
@ -19,12 +16,12 @@ const initConfig = async () => {
const configKeys = configPairs.map((pair) => pair.key);
// Create missing pairs
keys.forEach(async (key, idx) => {
config.forEach(async ({ key, value}) => {
if (!configKeys.includes(key)) {
await Config.create({
key,
value: values[idx],
valueType: typeof values[idx]
value,
valueType: typeof value
})
}
})

32
utils/initialConfig.json Normal file
View file

@ -0,0 +1,32 @@
{
"config": [
{
"key": "WEATHER_API_KEY",
"value": ""
},
{
"key": "lat",
"value": 0
},
{
"key": "long",
"value": 0
},
{
"key": "isCelsius",
"value": true
},
{
"key": "customTitle",
"value": "Flame"
},
{
"key": "pinAppsByDefault",
"value": true
},
{
"key": "pinCategoriesByDefault",
"value": true
}
]
}