initialize settings in an init file before app accepts requests

This commit is contained in:
Riley Davis
2016-11-10 13:02:52 -07:00
parent 26f48196d9
commit c698ae78a7
3 changed files with 33 additions and 15 deletions
+8
View File
@@ -11,6 +11,14 @@ const SettingSchema = new Schema({
}
});
/**
* this is run once when the app starts to ensure settings are populated
* @return {Promise} null initialize the global settings object
*/
SettingSchema.statics.init = function (defaults) {
return this.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true});
};
/**
* gets the entire settings record and sends it back
* @return {Promise} settings the whole settings record