uploadtask.js 939 B

1234567891011121314151617181920212223242526272829303132
  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 UploadtaskService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'uploadtask');
  10. this.model = this.ctx.model.Uploadtask;
  11. this.stumodel = this.ctx.model.Student;
  12. }
  13. async query({ skip, limit, ...info }) {
  14. const total = await this.model.count(info);
  15. const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
  16. const data = [];
  17. for (const elm of res) {
  18. const _elm = _.cloneDeep(JSON.parse(JSON.stringify(elm)));
  19. const stu = await this.stumodel.findById(_elm.studentid);
  20. _elm.stuname = stu.name;
  21. data.push(_elm);
  22. }
  23. return { data, total };
  24. }
  25. }
  26. module.exports = UploadtaskService;