-
Notifications
You must be signed in to change notification settings - Fork 0
SUPPORT-64-add-feedback-route #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9bafc63
feat: add clients repository fn findByName()
yqni13 3cfcf3f
test: feedback_ratings tests/interfaces/migration
yqni13 3c7a24c
feat: feedback_rating route + logic
yqni13 c367dbd
refactor: test data + email validation timing
yqni13 9d38fea
test: add tests + test-app setup, update utils
yqni13 b79494d
feat: add Feedback/FeedbackRating route/logic/test
yqni13 95ba431
docs: update documentation
yqni13 5761c5d
refactor: code review changes
yqni13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
109 changes: 109 additions & 0 deletions
109
backend/migrations/1772192517446_12-feedback-entries-create.migrations.js
This file contains hidden or 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,109 @@ | ||
| /** | ||
| * @type {import('node-pg-migrate').ColumnDefinitions | undefined} | ||
| */ | ||
| const shorthands = undefined; | ||
|
|
||
| /** | ||
| * @param {import('node-pg-migrate').MigrationBuilder} pgm | ||
| */ | ||
| async function up(pgm) { | ||
| pgm.createTable('feedback_entries', { | ||
| feedback_id: { | ||
| type: 'serial', | ||
| primaryKey: true | ||
| }, | ||
| client_id: { | ||
| type: 'uuid', | ||
| notNull: true, | ||
| references: '"clients"(client_id)', | ||
| onDelete: 'CASCADE', | ||
| onUpdate: 'CASCADE' | ||
| }, | ||
| user_id: { | ||
| type: 'uuid', | ||
| notNull: true, | ||
| references: '"users"(user_id)', | ||
| onDelete: 'CASCADE', | ||
| onUpdate: 'CASCADE' | ||
| }, | ||
| rating: { | ||
| type: 'smallint', | ||
| notNull: true, | ||
| default: 5 | ||
| }, | ||
| term_accepted: { | ||
| type: 'boolean', | ||
| notNull: true, | ||
| default: false | ||
| }, | ||
| message: { | ||
| type: 'text', | ||
| notNull: false | ||
| }, | ||
| reviewed_on: { | ||
| type: 'TIMESTAMP WITH TIME ZONE', | ||
| notNull: false | ||
| }, | ||
| last_modified: { | ||
| type: 'TIMESTAMP WITH TIME ZONE', | ||
| notNull: true, | ||
| default: 'NOW()' | ||
| }, | ||
| created_on: { | ||
| type: 'TIMESTAMP WITH TIME ZONE', | ||
| notNull: true, | ||
| default: 'NOW()' | ||
| } | ||
| }); | ||
| pgm.addConstraint( | ||
| 'feedback_entries', | ||
| 'feedback_entries_unique_clients_users', | ||
| { unique: ['client_id', 'user_id'] } | ||
| ); | ||
| pgm.sql(`ALTER SEQUENCE feedback_entries_feedback_id_seq RESTART WITH 1;`); | ||
| pgm.createTable('feedback_ratings', { | ||
| client_id: { | ||
| type: 'uuid', | ||
| primaryKey: true, | ||
| references: '"clients"(client_id)', | ||
| onDelete: 'CASCADE', | ||
| onUpdate: 'CASCADE' | ||
| }, | ||
| count: { | ||
| type: 'integer', | ||
| notNull: true, | ||
| default: 0 | ||
| }, | ||
| rating_sum: { | ||
| type: 'integer', | ||
| notNull: true, | ||
| default: 0 | ||
| }, | ||
| last_modified: { | ||
| type: 'TIMESTAMP WITH TIME ZONE', | ||
| notNull: true, | ||
| default: 'NOW()' | ||
| }, | ||
| created_on: { | ||
| type: 'TIMESTAMP WITH TIME ZONE', | ||
| notNull: true, | ||
| default: 'NOW()' | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {import('node-pg-migrate').MigrationBuilder} pgm | ||
| */ | ||
| async function down(pgm) { | ||
| pgm.dropTable('feedback_entries', { | ||
| ifExists: true, | ||
| cascade: true | ||
| }); | ||
| pgm.dropTable('feedback_ratings', { | ||
| ifExists: true, | ||
| cascade: true | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = { shorthands, up, down }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
| import { NextFunction, Request, Response } from "express"; | ||
| import { checkValidation } from "../middleware/validation.middleware"; | ||
| import feedbackRatingService from "../services/feedback-rating.service"; | ||
| import { FeedbackRatingExtendedResponseDTO, FeedbackRatingResponseDTO } from "../dtos/feedback-rating.dto"; | ||
|
|
||
| class FeedbackRatingController { | ||
| async getExtendedFeedbackRating(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const id = req.params.id; | ||
| const response: FeedbackRatingExtendedResponseDTO | null = await feedbackRatingService.getExtendedFeedbackRatingById(id); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
|
|
||
| async getFeedbackRating(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const client_name = req.params.client_name; | ||
| const response: FeedbackRatingResponseDTO | null = await feedbackRatingService.getFeedbackRatingByClientName(client_name); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
|
|
||
| async getAllFeedbackRatings(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| const response: FeedbackRatingExtendedResponseDTO[] | null = await feedbackRatingService.getAllFeedbackRatings(); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default new FeedbackRatingController(); |
This file contains hidden or 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,56 @@ | ||
| import { NextFunction, Request, Response } from "express"; | ||
| import { checkValidation } from "../middleware/validation.middleware"; | ||
| import { FeedbackCreateDTO, FeedbackFilterDTO, FeedbackResponseDTO } from "../dtos/feedback.dto"; | ||
| import feedbackService from "../services/feedback.service"; | ||
|
|
||
| class FeedbackController { | ||
| async getFeedback(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const id = +req.params.id; | ||
| const response: FeedbackResponseDTO | null = await feedbackService.getFeedbackById(id); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
|
|
||
| async postFeedbackEntriesSearch(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const dto: FeedbackFilterDTO = req.body; | ||
| const response: FeedbackResponseDTO[] | null = await feedbackService.searchFeedbackEntriesByFilter(dto); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
|
|
||
| async postFeedback(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const dto: FeedbackCreateDTO = { | ||
| ...req.body, | ||
| client_id: req.apiClients.client_id, | ||
| user_id: req.apiUsers.user_id | ||
| }; | ||
| const response: FeedbackResponseDTO | null = await feedbackService.createFeedback(dto); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
|
|
||
| async patchFeedbackReview(req: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| checkValidation(req); | ||
| const id = +req.params.id; | ||
| const response: FeedbackResponseDTO | null = await feedbackService.updateFeedbackReview(id); | ||
| res.json(response); | ||
| } catch(err: any) { | ||
| next(err); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default new FeedbackController(); |
This file contains hidden or 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,23 @@ | ||
| export interface FeedbackRatingCreateDTO { | ||
| client_id: string, | ||
| count?: number, | ||
| rating_sum?: number | ||
| } | ||
|
|
||
| export interface FeedbackRatingUpdateDTO { | ||
| count?: number, | ||
| rating: number, | ||
| last_modified?: string | ||
| } | ||
|
|
||
| export interface FeedbackRatingResponseDTO { | ||
| rating_average: number, | ||
| } | ||
|
|
||
| export interface FeedbackRatingExtendedResponseDTO extends FeedbackRatingResponseDTO { | ||
| client_id: string, | ||
| count: number, | ||
| rating_sum: number, | ||
| last_modified: string, | ||
| created_on: string | ||
| } |
This file contains hidden or 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,43 @@ | ||
| export interface FeedbackCreateDTO { | ||
| client_id: string, | ||
| user_id: string, | ||
| rating: number, | ||
| term_accepted: boolean, | ||
| message?: string, | ||
| } | ||
|
|
||
| export interface FeedbackRequestCreateDTO { | ||
| user_email: string, | ||
| rating: number, | ||
| term_accepted: boolean, | ||
| message?: string | ||
| } | ||
|
|
||
| export interface FeedbackUpdateReviewDTO { | ||
| reviewed_on: string, | ||
| last_modified: string | ||
| } | ||
|
|
||
| export interface FeedbackFilterDTO { | ||
| client_id?: string | string[], | ||
| user_id?: string | string[], | ||
| rating?: number | number[], | ||
| term_accepted?: boolean, | ||
| reviewed_on?: string | string[], | ||
| last_modified?: string | string[], | ||
| created_on?: string | string[] | ||
| } | ||
|
|
||
| export interface FeedbackResponseDTO { | ||
| feedback_id: number, | ||
| client_id: string, | ||
| user_id: string, | ||
| rating: number, | ||
| rating_average_new?: number, | ||
| rating_old?: number, | ||
| term_accepted: boolean, | ||
| message?: string, | ||
| reviewed_on?: string, | ||
| last_modified: string, | ||
| created_on: string | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.