'use strict'; const _ = require('lodash'); const Controller = require('egg').Controller; // 私聊管理 class ChatController extends Controller { constructor(ctx) { super(ctx); this.service = this.ctx.service.chat; } // 查询列表 async index() { let { skip, limit, ...info } = this.ctx.query; if (skip && !_.isNumber(skip)) skip = Number(skip); if (limit && !_.isNumber(limit)) limit = Number(limit); const data = await this.service.query(info, { skip, limit }); this.ctx.ok({ ...data }); } // POST // 添加群 async create() { // 如果参数校验未通过,将会抛出一个 status = 422 的异常 const res = await this.service.create(this.ctx.request.body); this.ctx.ok({ msg: 'created', data: res }); } // DELETE /{id} // 删除群信息 async destroy() { const { id } = this.ctx.params; await this.service.delete({ id }); this.ctx.ok({ msg: 'deleted' }); } } module.exports = ChatController;