import { Controller, Get, Param, Query, Req, UseGuards } from '@nestjs/common'; import type { Request } from 'express'; import { WecomPluginGuard } from './wecom-plugin.guard'; import { WecomPluginQueryService } from './wecom-plugin-query.service'; import { CurrentWecomPlugin } from './wecom-plugin.decorators'; import type { WecomPluginRuntime } from './wecom-plugin.types'; import { wecomPluginCaller } from './wecom-plugin.util'; @Controller('wecom/plugin') @UseGuards(WecomPluginGuard) export class WecomPluginController { constructor(private readonly query: WecomPluginQueryService) {} @Get() info(@CurrentWecomPlugin() plugin: WecomPluginRuntime) { return this.query.info(plugin); } @Get('openapi.json') openapi(@CurrentWecomPlugin() plugin: WecomPluginRuntime) { return this.query.openapi(plugin); } @Get('orders') orders( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryOrders(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('users') users( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryUsers(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('stores') stores( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryStores(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('store-audits') storeAudits( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryStoreAudits(plugin, wecomPluginCaller(req), q, status, page, pageSize); } @Get('store-info-audits') storeInfoAudits( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryStoreInfoAudits(plugin, wecomPluginCaller(req), status, page, pageSize); } @Get('store-info-audits/:id') storeInfoAuditDetail( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('id') id: string, ) { return this.query.queryStoreInfoAuditDetail(plugin, wecomPluginCaller(req), id); } @Get('store-package-audits') storePackageAudits( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryStorePackageAudits(plugin, wecomPluginCaller(req), status, page, pageSize); } @Get('store-package-audits/:id') storePackageAuditDetail( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('id') id: string, ) { return this.query.queryStorePackageAuditDetail(plugin, wecomPluginCaller(req), id); } @Get('redeems') redeems( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryRedeems(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('promo-codes') promoCodes( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryPromoCodes(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('promo-codes/:code/stats') promoStats( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('code') code: string, ) { return this.query.queryPromoCodeStats(plugin, wecomPluginCaller(req), code); } @Get('partners') partners( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryPartners(plugin, wecomPluginCaller(req), q, page, pageSize); } @Get('partners/:partnerId/users') partnerUsers( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('partnerId') partnerId: string, @Query('from') from?: string, @Query('to') to?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryPartnerUsers( plugin, wecomPluginCaller(req), partnerId, from, to, page, pageSize, ); } @Get('partners/:partnerId/stores') partnerStores( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('partnerId') partnerId: string, @Query('from') from?: string, @Query('to') to?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryPartnerStores( plugin, wecomPluginCaller(req), partnerId, from, to, page, pageSize, ); } @Get('partners/:partnerId/orders') partnerOrders( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Param('partnerId') partnerId: string, @Query('from') from?: string, @Query('to') to?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryPartnerOrders( plugin, wecomPluginCaller(req), partnerId, from, to, page, pageSize, ); } @Get('metrics') metrics( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('kind') kind?: string, ) { return this.query.queryMetrics(plugin, wecomPluginCaller(req), kind); } @Get('versions') versions( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryVersions(plugin, wecomPluginCaller(req), q, status, page, pageSize); } @Get('tasks') tasks( @CurrentWecomPlugin() plugin: WecomPluginRuntime, @Req() req: Request, @Query('q') q?: string, @Query('status') status?: string, @Query('versionNo') versionNo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.query.queryTasks(plugin, wecomPluginCaller(req), q, status, versionNo, page, pageSize); } }