group.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. const _ = require('lodash');
  3. const Controller = require('egg').Controller;
  4. // 群管理
  5. class GroupController extends Controller {
  6. constructor(ctx) {
  7. super(ctx);
  8. this.service = this.ctx.service.group;
  9. }
  10. // 查询列表
  11. async index() {
  12. let { skip, limit, ...info } = this.ctx.query;
  13. if (skip && !_.isNumber(skip)) skip = Number(skip);
  14. if (limit && !_.isNumber(limit)) limit = Number(limit);
  15. const res = await this.service.query(info, { skip, limit });
  16. this.ctx.ok({ ...res });
  17. }
  18. // POST
  19. // 添加群
  20. async create() {
  21. // 如果参数校验未通过,将会抛出一个 status = 422 的异常
  22. const res = await this.service.create(this.ctx.request.body);
  23. this.ctx.ok({ msg: 'created', data: res });
  24. }
  25. // GET /{id}
  26. // 获得群详情
  27. async show() {
  28. const res = await this.service.fetch(this.ctx.params);
  29. this.ctx.ok({ data: res });
  30. }
  31. // GET /{id}/info
  32. // POST /{id}/info
  33. // 获得基本信息,修改基本信息
  34. async info() {
  35. if (this.ctx.request.method === 'POST') {
  36. await this.service.updateInfo(this.ctx.params, this.ctx.request.body);
  37. this.ctx.ok({ msg: 'accepted' });
  38. } else {
  39. const res = await this.service.fetch(this.ctx.params, { patients: '+patients' });
  40. this.ctx.ok({ data: res && res.emrs });
  41. }
  42. }
  43. // DELETE /{id}
  44. // 删除群信息
  45. async destroy() {
  46. const { id } = this.ctx.params;
  47. await this.service.delete({ id });
  48. this.ctx.ok({ msg: 'deleted' });
  49. }
  50. async exit() {
  51. await this.service.exit(this.ctx.request.body);
  52. this.ctx.ok();
  53. }
  54. }
  55. module.exports = GroupController;