- Create Newsletter Page: MailingList (without the class style, using Gulp tasks)#94
This commit is contained in:
79
src/server/models/settings.js
Normal file
79
src/server/models/settings.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const SettingsSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
key: {
|
||||
type: String,
|
||||
},
|
||||
type: {
|
||||
type: Number,
|
||||
},
|
||||
value_str: {
|
||||
type: String,
|
||||
},
|
||||
value_date: {
|
||||
type: Date,
|
||||
},
|
||||
value_num: {
|
||||
type: Number,
|
||||
}
|
||||
});
|
||||
|
||||
SettingsSchema.statics.getFieldsForSearch = function () {
|
||||
return ['key', 'value_str']
|
||||
};
|
||||
|
||||
SettingsSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
SettingsSchema.statics.getValDbSettings = function (idapp, key) {
|
||||
return Settings.findOne({ idapp, key })
|
||||
.then((myrec) => {
|
||||
console.log('getValDbSettings', myrec, 'idapp', idapp);
|
||||
if (myrec) {
|
||||
if (myrec.type === tools.FieldType.date)
|
||||
return myrec.value_date;
|
||||
if (myrec.type === tools.FieldType.number)
|
||||
return myrec.value_num;
|
||||
else
|
||||
return myrec.value_str;
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
console.error('getValDbSettings', err);
|
||||
return null;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
SettingsSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Settings = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return Settings.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
const Settings = mongoose.model('Settings', SettingsSchema);
|
||||
|
||||
module.exports = { Settings };
|
||||
Reference in New Issue
Block a user