Skip to content

Commit

Permalink
Fix: Made reviews changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rayaanoidPrime committed May 12, 2024
1 parent f5bf431 commit 0454209
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
36 changes: 32 additions & 4 deletions apps/api/src/feedback/controller/feedback.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Controller, Post, Body } from '@nestjs/common'
import { Controller, Post, Body, HttpStatus } from '@nestjs/common'
import { Public } from '../../decorators/public.decorator'
import { FeedbackService } from '../service/feedback.service'
import { ApiTags } from '@nestjs/swagger'
import {
ApiTags,
ApiBody,
ApiResponse,
ApiOperation,
ApiProperty
} from '@nestjs/swagger'

@ApiTags('Feedback Controller')
@Controller('feedback')
Expand All @@ -10,7 +16,29 @@ export class FeedbackController {

@Public()
@Post()
async registerFeedback(@Body('feedback') feedback: string): Promise<void> {
await this.feedbackService.registerFeedback(feedback)
@ApiOperation({
summary: 'Send Feedback message to Admin',
description: 'This endpoint sends a feedback message to the Admin email.'
})
@ApiBody({
schema: {
type: 'object',
properties: {
feedback: {
type: 'string',
example: 'Your feedback message here'
}
}
}
})
@ApiResponse({
status: HttpStatus.CREATED,
description: 'Feedback registered successfully'
})
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Bad Request' })
async registerFeedback(
@Body() feedbackData: { feedback: string }
): Promise<void> {
await this.feedbackService.registerFeedback(feedbackData.feedback)
}
}
13 changes: 11 additions & 2 deletions apps/api/src/feedback/feedback.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe('Feedback Controller (E2E)', () => {
await app.getHttpAdapter().getInstance().ready()

await cleanUp(prisma)
})

beforeEach(async () => {
user = await prisma.user.create({
data: {
email: '[email protected]',
Expand All @@ -52,8 +54,15 @@ describe('Feedback Controller (E2E)', () => {
})
})

afterEach(async () => {
if (user) {
await prisma.user.delete({
where: { id: user.id }
})
}
})

afterAll(async () => {
await cleanUp(prisma)
await prisma.$disconnect()
await app.close()
})
Expand Down Expand Up @@ -93,7 +102,7 @@ describe('Feedback Controller (E2E)', () => {
expect(statusCode).toBe(400)
expect(JSON.parse(payload)).toEqual({
error: 'Bad Request',
message: 'Feedback cannot be null',
message: 'Feedback cannot be null or empty',
statusCode: 400
})
})
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/feedback/service/feedback.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class FeedbackService {
) {}

async registerFeedback(feedback: string): Promise<void> {
if (!feedback) {
throw new BadRequestException('Feedback cannot be null')
if (!feedback || feedback.trim().length === 0) {
throw new BadRequestException('Feedback cannot be null or empty')
}
const adminEmail = '[email protected]'

await this.mailService.feedbackEmail(adminEmail, feedback)
await this.mailService.feedbackEmail(adminEmail, feedback.trim())
}
}

0 comments on commit 0454209

Please sign in to comment.