-
Notifications
You must be signed in to change notification settings - Fork 0
Dynamic host rating bars API, sanitiseData, adjusted error responses and bug fixes #75
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
19 commits
Select commit
Hold shift + click to select a range
b8353c1
Merge pull request #65 from MakanMatch/main
Prakhar896 901a39f
replaced auth middle ware with prakhar's code
Sadliquid 8ad07a2
Removed yup date validation which causes invalid date format. Pivoted…
Sadliquid ccc9790
Added reviews statistics consolidation route
Sadliquid 30bc4f7
Moved aggregation to backend
Sadliquid 3111cc1
Added validation for adding a listing on backend
Sadliquid 661e7e5
Implemented sanitiseData
Sadliquid 53dba9f
Standardised responses to include message and error
Sadliquid 0b80efc
Re-adjusted error handling
Sadliquid d1dc840
Standardised error codes
Sadliquid f210288
added support for addListing publishInstantly
Sadliquid 8586b26
Added backend routes for MakanHistory
Sadliquid f1318f5
Changed error types, remove console logs, standardised responses to r…
Sadliquid da6189b
Added error tag
Sadliquid 5f300ad
Removed 3 letter Us
Sadliquid 2199318
Added include and filtering
Sadliquid f69d6ad
Added empty array for no reservations response
Sadliquid 06a6868
Merge branch 'main' into joshua
Prakhar896 f23a65d
sanitising out password in coreData /listings
Prakhar896 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
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,62 @@ | ||
| const express = require("express"); | ||
| const router = express.Router(); | ||
| const path = require("path"); | ||
| const FileManager = require("../../services/FileManager"); | ||
| const Extensions = require("../../services/Extensions"); | ||
| const { FoodListing, Host, Guest, Admin, Review, Reservation, ReviewLike } = require("../../models"); | ||
| const Logger = require("../../services/Logger"); | ||
| const { Sequelize } = require('sequelize'); | ||
| const Universal = require("../../services/Universal"); | ||
| const { validateToken, checkUser } = require("../../middleware/auth"); | ||
| const { Op } = require("sequelize"); | ||
|
|
||
| router.get("/getGuestPastReservations", validateToken, async(req, res) => { | ||
| const userID = req.user.userID; | ||
| if (!userID) { | ||
| return res.status(400).send("ERROR: One or more required payloads were not provided"); | ||
| } | ||
| try { | ||
| const user = await Guest.findByPk(userID) || await Host.findByPk(userID); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do take note that, in the future, you have to just do |
||
| if (!user) { | ||
| return res.status(404).send("ERROR: User doesn't exist"); | ||
| } else { | ||
| const pastReservations = await Reservation.findAll({ | ||
| where: { | ||
| guestID: userID, | ||
| datetime: { | ||
| [Op.lt]: new Date().toISOString() | ||
| } | ||
| } | ||
| }); | ||
| if (pastReservations.length > 0) { | ||
| const foodListings = await FoodListing.findAll({ | ||
| where: { | ||
| listingID: { | ||
| [Op.in]: pastReservations.map(reservation => reservation.listingID) | ||
| } | ||
| }, | ||
| include: [{ | ||
| model: Host, | ||
| attributes: ["username", "foodRating"] | ||
| }] | ||
| }); | ||
| if (foodListings) { | ||
| if (foodListings.length > 0) { | ||
| return res.status(200).json({ pastReservations: pastReservations, foodListings: foodListings }); | ||
|
Sadliquid marked this conversation as resolved.
|
||
| } else { | ||
| return res.status(400).send("ERROR: Could not find any food listings that were tied to this reservation"); | ||
| } | ||
| } else { | ||
| return res.status(400).send("ERROR: An error occured while retrieving food listings for the past reservations"); | ||
| } | ||
| } else { | ||
| return res.status(200).json({ pastReservations: [], foodListings: [] }); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| Logger.log(`MAKAN_HISTORY GETGUESTPASTRESERVATIONS ERROR: ${err}`) | ||
| return res.status(500).send("ERROR: An error occured while retrieving user's past reservations"); | ||
| } | ||
| }); | ||
|
|
||
| module.exports = { router, at: '/makanHistory' }; | ||
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
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.