exposes errors, fixes bug with globals and localization
This commit is contained in:
5
errors.js
Normal file
5
errors.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const { APIError } = require('./src/errors');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
APIError,
|
||||||
|
};
|
||||||
@@ -6,20 +6,26 @@ const localizationPlugin = require('../localization/plugin');
|
|||||||
|
|
||||||
const buildModel = (config) => {
|
const buildModel = (config) => {
|
||||||
if (config.globals && config.globals.length > 0) {
|
if (config.globals && config.globals.length > 0) {
|
||||||
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true })
|
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true });
|
||||||
.plugin(localizationPlugin, config.localization)
|
|
||||||
.plugin(autopopulate)
|
if (config.localization) {
|
||||||
.plugin(mongooseHidden);
|
globalsSchema.plugin(localizationPlugin, config.localization);
|
||||||
|
}
|
||||||
|
|
||||||
|
globalsSchema.plugin(autopopulate);
|
||||||
|
globalsSchema.plugin(mongooseHidden);
|
||||||
|
|
||||||
const Globals = mongoose.model('globals', globalsSchema);
|
const Globals = mongoose.model('globals', globalsSchema);
|
||||||
|
|
||||||
Object.values(config.globals).forEach((globalConfig) => {
|
Object.values(config.globals).forEach((globalConfig) => {
|
||||||
const globalSchema = buildSchema(globalConfig.fields);
|
const globalSchema = buildSchema(globalConfig.fields);
|
||||||
|
|
||||||
globalSchema
|
if (config.localization) {
|
||||||
.plugin(localizationPlugin, config.localization)
|
globalSchema.plugin(localizationPlugin, config.localization);
|
||||||
.plugin(autopopulate)
|
}
|
||||||
.plugin(mongooseHidden);
|
|
||||||
|
globalSchema.plugin(autopopulate);
|
||||||
|
globalSchema.plugin(mongooseHidden);
|
||||||
|
|
||||||
Globals.discriminator(globalConfig.slug, globalSchema);
|
Globals.discriminator(globalConfig.slug, globalSchema);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user