buff.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 BuffService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'user');
  10. this.umodel = this.ctx.model.User;
  11. this.emodel = this.ctx.model.Expertsuser;
  12. }
  13. async userlist(info) {
  14. const { pid, code, skip, limit } = info;
  15. let url = this.ctx.app.config.axios.auth.baseUrl + '/finduserlist?skip=' + skip + '&limit=' + limit;
  16. if (pid) {
  17. url = url + '&pid=' + pid;
  18. }
  19. if (code) {
  20. url = url + '&code=' + code;
  21. }
  22. const res = await this.ctx.curl(url, {
  23. method: 'get',
  24. headers: {
  25. 'content-type': 'application/json',
  26. },
  27. dataType: 'json',
  28. });
  29. const resdata = res.data.data;
  30. const data = [];
  31. for (const elm of resdata) {
  32. const newdata = { ...JSON.parse(JSON.stringify(elm)) };
  33. if (elm.role === '4' || elm.role === '5') {
  34. const user = await this.umodel.findById(elm.uid);
  35. if (user) {
  36. newdata.status = user.status;
  37. }
  38. } else if (elm.role === '6') {
  39. const user = await this.emodel.findById(elm.uid);
  40. if (user) {
  41. newdata.status = user.status;
  42. }
  43. }
  44. data.push(newdata);
  45. }
  46. return { data, total: res.data.total };
  47. }
  48. }
  49. module.exports = BuffService;