Skip to content

Commit

Permalink
chore: protected routes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorsulcer committed Dec 10, 2023
1 parent 5649718 commit 2dc627e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/api/emails/emails.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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')
export class EmailsController {
constructor(private readonly emailsService: EmailsService) {}

@ApiOkResponse({ description: 'Sent new email' })
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Post()
async createEmail(@Body() emailData: CreateEmailDto) {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/api/emails/emails.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
NotificationSchema,
} from '../notifications/schemas/notification.schema';
import { ConfigService } from '@nestjs/config';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [
MongooseModule.forFeature([
{ name: Notification.name, schema: NotificationSchema },
]),
NotificationsModule,
HttpModule,
],
controllers: [EmailsController],
providers: [EmailsService, NotificationsService, ConfigService],
Expand Down
15 changes: 15 additions & 0 deletions src/api/notifications/notifications.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import {
ApiBearerAuth,
ApiNotFoundResponse,
ApiOkResponse,
ApiPreconditionFailedResponse,
Expand All @@ -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')
Expand All @@ -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 {
Expand All @@ -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<boolean> {
try {
Expand All @@ -49,6 +56,8 @@ export class NotificationsController {

@ApiOkResponse({ description: 'Retrieves all notifications' })
@ApiNotFoundResponse({ description: 'Notifications not found' })
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Get()
async findAll() {
try {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/api/notifications/notifications.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 2dc627e

Please sign in to comment.