util.js 970 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class UtilService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx);
  10. this.mq = this.ctx.mq;
  11. }
  12. async findModel({ model }) {
  13. const _model = _.capitalize(model);
  14. const data = this.ctx.model[_model].prototype.schema.obj;
  15. const keys = Object.keys(data);
  16. let res = [];
  17. for (const k of keys) {
  18. const obj = _.omit(data[k], [ 'type', 'required', 'maxLength', 'default', 'zh' ]);
  19. if (_.get(data[k], 'zh')) {
  20. obj.model = k;
  21. obj.label = _.get(data[k], 'zh');
  22. res.push(obj);
  23. }
  24. }
  25. res = _.orderBy(res, [ 'row' ], [ 'asc' ]);
  26. return res;
  27. }
  28. async utilMethod() {
  29. console.log('in function:');
  30. }
  31. }
  32. module.exports = UtilService;