import BaseController from '../../base'; import { AdminRoute } from '../../../decorator/router_register'; import { PageGetDto } from '../../../dto/comm'; import { CreateBotDto, DeleteBotDto, UpdateBotDto } from '../../../dto/admin/tg/bot'; export default class TgbotController extends BaseController { @AdminRoute('/tg/tgboot/test', 'get') async test() { this.res({ data: await this.service.admin.tg.tgbot.tgTest(), }); } /** * list */ @AdminRoute('/tg/bot/list', 'get') async list() { this.res({ data: await this.service.admin.tg.tgbot.list(), }); } /** * page */ @AdminRoute('/tg/bot/page', 'get') async page() { const dto = await this.ctx.validate(PageGetDto, this.getQuery()); this.res({ data: { list: await this.service.admin.tg.tgbot.page(dto.current - 1, dto.pageSize), pagination: { page: dto.current, size: dto.pageSize, total: await this.service.admin.tg.tgbot.count(), }, }, }); } @AdminRoute('/tg/bot/add', 'post') async add() { const dto = await this.ctx.validate(CreateBotDto); this.res({ data: await this.service.admin.tg.tgbot.add(dto), }); } @AdminRoute('/tg/bot/update', 'post') async update() { const dto = await this.ctx.validate(UpdateBotDto); await this.service.admin.tg.tgbot.update(dto); this.res({}); } @AdminRoute('/tg/bot/delete', 'post') async delete() { const dto = await this.ctx.validate(DeleteBotDto); this.res({ data: await this.service.admin.tg.tgbot.delete(dto.id), }); } }