Skip to content

Commit

Permalink
add event logger controller
Browse files Browse the repository at this point in the history
  • Loading branch information
annarhughes committed Jun 13, 2024
1 parent 872f49b commit fa76c38
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/event-logger/event-logger.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { FirebaseAuthGuard } from 'src/firebase/firebase-auth.guard';
import { ControllerDecorator } from 'src/utils/controller.decorator';
import { EVENT_NAME } from './event-logger.interface';
import { EventLoggerService } from './event-logger.service';

@ApiTags('Event Logger')
@ControllerDecorator()
@Controller('/v1/event-logger')
export class EventLoggerController {
constructor(private readonly eventLoggerService: EventLoggerService) {}

@Post()
@ApiOperation({
description: 'Creates an event log',
})
@ApiBearerAuth('access-token')
@UseGuards(FirebaseAuthGuard)
async complete(@Req() req: Request, @Body() event: EVENT_NAME) {
const now = new Date();
return await this.eventLoggerService.createEventLog({
userId: req['userEntity'].id,
event,
date: now,
});
}
}
2 changes: 2 additions & 0 deletions src/event-logger/event-logger.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum EVENT_NAME {
CHAT_MESSAGE_SENT = 'CHAT_MESSAGE_SENT',
LOGGED_IN = 'LOGGED_IN',
LOGGED_OUT = 'LOGGED_OUT',
}

export interface ICreateEventLog {
Expand Down

0 comments on commit fa76c38

Please sign in to comment.