Skip to content
Open

List #16

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
3 changes: 3 additions & 0 deletions Project/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ app.use("/", indexRoutes);
const authRoutes = require("./routes/auth.routes");
app.use("/auth", authRoutes);

const restaurantsRoutes = require("./routes/restaurants.routes");
app.use("/", restaurantsRoutes);

// ❗ To handle errors. Routes that don't exist or errors that you handle in specific routes
require("./error-handling")(app);

Expand Down
91 changes: 90 additions & 1 deletion Project/bin/seeds.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const mongoose = require("mongoose")
const Restaurant = require("../models/restaurant")

// Require the models, Example: (-- const Book = require("../models/Book.model") --)

const MONGO_URI = "mongodb://localhost:27017/project2"
const MONGO_URI = "mongodb://localhost:27017/appetito"


const createSeeds = async function () {
try {
const connect = await mongoose.connect(MONGO_URI)
console.log(`Connected to database: ${connect.connections[0].name}`)
await Restaurant.create(Restaurants)

// Clear DB, Example: (-- const deleteAll = await Book.deleteMany() --)
// console.log("Db clean")
Expand All @@ -20,4 +22,91 @@ const createSeeds = async function () {
}
}


const Restaurants = [
{
name: "Two Schmucks",
style: "Bar",
address: "Carrer de Joaquín Costa, 52, 08001 Barcelona",
price: "€€",
phonenumber: 685309575,
picture: "https://www.theworlds50best.com/discovery/filestore/jpg/TwoSchmucks-Barcelona-Spain-02.jpg",
instagram: "https://www.instagram.com/two.schmucks/?hl=es",
wifi: true,
coworking: false,
delivery: false
},

{
name: "Paradiso",
style: "Bar",
address: "Carrer de Rera Palau, 4, 08003 Barcelona",
price: "€€",
phonenumber: 933607222,
picture: "https://paradiso.cat/wp-content/uploads/2020/05/the_cloud.jpg",
instagram: "https://www.instagram.com/paradiso_barcelona/?hl=es",
wifi: true,
coworking: false,
delivery: false,

},

{
name: "Bobby's Free",
style: "Bar",
address: "C/ de Pau Claris, 85, 08010 Barcelona",
price: "€€",
phonenumber: 000000,
picture: "https://www.gastronosfera.com/sites/default/files/uploads/gatronosfera_bobbydrink-53.jpg",
instagram: "https://www.instagram.com/bobbysfree/?hl=es",
wifi: true,
coworking: false,
delivery: false,

},

{
name: "Brasería La Selva Barcelona",
style: "Steakhouse",
address: "Carrer de la Indústria, 138, 08025 Barcelona",
price: "€€",
phonenumber: 933487299,
picture: "https://media.timeout.com/images/104717624/750/422/image.jpg",
instagram: "https://www.instagram.com/laselvabarcelona/",
wifi: true,
coworking: false,
delivery: false,

},

{
name: "Casa Lolea",
style: "Bar",
address: "Carrer de Sant Pere Més Alt 49, 08003 Barcelona",
price: "€€",
phonenumber: 936241016,
picture: "https://www.lolea.com/wp-content/uploads/2020/12/casa-lolea-23-baja-1600x1200.jpg",
instagram: "https://www.instagram.com/casalolea/",
wifi: true,
coworking: false,
delivery: false,

},

{
name: "Billy Brunch",
style: "Brunch",
address: "Carrer de Bailèn, 115, 08009 Barcelona ",
price: "€€",
phonenumber: 000000,
picture: "https://www.metropoliabierta.com/uploads/s1/19/19/48/6/aperturabilly.jpeg",
instagram: "https://www.instagram.com/billybrunch/?hl=es",
wifi: true,
coworking: false,
delivery: false,

},
]


createSeeds()
17 changes: 12 additions & 5 deletions Project/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MongoStore = require("connect-mongo");

// Connects the mongo uri to maintain the same naming structure
const MONGO_URI =
process.env.MONGODB_URI || "mongodb://localhost:27017/project2";
process.env.MONGODB_URI || "mongodb://localhost:27017/appetito";

// Middleware configuration
module.exports = (app) => {
Expand All @@ -51,15 +51,22 @@ module.exports = (app) => {
favicon(path.join(__dirname, "..", "public", "images", "favicon.ico"))
);


// ℹ️ Middleware that adds a "req.session" information and later to check that you are who you say you are 😅
app.use(
session({
secret: process.env.SESSION_SECRET || "super hyper secret key",
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
secure: process.env.NODE_ENV === 'production',
httpOnly: true,
maxAge: 60000
},
store: MongoStore.create({
mongoUrl: MONGO_URI,
}),
})
mongoUrl: process.env.MONGODB_URI || 'mongodb://localhost:27017/appetito'
})
})
);
};
2 changes: 1 addition & 1 deletion Project/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mongoose = require("mongoose");
// If no env has been set, we dynamically set it to whatever the folder name was upon the creation of the app

const MONGO_URI =
process.env.MONGODB_URI || "mongodb://localhost:27017/project2";
process.env.MONGODB_URI || "mongodb://localhost:27017/appetito";

mongoose
.connect(MONGO_URI)
Expand Down
8 changes: 8 additions & 0 deletions Project/middleware/isAdmin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = (req, res, next) => {
// checks if the user is logged in when trying to access a specific page
if (!req.session.currentUser.admin) {
return res.redirect("/restaurants");
}

next();
};
10 changes: 9 additions & 1 deletion Project/models/User.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const userSchema = new Schema(
{
username: {
type: String,
required: false,
required: true,
unique: true,
trim: true,
},
Expand All @@ -20,6 +20,14 @@ const userSchema = new Schema(
type: String,
required: true,
},

favorites: {
type: [{type: Schema.Types.ObjectId, ref:"Restaurant"}]
},

admin : {
type: Boolean
}
},
{
// this second object adds extra properties: `createdAt` and `updatedAt`
Expand Down
25 changes: 25 additions & 0 deletions Project/models/favorite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { Schema, model } = require("mongoose");

// TODO: Please make sure you edit the User model to whatever makes sense in this case
const favoriteSchema = new Schema(
{
user: {
type: {type: Schema.Types.ObjectId, ref:"User"},

},

restaurant: {
type: [{type: Schema.Types.ObjectId, ref:"Restaurant"}]
},

},

{
// this second object adds extra properties: `createdAt` and `updatedAt`
timestamps: true,
}
);

const Favorite = model("Favorite", favoriteSchema);

module.exports = Favorite;
29 changes: 29 additions & 0 deletions Project/models/rate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Schema, model } = require("mongoose");

// TODO: Please make sure you edit the User model to whatever makes sense in this case
const rateSchema = new Schema(
{
user: {
type: {type: Schema.Types.ObjectId, ref:"User"},

},

rate: {
type: Boolean,
},

review: {
type: String,
},

},

{
// this second object adds extra properties: `createdAt` and `updatedAt`
timestamps: true,
}
);

const Rate = model("Rate", rateSchema);

module.exports = Rate;
64 changes: 64 additions & 0 deletions Project/models/restaurant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { Schema, model } = require("mongoose");

// TODO: Please make sure you edit the User model to whatever makes sense in this case
const restaurantSchema = new Schema(
{
name: {
type: String,
required: true,
unique: true
},
// duda en style si poner solo los estilos que queremos (ENUM)
style: {
type: String,
required: true,
enum: ["Arabic", "Argentinian", "Bar", "Brazilian", "Burgers", "Chinese", "Korean",
"Brunch", "Indian", "Japanese", "Indian", "Kebab", "Mexican", "Italian", "Poke",
"Sushi", "Vegan", "Vegetarian", "Vietnamese", "Coffee Shop", "Steakhouse"]
},

address: {
type: String,
unique: true
},

price: {
type: String,
required: true
},
phonenumber: {
type: Number,
unique: true
},

picture: {
type: String,
},
instagram: {
type: String,
unique: true
},
// como poder hacer si o no (poner el si y el no en HBS)
wifi: {
type: Boolean,
},

coworking: {
type: Boolean,
},

delivery: {
type: Boolean,
},

},

{
// this second object adds extra properties: `createdAt` and `updatedAt`
timestamps: true,
}
);

const Restaurant = model("Restaurant", restaurantSchema);

module.exports = Restaurant;
Loading