uploadquestion.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 UploadquestionService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'uploadquestion');
  10. this.model = this.ctx.model.Uploadquestion;
  11. this.smodel = this.ctx.model.Student;
  12. }
  13. // 完成度查询
  14. async completion(data) {
  15. const { type, typeid } = data;
  16. let allcount = '';
  17. let answercount = '';
  18. // 如果是期查询
  19. if (type === '0') {
  20. // 取得当前期学生总数
  21. allcount = await this.smodel.count({ termid: typeid });
  22. // 取得当前期学生答问卷数
  23. answercount = await this.model.count({ termid: typeid });
  24. } else if (type === '1') {
  25. // 取得当前期学生总数
  26. allcount = await this.smodel.count({ batchid: typeid });
  27. // 取得当前期学生答问卷数
  28. answercount = await this.model.count({ batchid: typeid });
  29. } else if (type === '2') {
  30. // 取得当前期学生总数
  31. allcount = await this.smodel.count({ classid: typeid });
  32. // 取得当前期学生答问卷数
  33. answercount = await this.model.count({ classid: typeid });
  34. }
  35. const newdata = { allcount, answercount };
  36. return newdata;
  37. }
  38. }
  39. module.exports = UploadquestionService;