12345678910111213141516171819202122232425262728293031 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- // 文章
- class ArticleService extends CrudService {
- constructor(ctx) {
- super(ctx, 'article');
- this.model = this.ctx.model.Article;
- this.pdModel = this.ctx.model.Patientdocs;
- }
- async query({ skip = 0, limit = 0, ...query } = {}) {
- query = this.ctx.service.util.dealQuery(query);
- const { patientid } = query;
- if (patientid) {
- // 需要查出这个病人所属的医生,然后添加医生范围的条件
- const doctors = await this.pdModel.find({ patientid }, 'doctorid');
- const ids = doctors.map(i => JSON.parse(JSON.stringify(i.doctorid)));
- query.user_id = ids;
- delete query.patientid;
- }
- const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
- .sort({ 'meta.createdAt': -1 });
- const total = await this.model.count(query);
- return { data, total };
- }
- }
- module.exports = ArticleService;
|