progress.js 760 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. class HandleService extends Service {
  4. constructor(ctx) {
  5. super(ctx);
  6. this.progressModel = this.ctx.model.Progress;
  7. }
  8. // 修改进度
  9. async updateProgress({ taskId, progress, type }) {
  10. const res = await this.progressModel.findOne({ taskId });
  11. if (!res) {
  12. await this.progressModel.create({ type, taskId, progress });
  13. } else {
  14. await this.progressModel.updateOne({ _id: res._id }, { type, taskId, progress });
  15. }
  16. }
  17. // 查询进度
  18. async progressed({ taskId }) {
  19. console.log(taskId);
  20. const res = await this.progressModel.findOne({ taskId });
  21. console.log(res);
  22. return { errcode: 0, errmsg: '', data: res };
  23. }
  24. }
  25. module.exports = HandleService;