utsushiiro před 7 roky
rodič
revize
c00bab974a
1 změnil soubory, kde provedl 32 přidání a 0 odebrání
  1. 32 0
      src/server/service/config-manager.js

+ 32 - 0
src/server/service/config-manager.js

@@ -9,16 +9,30 @@ class ConfigManager {
     this.configObject = null;
     this.configObject = null;
   }
   }
 
 
+  /**
+   * load configs from the database and the environment variables
+   */
   async loadConfigs() {
   async loadConfigs() {
     this.configObject = await this.configLoader.load();
     this.configObject = await this.configLoader.load();
 
 
     debug('ConfigManager#loadConfigs', this.configObject);
     debug('ConfigManager#loadConfigs', this.configObject);
   }
   }
 
 
+  /**
+   * get a config specified by namespace & key
+   *
+   * Basically, search a specified config from configs loaded from database at first
+   * and then from configs loaded from env vars.
+   *
+   * In some case, this search method changes.(not yet implemented)
+   */
   getConfig(namespace, key) {
   getConfig(namespace, key) {
     return this.defaultSearch(namespace, key);
     return this.defaultSearch(namespace, key);
   }
   }
 
 
+  /**
+   * private api
+   */
   defaultSearch(namespace, key) {
   defaultSearch(namespace, key) {
     if (this.configObject.fromDB[namespace][key] !== undefined) {
     if (this.configObject.fromDB[namespace][key] !== undefined) {
       return this.configObject.fromDB[namespace][key];
       return this.configObject.fromDB[namespace][key];
@@ -28,6 +42,24 @@ class ConfigManager {
     }
     }
   }
   }
 
 
+  /**
+   * update configs by a iterable object consisting of several objects with ns, key, value fields
+   *
+   * For example:
+   * ```
+   *  updateConfigs(
+   *   [{
+   *     ns:    'some namespace 1',
+   *     key:   'some key 1',
+   *     value: 'some value 1'
+   *   }, {
+   *     ns:    'some namespace 2',
+   *     key:   'some key 2',
+   *     value: 'some value 2'
+   *   }]
+   *  );
+   * ```
+   */
   async updateConfigs(configs) {
   async updateConfigs(configs) {
     for (const config of configs) {
     for (const config of configs) {
       this.configModel.findOneAndUpdate(
       this.configModel.findOneAndUpdate(