1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- const path = require('path');
- //
- class InstallService extends CrudService {
- constructor(ctx) {
- super(ctx, 'install');
- this.dataIndex = path.resolve('app', 'public', 'defaultData');
- }
- async init() {
- await this.initDict();
- // await this.initSelfShop();
- // await this.initTestCustomer();
- // await this.initTestGoods();
- // await this.initServiceContact();
- }
- /**
- * 初始化字典
- */
- async initDict() {
- const indexModel = this.ctx.model.Dev.DictIndex;
- const dataModel = this.ctx.model.Dev.DictData;
- const p = path.resolve(this.dataIndex, 'dict.js');
- const data = require(p);
- for (const i of data) {
- const { children, ...others } = i;
- const num = await indexModel.count({ code: others.code });
- if (num > 0) continue;
- await indexModel.create(others);
- const newChildren = children.map(i => ({ ...i, code: others.code }));
- await dataModel.insertMany(newChildren);
- }
- }
- }
- module.exports = InstallService;
|