platformAct.js 974 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. //
  7. class PlatformActService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'platformact');
  10. this.model = this.ctx.model.System.PlatformAct;
  11. }
  12. async query(filter, { skip = 0, limit, projection } = {}) {
  13. let condition = _.cloneDeep(filter);
  14. condition = await this.beforeQuery(condition);
  15. condition = this.dealFilter(condition);
  16. // 过滤出ref字段
  17. const { populate } = this.getRefMods();
  18. // 带ref查询
  19. let rs = await this.model.find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } }).populate(populate).exec();
  20. rs = JSON.parse(JSON.stringify(rs));
  21. // 整理ref数据
  22. rs = await this.afterQuery(filter, rs);
  23. return rs;
  24. }
  25. }
  26. module.exports = PlatformActService;