Download src/modules/analytics/analytics.service.ts from shizoki/Lovia: direct link, hf CLI and curl.
- Browser
- Download file 959 Bytes
-
https://huggingface.co/spaces/shizoki/Lovia/resolve/main/src/modules/analytics/analytics.service.ts
- Command line
-
hf download hf://spaces/shizoki/Lovia/src/modules/analytics/analytics.service.ts
-
curl -L -o analytics.service.ts https://huggingface.co/spaces/shizoki/Lovia/resolve/main/src/modules/analytics/analytics.service.ts
959 Bytes
| import { Injectable } from '@nestjs/common'; | |
| import { InjectModel } from '@nestjs/mongoose'; | |
| import { Model } from 'mongoose'; | |
| import { UsersService } from '../users/users.service'; | |
| import { ButtonClickDto } from './dto/button-click.dto'; | |
| import { ClickEvent, ClickEventDocument } from './schemas/click-event.schema'; | |
| () | |
| export class AnalyticsService { | |
| constructor( | |
| (ClickEvent.name) private readonly clickEventModel: Model<ClickEventDocument>, | |
| private readonly usersService: UsersService | |
| ) {} | |
| async trackButtonClick(telegramId: string, dto: ButtonClickDto) { | |
| const [user] = await Promise.all([ | |
| this.usersService.incrementButtonClick(telegramId), | |
| this.clickEventModel.create({ | |
| telegramId, | |
| eventName: dto.eventName, | |
| source: dto.source, | |
| metadata: dto.metadata ?? {} | |
| }) | |
| ]); | |
| return { | |
| ok: true, | |
| buttonClicksCount: user.buttonClicksCount | |
| }; | |
| } | |
| } | |