@@ -2,11 +2,12 @@ import {
22 Injectable ,
33 Logger ,
44 ConflictException ,
5- BadRequestException ,
5+ // BadRequestException,
66 NotFoundException ,
77 HttpException ,
88 HttpStatus ,
99} from '@nestjs/common' ;
10+ import { EventEmitter2 } from '@nestjs/event-emitter' ;
1011import { InjectRepository } from '@nestjs/typeorm' ;
1112import { Repository , DataSource , MoreThan } from 'typeorm' ;
1213import * as crypto from 'crypto' ;
@@ -26,6 +27,7 @@ import { ViolationType } from '../../anti-cheat/constants';
2627import { XpService } from '../../xp/xp.service' ;
2728import { PlayerEventsService } from '../../player-events/player-events.service' ;
2829import { PuzzleVersionService } from './puzzle-version.service' ;
30+ import { WEBHOOK_INTERNAL_EVENTS } from '../../webhooks/webhook.constants' ;
2931
3032// ────────────────────────────────────────────────────────────────────────────
3133// Constants
@@ -56,6 +58,7 @@ export class SolutionSubmissionService {
5658 private readonly xpService : XpService ,
5759 private readonly playerEventsService : PlayerEventsService ,
5860 private readonly puzzleVersionService : PuzzleVersionService ,
61+ private readonly eventEmitter : EventEmitter2 ,
5962 ) { }
6063
6164 // ──────────────────────────────────────────────────────────────────────────
@@ -251,6 +254,15 @@ export class SolutionSubmissionService {
251254 } ,
252255 } ) ;
253256
257+ this . eventEmitter . emit ( WEBHOOK_INTERNAL_EVENTS . puzzleSolved , {
258+ userId,
259+ puzzleId,
260+ solveTimeSeconds : timeTakenSeconds ,
261+ hintsUsed : dto . hintsUsed ?? 0 ,
262+ scoreAwarded,
263+ solvedAt : now . toISOString ( ) ,
264+ } ) ;
265+
254266 // Each achievement unlocked should produce an audit event
255267 for ( const achievement of result . rewards ?. achievements ?? [ ] ) {
256268 void this . playerEventsService . emitPlayerEvent ( {
@@ -264,6 +276,15 @@ export class SolutionSubmissionService {
264276 hintsUsed : dto . hintsUsed ?? 0 ,
265277 } ,
266278 } ) ;
279+
280+ this . eventEmitter . emit ( WEBHOOK_INTERNAL_EVENTS . achievementUnlocked , {
281+ userId,
282+ puzzleId,
283+ achievementId : achievement ,
284+ unlockedAt : now . toISOString ( ) ,
285+ hintsUsed : dto . hintsUsed ?? 0 ,
286+ solveTimeSeconds : timeTakenSeconds ,
287+ } ) ;
267288 }
268289 }
269290
0 commit comments