Skip to content
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

Backend updated with new database string and user authentication resolved. #31

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions controllers/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class LoginController {
res.status(status);
res.json({ message, data });
}


}

module.exports = LoginController;
4 changes: 2 additions & 2 deletions controllers/ReviewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const reviewService = require("../services/review.service");
class ReviewController {

async create(req, res) {
const { reviewId, location_id, user_id, review } = req.body;
const { location_id, user_id, review } = req.body;
if(typeof review !== "string"){
res.status(400);
return res.send("Incorrect request data");
}
// Make sure the sequence is the same as in location.
const { status, data, message } =
await reviewService.create(
reviewId,

location_id,
user_id,
review
Expand Down
4 changes: 2 additions & 2 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Sequelize } = require("sequelize");

const sequelize = new Sequelize('d3fpq27b46ct8n', 'gxfycuowlyjazp', 'b3b4c032a56be20bcc5410ea35a7faf487852a194ade5d44e6ec498b9f380e50', {
host: 'ec2-44-197-128-108.compute-1.amazonaws.com',
const sequelize = new Sequelize('dbheroku', 'postgres', 'mypassword', {
host: 'mydatabase-1.ctgdayi97uhz.ap-southeast-1.rds.amazonaws.com',
dialect: 'postgres',
dialectOptions:{
ssl: {
Expand Down
5,773 changes: 2,264 additions & 3,509 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Supper Makan Apa?",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"start": "node index.js",
"test": "mocha --timeout 15000"
},
"repository": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"sqlite3": "^5.0.8"
},
"engines": {
"node": "14.x",
"node": "<14.x",
"npm": "8.9.0"
},
"devDependencies": {
Expand Down
17 changes: 9 additions & 8 deletions routes/login.routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const express = require("express");
const router = express.Router();
const { User } = require("../models");
const bcrypt = require("bcrypt");
const saltRounds = 10;
const bcrypt = require("bcryptjs");
const jwt = require("jsonwebtoken");
const config = require("../config/auth.config");
const app = express();
Expand Down Expand Up @@ -35,15 +34,12 @@ router.post("/login/signup", loginController.create);
router.post("/login/signin", async (req, res) => {
User.findOne({
where: {
username: req.body.username,
username: req.body.username
},
})
.then((user) => {
if (!user) {
return res.status(404).send({ message: "User Not found." });
}

var passwordIsValid = bcrypt.compare(

var passwordIsValid = bcrypt.compareSync(
req.body.password,
user.password
);
Expand All @@ -54,6 +50,11 @@ router.post("/login/signin", async (req, res) => {
message: "Invalid Password!",
});
}
if (!user) {
return res.status(404).send({ message: "User Not found." });
}



var token = jwt.sign({ id: user.id }, config.secret, {
expiresIn: 86400, // 24 hours
Expand Down
5 changes: 4 additions & 1 deletion routes/user.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const { sequelize } = require('../models');
const locationController = new LocationController();
const reviewController = new ReviewController();
const favoriteController = new FavoriteController();
const app = express();
app.use(express.json()); // Enable express to parse JSON as request body.
const cors = require('cors');


app.use(cors());
router.get("/user", (req, res) => {
return res.send("You have called a user route");
});
Expand Down
4 changes: 2 additions & 2 deletions services/review.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Review } = require("../models");

module.exports = {

create: async (reviewId, location_id, user_id, review) => {
create: async (location_id, user_id, review) => {
//The result object is where we will put the result to be sent to th client.
let result = {
message: null,
Expand All @@ -12,7 +12,7 @@ module.exports = {

//Look for the review and in the database.
const newReview = await Review.create({
reviewId: reviewId,

location_id: location_id,
user_id: user_id,
review: review,
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chai = require('chai');
const server = "https://supper-makan-apa.herokuapp.com";
const server = "https://witty-puce-boot.cyclic.app";
const chaiHttp = require('chai-http');
const { describe } = require('mocha');
const expect = require("chai").expect;
Expand Down Expand Up @@ -84,7 +84,7 @@ describe("LOCATIONS", () => {
// "address": "75 Tanjong Pagar Road Singapore 088496",
// "located_at": "South",
// "cuisineId": "Korean",
// "priceId": "$$$",
// "priceId": "moderate",
// "openingHour": "11am to 2am",
// "image": "https://sethlui.com/wp-content/uploads/2014/11/supper-listicle-14.jpg"
// };
Expand Down Expand Up @@ -185,8 +185,8 @@ describe("REVIEWS", () => {
// describe("/POST review", () => {
// it("it should POST a review", (done) => {
// let myreview = {
// "location_id": 9,
// "user_id": 14,
// "location_id": "9",
// "user_id": "14",
// "review": "Authentic Korean food. Nice environment to dine in.",
// };
// chai.request(server)
Expand Down