tgbot.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import BaseController from '../../base';
  2. import { AdminRoute } from '../../../decorator/router_register';
  3. import { PageGetDto } from '../../../dto/comm';
  4. import { CreateBotDto, DeleteBotDto, UpdateBotDto } from '../../../dto/admin/tg/bot';
  5. export default class TgbotController extends BaseController {
  6. @AdminRoute('/tg/tgboot/test', 'get')
  7. async test() {
  8. this.res({
  9. data: await this.service.admin.tg.tgbot.tgTest(),
  10. });
  11. }
  12. /**
  13. * list
  14. */
  15. @AdminRoute('/tg/bot/list', 'get')
  16. async list() {
  17. this.res({
  18. data: await this.service.admin.tg.tgbot.list(),
  19. });
  20. }
  21. /**
  22. * page
  23. */
  24. @AdminRoute('/tg/bot/page', 'get')
  25. async page() {
  26. const dto = await this.ctx.validate<PageGetDto>(PageGetDto, this.getQuery());
  27. this.res({
  28. data: {
  29. list: await this.service.admin.tg.tgbot.page(dto.current - 1, dto.pageSize),
  30. pagination: {
  31. page: dto.current,
  32. size: dto.pageSize,
  33. total: await this.service.admin.tg.tgbot.count(),
  34. },
  35. },
  36. });
  37. }
  38. @AdminRoute('/tg/bot/add', 'post')
  39. async add() {
  40. const dto = await this.ctx.validate<CreateBotDto>(CreateBotDto);
  41. this.res({
  42. data: await this.service.admin.tg.tgbot.add(dto),
  43. });
  44. }
  45. @AdminRoute('/tg/bot/update', 'post')
  46. async update() {
  47. const dto = await this.ctx.validate<UpdateBotDto>(UpdateBotDto);
  48. await this.service.admin.tg.tgbot.update(dto);
  49. this.res({});
  50. }
  51. @AdminRoute('/tg/bot/delete', 'post')
  52. async delete() {
  53. const dto = await this.ctx.validate<DeleteBotDto>(DeleteBotDto);
  54. this.res({
  55. data: await this.service.admin.tg.tgbot.delete(dto.id),
  56. });
  57. }
  58. }