article.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. // 文章
  7. class ArticleService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'article');
  10. this.model = this.ctx.model.Article;
  11. this.pdModel = this.ctx.model.Patientdocs;
  12. }
  13. async query({ skip = 0, limit = 0, ...query } = {}) {
  14. query = this.ctx.service.util.dealQuery(query);
  15. const { patientid } = query;
  16. if (patientid) {
  17. // 需要查出这个病人所属的医生,然后添加医生范围的条件
  18. const doctors = await this.pdModel.find({ patientid }, 'doctorid');
  19. const ids = doctors.map(i => JSON.parse(JSON.stringify(i.doctorid)));
  20. query.user_id = ids;
  21. delete query.patientid;
  22. }
  23. const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
  24. .sort({ 'meta.createdAt': -1 });
  25. const total = await this.model.count(query);
  26. return { data, total };
  27. }
  28. }
  29. module.exports = ArticleService;