diff --git a/src/api/emails/emails.controller.ts b/src/api/emails/emails.controller.ts index ffddce6..3f41bdb 100644 --- a/src/api/emails/emails.controller.ts +++ b/src/api/emails/emails.controller.ts @@ -1,7 +1,14 @@ import { EmailsService } from './emails.service'; -import { Body, Controller, HttpException, Post } from '@nestjs/common'; -import { ApiOkResponse, ApiTags } from '@nestjs/swagger'; +import { + Body, + Controller, + HttpException, + Post, + UseGuards, +} from '@nestjs/common'; +import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { CreateEmailDto } from './dto/create-email.dto'; +import { AuthGuard } from '../../auth/AuthGuard'; @ApiTags('Emails') @Controller('emails') @@ -9,6 +16,8 @@ export class EmailsController { constructor(private readonly emailsService: EmailsService) {} @ApiOkResponse({ description: 'Sent new email' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Post() async createEmail(@Body() emailData: CreateEmailDto) { try { diff --git a/src/api/emails/emails.module.ts b/src/api/emails/emails.module.ts index 77f4168..bb1519d 100644 --- a/src/api/emails/emails.module.ts +++ b/src/api/emails/emails.module.ts @@ -9,6 +9,7 @@ import { NotificationSchema, } from '../notifications/schemas/notification.schema'; import { ConfigService } from '@nestjs/config'; +import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ @@ -16,6 +17,7 @@ import { ConfigService } from '@nestjs/config'; { name: Notification.name, schema: NotificationSchema }, ]), NotificationsModule, + HttpModule, ], controllers: [EmailsController], providers: [EmailsService, NotificationsService, ConfigService], diff --git a/src/api/notifications/notifications.controller.ts b/src/api/notifications/notifications.controller.ts index 6730aad..54d7f71 100644 --- a/src/api/notifications/notifications.controller.ts +++ b/src/api/notifications/notifications.controller.ts @@ -7,8 +7,10 @@ import { Param, Patch, Post, + UseGuards, } from '@nestjs/common'; import { + ApiBearerAuth, ApiNotFoundResponse, ApiOkResponse, ApiPreconditionFailedResponse, @@ -19,6 +21,7 @@ import { NotificationsService } from './notifications.service'; import { NotificationDocument } from './schemas/notification.schema'; import { UpdateNotificationDto } from './dto/update-notification.dto'; import { CreateActionNotificationDto } from './dto/create-action-notification.dto'; +import { AuthGuard } from '../../auth/AuthGuard'; @ApiTags('Notifications') @Controller('notifications') @@ -27,6 +30,8 @@ export class NotificationsController { @ApiOkResponse({ description: 'Retrieves notification' }) @ApiNotFoundResponse({ description: 'Notification not found' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Get(':id') async findById(@Param('id') id: string) { try { @@ -38,6 +43,8 @@ export class NotificationsController { @ApiOkResponse({ description: 'Delete notification' }) @ApiNotFoundResponse({ description: 'Notification not found' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Delete() async delete(@Param('id') id: string): Promise { try { @@ -49,6 +56,8 @@ export class NotificationsController { @ApiOkResponse({ description: 'Retrieves all notifications' }) @ApiNotFoundResponse({ description: 'Notifications not found' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Get() async findAll() { try { @@ -59,6 +68,8 @@ export class NotificationsController { } @ApiOkResponse({ description: 'Create new notification' }) @ApiPreconditionFailedResponse({ description: 'Notification already exits' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Post() async createNotification( @Body() notification: CreateNotificationDto, @@ -72,6 +83,8 @@ export class NotificationsController { @ApiOkResponse({ description: 'Updates notification' }) @ApiNotFoundResponse({ description: 'Notification not found' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Patch() async update( @Body() notification: UpdateNotificationDto, @@ -86,6 +99,8 @@ export class NotificationsController { @ApiOkResponse({ description: 'Notify action' }) @ApiNotFoundResponse({ description: 'Notification action not found' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) @Post('notify_action') async notify_action( @Body() notification: CreateActionNotificationDto, diff --git a/src/api/notifications/notifications.module.ts b/src/api/notifications/notifications.module.ts index 8c73a34..ffeecbb 100644 --- a/src/api/notifications/notifications.module.ts +++ b/src/api/notifications/notifications.module.ts @@ -7,12 +7,14 @@ import { NotificationSchema, } from './schemas/notification.schema'; import { NotificationRepository } from './repository/notification.repository'; +import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ MongooseModule.forFeature([ { name: Notification.name, schema: NotificationSchema }, ]), + HttpModule, ], controllers: [NotificationsController], providers: [NotificationsService, NotificationRepository],