-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented feedback controller and service and added mutation hook f…
…or sending feedback to backend
- Loading branch information
1 parent
d0f76bd
commit 7d5c954
Showing
17 changed files
with
171 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { addFeedback } from "../api/axios"; | ||
import toast from "react-hot-toast"; | ||
import { Feedback } from "../types/types"; | ||
|
||
export const useAddFeedback = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationKey: ["feedback", "add"], | ||
mutationFn: addFeedback, | ||
onSuccess: (data: Feedback) => { | ||
queryClient.setQueryData(["feedback"], data); | ||
toast.success("Feedback sent!"); | ||
}, | ||
onError: (err) => { | ||
console.log(err); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { getFeedbacks } from "../api/axios"; | ||
|
||
export const useFetchFeedbacks = () => { | ||
return useQuery({ | ||
queryKey: ["feedbacks"], | ||
queryFn: getFeedbacks, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Body, Controller, Get, Post, UsePipes } from '@nestjs/common'; | ||
import { FeedbacksService } from './feedbacks.service'; | ||
import { ZodValidationPipe } from 'src/utils/pipes/ZodValidationPipe'; | ||
import { FeedbackDto, FeedbackDtoSchema } from 'src/utils/dtos/feedback.dto'; | ||
|
||
@Controller('feedbacks') | ||
export class FeedbacksController { | ||
constructor(private readonly feedbacksService: FeedbacksService) {} | ||
|
||
@Get() | ||
async getFeedbacks() { | ||
return await this.feedbacksService.getFeedbacks(); | ||
} | ||
|
||
@Post() | ||
@UsePipes(new ZodValidationPipe(FeedbackDtoSchema)) | ||
async addFeedback(@Body() dto: FeedbackDto) { | ||
return await this.feedbacksService.addFeedback(dto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { FeedbacksController } from './feedbacks.controller'; | ||
import { FeedbacksService } from './feedbacks.service'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Feedback } from 'src/utils/entities/feedback.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Feedback])], | ||
controllers: [FeedbacksController], | ||
providers: [FeedbacksService], | ||
}) | ||
export class FeedbacksModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { feedbacksI } from './feedbacksInterface'; | ||
import { Feedback } from 'src/utils/entities/feedback.entity'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { FeedbackDto } from 'src/utils/dtos/feedback.dto'; | ||
|
||
@Injectable() | ||
export class FeedbacksService implements feedbacksI { | ||
constructor( | ||
@InjectRepository(Feedback) | ||
private feedbackRepository: Repository<Feedback>, | ||
) {} | ||
async addFeedback(dto: FeedbackDto): Promise<Feedback> { | ||
const newFeedback = this.feedbackRepository.create(dto); | ||
return await this.feedbackRepository.save(newFeedback); | ||
} | ||
|
||
async getFeedbacks(): Promise<Feedback[]> { | ||
return await this.feedbackRepository.find({}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { FeedbackDto } from 'src/utils/dtos/feedback.dto'; | ||
import { Feedback } from 'src/utils/entities/feedback.entity'; | ||
|
||
export interface feedbacksI { | ||
getFeedbacks(): Promise<Feedback[]>; | ||
addFeedback(dto: FeedbackDto): Promise<Feedback>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { z } from 'zod'; | ||
|
||
export const FeedbackDtoSchema = z.object({ | ||
featureType: z.union([ | ||
z.literal('other'), | ||
z.literal('bug'), | ||
z.literal('enhancement'), | ||
z.literal('new feature'), | ||
]), | ||
email: z.string().email(), | ||
contactName: z.string().min(1, 'Contact name is required'), | ||
description: z.string().min(1, 'Description is required'), | ||
}); | ||
|
||
export type FeedbackDto = z.infer<typeof FeedbackDtoSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
Column, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class Feedback { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
featureType: 'other' | 'enhancement' | 'bug' | 'new feature'; | ||
|
||
@Column() | ||
email: string; | ||
|
||
@Column() | ||
contactName: string; | ||
|
||
@Column() | ||
description: string; | ||
|
||
@UpdateDateColumn() | ||
createdAt: Date; | ||
} |