models initialization refactored, better dev experience as backend hmr is working

This commit is contained in:
lesion
2022-12-23 01:08:14 +01:00
parent 380eaa87ca
commit cbed0288fe
43 changed files with 624 additions and 707 deletions

View File

@@ -1,6 +1,5 @@
const path = require('path')
const URL = require('url')
const fs = require('fs')
const crypto = require('crypto')
const { promisify } = require('util')
const sharp = require('sharp')
@@ -9,7 +8,7 @@ const generateKeyPair = promisify(crypto.generateKeyPair)
const log = require('../../log')
// const locales = require('../../../locales/index')
const escape = require('lodash/escape')
const pluginController = require('./plugins')
const DB = require('../models/models')
let defaultHostname
try {
@@ -30,7 +29,7 @@ const defaultSettings = {
allow_multidate_event: true,
allow_recurrent_event: false,
recurrent_event_visible: false,
allow_geolocation: true,
allow_geolocation: false,
geocoding_provider_type: 'Nominatim',
geocoding_provider: 'https://nominatim.openstreetmap.org/search',
geocoding_countrycodes: [],
@@ -74,8 +73,7 @@ const settingsController = {
// initialize instance settings from db
// note that this is done only once when the server starts
// and not for each request
const Setting = require('../models/setting')
const settings = await Setting.findAll()
const settings = await DB.Setting.findAll()
settingsController.settings = defaultSettings
settings.forEach(s => {
if (s.is_secret) {
@@ -117,15 +115,14 @@ const settingsController = {
// }
// })
// }
const pluginController = require('./plugins')
pluginController._load()
},
async set (key, value, is_secret = false) {
const Setting = require('../models/setting')
log.info(`SET ${key} ${is_secret ? '*****' : value}`)
try {
const [setting, created] = await Setting.findOrCreate({
const [setting, created] = await DB.Setting.findOrCreate({
where: { key },
defaults: { value, is_secret }
})