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

Add Restaurant Group Data Model #2

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions backend/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const sequelize = new Sequelize(

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

Expand Down
25 changes: 25 additions & 0 deletions backend/models/restaurantGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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 RestaurantGroup = sequelize.define(
"restaurantgroup",
{
/* sequelize automatically defines an id column as primary key */
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
},
restaurantIds: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
},
},
{
timestamps: false,
}
);

return RestaurantGroup;
}
14 changes: 13 additions & 1 deletion backend/seedRestaurantData.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,16 @@ const seedRestaurantData = [
},
];

export default seedRestaurantData;
const seedRestaurantGroupData =[{
name: "Best Pizza Place",
description: "Only Campus Pizza",
restaurantIds: [1],
},
{
name: "Boba Places",
description: "fun boba places",
restaurantIds: [5,6],
},];
export {seedRestaurantGroupData,seedRestaurantData};


6 changes: 5 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ApolloServer } from "apollo-server-express";

import schema from "./graphql";
import db, { sequelize } from "./models/index";
import seedRestaurantData from "./seedRestaurantData";
import {seedRestaurantData, seedRestaurantGroupData} from "./seedRestaurantData";


/* create our Express.js application */
Expand Down Expand Up @@ -62,5 +62,9 @@ async function seedDb() {
await db.Restaurant.create(r);
});

seedRestaurantGroupData.forEach(async (r) => {
await db.RestaurantGroup.create(r);
});

console.info("Successfully seeded the database!");
}