228 lines
6.2 KiB
TypeScript
228 lines
6.2 KiB
TypeScript
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';
|
|
|
|
@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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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, pluginCaller(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,
|
|
pluginCaller(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,
|
|
pluginCaller(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,
|
|
pluginCaller(req),
|
|
partnerId,
|
|
from,
|
|
to,
|
|
page,
|
|
pageSize,
|
|
);
|
|
}
|
|
|
|
@Get('metrics')
|
|
metrics(
|
|
@CurrentWecomPlugin() plugin: WecomPluginRuntime,
|
|
@Req() req: Request,
|
|
@Query('kind') kind?: string,
|
|
) {
|
|
return this.query.queryMetrics(plugin, pluginCaller(req), kind);
|
|
}
|
|
}
|
|
|
|
function pluginCaller(req: Request): string {
|
|
const raw = req.headers['x-wecom-userid'] ?? req.headers['userid'];
|
|
const v = Array.isArray(raw) ? raw[0] : raw;
|
|
return String(v || 'plugin').trim() || 'plugin';
|
|
}
|