lrf 2 rokov pred
rodič
commit
dcf6649ec6
1 zmenil súbory, kde vykonal 17 pridanie a 0 odobranie
  1. 17 0
      app/service/util/install.js

+ 17 - 0
app/service/util/install.js

@@ -17,6 +17,23 @@ class InstallService extends CrudService {
     await this.initAdmin();
     await this.initSelfShop();
     await this.initTestCustomer();
+    await this.initGoodsTags();
+  }
+
+  async initGoodsTags() {
+    const model = this.ctx.model.System.GoodsTags;
+    const p = path.resolve(this.dataIndex, 'goodsTags.js');
+    const data = require(p);
+    const loop = async (list, pid) => {
+      for (const i of list) {
+        const { children = [], label, code } = i;
+        let pdata;
+        pdata = await model.findOne({ code });
+        if (!pdata) pdata = await model.create({ label, code, pid });
+        if (children.length > 0) loop(children, pdata._id);
+      }
+    };
+    await loop(data);
   }
 
   /**