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

Create restaurant groups #12

Open
wants to merge 9 commits into
base: master
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
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
root: true,
settings: {
react: {
version: "detect",
},
},
extends: [
"airbnb-typescript",
"prettier",
"plugin:prettier/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
plugins: ["simple-import-sort"],
rules: {
"prettier/prettier": ["warn", { endOfLine: "auto" }],
"react/require-default-props": "off",
"react/no-array-index-key": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off",
"simple-import-sort/imports": 1,
"simple-import-sort/exports": 1,
},
};
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
trailingComma: "all",
};
3 changes: 2 additions & 1 deletion backend/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const sequelize = new Sequelize(
);

const db = {
Restaurant: require("./restaurant")(sequelize, Sequelize)
Restaurant: require("./restaurant")(sequelize, Sequelize),
User: require("./user")(sequelize, Sequelize)
};

Object.keys(db).forEach(key => {
Expand Down
32 changes: 19 additions & 13 deletions backend/models/restaurant.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
/* can't use ES6 export syntax due to incompatibility with sequelize */
module.exports = (sequelize, DataTypes) => {
/* create the model corresponding to the restaurant PostgreSQL table */
const Restaurant = sequelize.define("restaurant", {
const Restaurant = sequelize.define(
"restaurant",
{
/* sequelize automatically defines an id column as primary key */
name: {
type: DataTypes.STRING,
allowNull: false
type: DataTypes.STRING,
allowNull: false,
},
address: {
type: DataTypes.STRING,
type: DataTypes.STRING,
},
type: {
type: DataTypes.STRING,
type: DataTypes.STRING,
},
budget: {
type: DataTypes.ENUM,
values: ["LOW", "MEDIUM", "HIGH"]
type: DataTypes.ENUM,
values: ["LOW", "MEDIUM", "HIGH"],
},
description: {
type: DataTypes.STRING,
type: DataTypes.STRING,
},
rating: {
type: DataTypes.INTEGER,
type: DataTypes.INTEGER,
},
},
{
timestamps: false
});
numRatings: {
type: DataTypes.INTEGER,
},
},
{
timestamps: false,
}
);

return Restaurant;
}
26 changes: 26 additions & 0 deletions backend/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* can't use ES6 export syntax due to incompatibility with sequelize */
module.exports = (sequelize, DataTypes) => {
/* create the model corresponding to the restaurant PostgreSQL table */
const User = sequelize.define(
"user",
{
/* sequelize automatically defines an id column as primary key */
email: {
type: DataTypes.STRING,
allowNull: false,
},
password: {
type: DataTypes.STRING,
},
role: {
type: DataTypes.ENUM,
values: ["ADMIN", "REGULAR"],
},
},
{
timestamps: false,
}
);

return User;
}
187 changes: 99 additions & 88 deletions backend/seedRestaurantData.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,103 @@
const seedRestaurantData = [
{
name: "Campus Pizza",
address: "160 University Ave W #2, Waterloo, ON N2L 3E9",
type: "Pizzeria",
budget: "LOW",
description: "giant slices, affordable prices",
rating: 2
},
{
name: "Shawerma Plus",
address: "160 University Ave W, Waterloo, ON N2L 3E9",
type: "Middle Eastern",
budget: "MEDIUM",
description: "better than Lazeez apparently",
rating: 4
},
{
name: "Mr Panino's Beijing House",
address: "106 University Ave W #1, Waterloo, ON N2L 3E9",
type: "Chinese",
budget: "LOW",
description: "good portions, questionable health inspection records though 🤔",
rating: 2
},
{
name: "Foodie Fruitie",
address: "203 Lester St #7, Waterloo, ON N2L 0B5",
type: "East Asian",
budget: "LOW",
description: "good selection on the menu, sushi, ramen, curry, etc.",
rating: 4
},
{
name: "CoCo",
address: "203 Lester St #3, Waterloo, ON N2L 3W4",
type: "Bubble Tea",
budget: "LOW",
description: "relatively cheap bubble tea",
rating: 3
},
{
name: "Sharetea",
address: "256 Phillip St d, Waterloo, ON N2L 3W8",
type: "Bubble Tea",
budget: "MEDIUM",
description: "more expensive bubble tea",
rating: 3
},
{
name: "Williams Fresh Cafe",
address: "170 University Ave W, Waterloo, ON N2L 3E9",
type: "Coffee",
budget: "MEDIUM",
description: "good study spot",
rating: 3
},
{
name: "O'My Bakery",
address: "262-264 Phillip St, Waterloo, ON N2L 3W8",
type: "Bakery",
budget: "LOW",
description: "good for grabbing a quick bite",
rating: 3
},
{
name: "The Poke Box",
address: "255 King St N #3, Waterloo, ON N2J 4V2",
type: "Poke",
budget: "MEDIUM",
description: "good stuff!",
rating: 4
},
{
name: "Bao Sandwich Bar",
address: "62 Balsam St B106, Waterloo, ON N2L 3H2",
type: "East Asian",
budget: "LOW",
description: "good food but hard to get a seat",
rating: 4
},
{
name: "Tim Horton's",
address: "151 Columbia St W, Waterloo, ON N2L 3L2",
type: "Coffee",
budget: "LOW",
description: "typical Tim Horton's, short walk if you live at icon",
rating: 3
},
{
name: "Campus Pizza",
address: "160 University Ave W #2, Waterloo, ON N2L 3E9",
type: "Pizzeria",
budget: "LOW",
description: "giant slices, affordable prices",
rating: 2,
numRatings: 1,
},
{
name: "Shawerma Plus",
address: "160 University Ave W, Waterloo, ON N2L 3E9",
type: "Middle Eastern",
budget: "MEDIUM",
description: "better than Lazeez apparently",
rating: 4,
numRatings: 1,
},
{
name: "Mr Panino's Beijing House",
address: "106 University Ave W #1, Waterloo, ON N2L 3E9",
type: "Chinese",
budget: "LOW",
description: "good portions, questionable health inspection records though 🤔",
rating: 2,
numRatings: 1,
},
{
name: "Foodie Fruitie",
address: "203 Lester St #7, Waterloo, ON N2L 0B5",
type: "East Asian",
budget: "LOW",
description: "good selection on the menu, sushi, ramen, curry, etc.",
rating: 4,
numRatings: 1,
},
{
name: "CoCo",
address: "203 Lester St #3, Waterloo, ON N2L 3W4",
type: "Bubble Tea",
budget: "LOW",
description: "relatively cheap bubble tea",
rating: 3,
numRatings: 1,
},
{
name: "Sharetea",
address: "256 Phillip St d, Waterloo, ON N2L 3W8",
type: "Bubble Tea",
budget: "MEDIUM",
description: "more expensive bubble tea",
rating: 3,
numRatings: 1,
},
{
name: "Williams Fresh Cafe",
address: "170 University Ave W, Waterloo, ON N2L 3E9",
type: "Coffee",
budget: "MEDIUM",
description: "good study spot",
rating: 3,
numRatings: 1,
},
{
name: "O'My Bakery",
address: "262-264 Phillip St, Waterloo, ON N2L 3W8",
type: "Bakery",
budget: "LOW",
description: "good for grabbing a quick bite",
rating: 3,
numRatings: 1,
},
{
name: "The Poke Box",
address: "255 King St N #3, Waterloo, ON N2J 4V2",
type: "Poke",
budget: "MEDIUM",
description: "good stuff!",
rating: 4,
numRatings: 1,
},
{
name: "Bao Sandwich Bar",
address: "62 Balsam St B106, Waterloo, ON N2L 3H2",
type: "East Asian",
budget: "LOW",
description: "good food but hard to get a seat",
rating: 4,
numRatings: 1,
},
{
name: "Tim Horton's",
address: "151 Columbia St W, Waterloo, ON N2L 3L2",
type: "Coffee",
budget: "LOW",
description: "typical Tim Horton's, short walk if you live at icon",
rating: 3,
numRatings: 1,
},
];

export default seedRestaurantData;
60 changes: 32 additions & 28 deletions backend/services/restaurantService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,43 @@ async function getRestaurants() {
}

async function createRestaurant(name, address, type, budget, description, rating) {
return await db.Restaurant.create({
name,
address,
type,
budget,
description,
rating
});
return await db.Restaurant.create({
name,
address,
type,
budget,
description,
rating,
numRatings: 1,
});
}

async function updateRestaurant(id, name, address, type, budget, description, rating) {
const updateResult = await db.Restaurant.update({
name,
address,
type,
budget,
description,
rating
async function updateRestaurant(id, name, address, type, budget, description, rating, numRatings = 1) {
const updateResult = await db.Restaurant.update(
{
name,
address,
type,
budget,
description,
rating,
numRatings,
},
{
returning: true,
where: { id: id }
});

/**
* Sequelize's update() method returns an array.
* the first element is the number of records updated,
* the second element is an array of the records updated */
if (updateResult[0] === 1) {
return updateResult[1][0];
} else {
return null;
returning: true,
where: { id: id },
}
);

/**
* Sequelize's update() method returns an array.
* the first element is the number of records updated,
* the second element is an array of the records updated */
if (updateResult[0] === 1) {
return updateResult[1][0];
} else {
return null;
}
}

async function deleteRestaurant(id) {
Expand Down
Loading