'use strict'; const _ = require('lodash'); const Controller = require('egg').Controller; // 群管理 class GroupController extends Controller { constructor(ctx) { super(ctx); this.service = this.ctx.service.group; } // 查询列表 async index() { let { skip, limit, ...info } = this.ctx.query; if (skip && !_.isNumber(skip)) skip = Number(skip); if (limit && !_.isNumber(limit)) limit = Number(limit); const res = await this.service.query(info, { skip, limit }); this.ctx.ok({ ...res }); } // POST // 添加群 async create() { // 如果参数校验未通过,将会抛出一个 status = 422 的异常 const res = await this.service.create(this.ctx.request.body); this.ctx.ok({ msg: 'created', data: res }); } // GET /{id} // 获得群详情 async show() { const res = await this.service.fetch(this.ctx.params); this.ctx.ok({ data: res }); } // GET /{id}/info // POST /{id}/info // 获得基本信息,修改基本信息 async info() { if (this.ctx.request.method === 'POST') { await this.service.updateInfo(this.ctx.params, this.ctx.request.body); this.ctx.ok({ msg: 'accepted' }); } else { const res = await this.service.fetch(this.ctx.params, { patients: '+patients' }); this.ctx.ok({ data: res && res.emrs }); } } // DELETE /{id} // 删除群信息 async destroy() { const { id } = this.ctx.params; await this.service.delete({ id }); this.ctx.ok({ msg: 'deleted' }); } async exit() { await this.service.exit(this.ctx.request.body); this.ctx.ok(); } } module.exports = GroupController;