53e0db6a98
Add log_promo_event for scan/attribution/register/order with IP; admin metrics APIs and ECharts on promo detail page. Co-authored-by: Cursor <cursoragent@cursor.com>
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { PromoCodeService } from './promo-code.service';
|
|
import {
|
|
CreatePromoCodeDto,
|
|
PromoCodeListQueryDto,
|
|
PromoMetricEventsQueryDto,
|
|
PromoMetricTimelineQueryDto,
|
|
UpdatePromoCodeDto,
|
|
UpdatePromoCodeStatusDto,
|
|
} from './dto/promo-code.dto';
|
|
|
|
@Controller('admin/promo-codes')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPromoCodeController {
|
|
constructor(private readonly service: PromoCodeService) {}
|
|
|
|
@Get('scenes')
|
|
listScenes() {
|
|
return this.service.listScenes();
|
|
}
|
|
|
|
@Get()
|
|
list(@Query() query: PromoCodeListQueryDto) {
|
|
return this.service.list(query);
|
|
}
|
|
|
|
@Get(':id/users')
|
|
listUsers(@Param('id') id: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
|
|
return this.service.listUsers(
|
|
BigInt(id),
|
|
page ? Number(page) : 1,
|
|
pageSize ? Number(pageSize) : 20,
|
|
);
|
|
}
|
|
|
|
@Get(':id/stats')
|
|
stats(@Param('id') id: string) {
|
|
return this.service.stats(BigInt(id));
|
|
}
|
|
|
|
@Get(':id/metrics/timeline')
|
|
metricsTimeline(@Param('id') id: string, @Query() query: PromoMetricTimelineQueryDto) {
|
|
return this.service.getMetricsTimeline(BigInt(id), query);
|
|
}
|
|
|
|
@Get(':id/metrics/events')
|
|
metricsEvents(@Param('id') id: string, @Query() query: PromoMetricEventsQueryDto) {
|
|
return this.service.listMetricEvents(BigInt(id), query);
|
|
}
|
|
|
|
@Get(':id/qrcode')
|
|
qrcode(@Param('id') id: string) {
|
|
return this.service.getQrcodeUrl(BigInt(id));
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detail(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.PROMO_CODE_CREATE,
|
|
refType: 'PROMO_CODE',
|
|
batch: true,
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: CreatePromoCodeDto) {
|
|
return this.service.create(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PROMO_CODE_UPDATE,
|
|
refType: 'PROMO_CODE',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpdatePromoCodeDto) {
|
|
return this.service.update(BigInt(id), dto);
|
|
}
|
|
|
|
@Put(':id/status')
|
|
@HqOperation({
|
|
action: HqOperationAction.PROMO_CODE_UPDATE_STATUS,
|
|
refType: 'PROMO_CODE',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
updateStatus(@Param('id') id: string, @Body() dto: UpdatePromoCodeStatusDto) {
|
|
return this.service.updateStatus(BigInt(id), dto.status);
|
|
}
|
|
}
|