baseController.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class BaseController extends Controller {
  4. async one() {
  5. const { ctx } = this;
  6. const result = await this.tag().one(ctx.query.id);
  7. ctx.logic(result, '查询失败');
  8. }
  9. async list() {
  10. const { ctx } = this;
  11. const result = await this.tag().list(ctx.query);
  12. ctx.success(result);
  13. }
  14. async listForPage() {
  15. const { ctx } = this;
  16. const result = await this.tag().listForPage(ctx.query);
  17. ctx.success(result);
  18. }
  19. async add() {
  20. const { ctx } = this;
  21. const query = ctx.request.body;
  22. delete query._id;
  23. const result = await this.tag().add(query);
  24. ctx.success(result);
  25. }
  26. async update() {
  27. const { ctx } = this;
  28. const query = ctx.request.body;
  29. const { id } = query;
  30. delete query.id;
  31. const result = await this.tag().update(id, query);
  32. ctx.success(result);
  33. }
  34. async delete() {
  35. const { ctx } = this;
  36. const result = await this.tag().delete(ctx.query.id);
  37. ctx.success(result);
  38. }
  39. }
  40. module.exports = BaseController;