31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
|
import { AnalyticsService } from './analytics.service';
|
|
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
|
|
import { OptionalJwtAuthGuard } from '../../common/guards/optional-jwt-auth.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import { PromoTouchDto } from './dto/promo.dto';
|
|
import { ActorType } from '@dukang/shared-types';
|
|
|
|
@Controller('analytics')
|
|
export class AnalyticsController {
|
|
constructor(private readonly analyticsService: AnalyticsService) {}
|
|
|
|
@Post('events')
|
|
@UseGuards(JwtAuthGuard)
|
|
track(@CurrentUser() user: AuthUser, @Body() body: { events: Array<{ eventName: string; params?: Record<string, unknown> }> }) {
|
|
return this.analyticsService.trackBatch(user.actorId, user.clientApp, body.events);
|
|
}
|
|
}
|
|
|
|
@Controller('promo')
|
|
export class PromoController {
|
|
constructor(private readonly analyticsService: AnalyticsService) {}
|
|
|
|
@Post('touch')
|
|
@UseGuards(OptionalJwtAuthGuard)
|
|
touch(@CurrentUser() user: AuthUser | undefined, @Body() dto: PromoTouchDto) {
|
|
const userId = user?.actorType === ActorType.USER ? user.actorId : undefined;
|
|
return this.analyticsService.touchPromo(dto.promoCode, userId);
|
|
}
|
|
}
|