exposes errors, fixes bug with globals and localization

This commit is contained in:
James
2020-07-18 13:37:41 -04:00
parent d1820b0731
commit b6a90587e6
2 changed files with 19 additions and 8 deletions

5
errors.js Normal file
View File

@@ -0,0 +1,5 @@
const { APIError } = require('./src/errors');
module.exports = {
APIError,
};

View File

@@ -6,20 +6,26 @@ const localizationPlugin = require('../localization/plugin');
const buildModel = (config) => {
if (config.globals && config.globals.length > 0) {
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true })
.plugin(localizationPlugin, config.localization)
.plugin(autopopulate)
.plugin(mongooseHidden);
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true });
if (config.localization) {
globalsSchema.plugin(localizationPlugin, config.localization);
}
globalsSchema.plugin(autopopulate);
globalsSchema.plugin(mongooseHidden);
const Globals = mongoose.model('globals', globalsSchema);
Object.values(config.globals).forEach((globalConfig) => {
const globalSchema = buildSchema(globalConfig.fields);
globalSchema
.plugin(localizationPlugin, config.localization)
.plugin(autopopulate)
.plugin(mongooseHidden);
if (config.localization) {
globalSchema.plugin(localizationPlugin, config.localization);
}
globalSchema.plugin(autopopulate);
globalSchema.plugin(mongooseHidden);
Globals.discriminator(globalConfig.slug, globalSchema);
});