diff --git a/src/notifications/notifications.controller.ts b/src/notifications/notifications.controller.ts new file mode 100644 index 0000000000000000000000000000000000000000..83101be3d6cb57b58f5147ddbf0347a3291bb5db --- /dev/null +++ b/src/notifications/notifications.controller.ts @@ -0,0 +1,16 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { NotificationsService } from './notifications.service'; +import { Roles } from 'src/shared/guard.decorator'; + +@Controller('notifications') +export class NotificationsController { + constructor(private notificationService: NotificationsService) {} + + // get all sent notifications for game + // :id is the id of the game + @Get(':id') + @Roles('admin', 'factionleader', 'soldier', 'groupleader') + async(@Param('id') gameId) { + return this.notificationService.getNotifications(gameId); + } +} diff --git a/src/notifications/notifications.module.ts b/src/notifications/notifications.module.ts index 41e2fcaa36d1928dff9a60bd2c6853e240baf16f..607ea0c2d486bddc8f8919a86915ed6014176628 100644 --- a/src/notifications/notifications.module.ts +++ b/src/notifications/notifications.module.ts @@ -4,10 +4,13 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { NotificationGateway } from './notifications.gateway'; import { NotificationEntity } from './notification.entity'; import { GameEntity } from '../game/game.entity'; +import { NotificationsController } from './notifications.controller'; +import { NotificationsService } from './notifications.service'; @Module({ imports: [TypeOrmModule.forFeature([NotificationEntity, GameEntity])], - providers: [NotificationGateway], + providers: [NotificationGateway, NotificationsService], exports: [NotificationGateway], + controllers: [NotificationsController], }) export class NotificationModule {} diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..d63f01786f1bbab3b500658ac40c24a977165e73 --- /dev/null +++ b/src/notifications/notifications.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { NotificationEntity } from './notification.entity'; +import { Repository } from 'typeorm'; + +@Injectable() +export class NotificationsService { + constructor( + @InjectRepository(NotificationEntity) + private notificationRepository: Repository<NotificationEntity>, + ) {} + + async getNotifications(game: string) { + return this.notificationRepository.find({ game }); + } +}