student.js 1.3 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 StudentService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'student');
  10. this.model = this.ctx.model.Student;
  11. }
  12. // 查询
  13. async seek({ termid, skip, limit }) {
  14. const students = await this.model.find({ termid, classid: null });
  15. const data = await this.model.find({ termid, classid: null }).skip(Number(skip)).limit(Number(limit));
  16. const total = await students.length;
  17. const result = { total, data };
  18. return result;
  19. }
  20. async findbedroom({ batchid }) {
  21. const students = await this.model.find({ batchid });
  22. const bedroomList = new Set();
  23. for (const student of students) {
  24. bedroomList.add(student.bedroom);
  25. }
  26. const result = [];
  27. let studentList = [];
  28. for (const bedroom of bedroomList) {
  29. const newstudents = await this.model.find({ bedroom });
  30. for (const newstudent of newstudents) {
  31. studentList.push(newstudent.name);
  32. }
  33. result.push({ bedroom, studentList });
  34. studentList = [];
  35. }
  36. return result;
  37. }
  38. }
  39. module.exports = StudentService;