12345678910111213141516171819202122232425262728293031323334353637383940 |
- 'use strict';
- const _ = require('lodash');
- const Controller = require('egg').Controller;
- // 群管理
- class GroupChatController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.service = this.ctx.service.groupchat;
- }
- // 查询列表
- 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.params, 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 = GroupChatController;
|