Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
767fc17
routes done
proyectomarco Nov 4, 2022
de797fd
Model On the Way
Cugat Nov 4, 2022
1880564
Merge pull request #1 from projectmarcobravo/routes
marcobravocosta Nov 4, 2022
a86c993
Merge pull request #2 from projectmarcobravo/models
marcobravocosta Nov 4, 2022
f6587a0
Models and index updated
Lunarcito Nov 6, 2022
e925981
favmodels
Lunarcito Nov 7, 2022
d0b1a3d
Merge pull request #3 from projectmarcobravo/models
marcobravocosta Nov 7, 2022
f879bbd
Model Restaurant 0611
Cugat Nov 7, 2022
c62857c
Merge branch 'main' of https://github.com/projectmarcobravo/Appetito …
Cugat Nov 7, 2022
4b793d8
Update 0711
Cugat Nov 7, 2022
c244822
Merge pull request #4 from projectmarcobravo/models
Cugat Nov 7, 2022
7cddcc1
restaurant changed
proyectomarco Nov 7, 2022
11064d7
Merge pull request #5 from projectmarcobravo/restaurant
marcobravocosta Nov 7, 2022
c5d47e8
DB done
Cugat Nov 7, 2022
f2edc19
Merge pull request #6 from projectmarcobravo/models2
Cugat Nov 7, 2022
9a0e197
pacj.json
Lunarcito Nov 7, 2022
ea3c582
Update 4
Cugat Nov 7, 2022
a9e731a
Merge pull request #7 from projectmarcobravo/models3
marcobravocosta Nov 7, 2022
a5de826
post done
proyectomarco Nov 7, 2022
75923c2
Merge branch 'main' into restaurant
marcobravocosta Nov 7, 2022
3aa0fc5
Merge pull request #8 from projectmarcobravo/restaurant
marcobravocosta Nov 7, 2022
f4ef7ab
restaurant card route done
proyectomarco Nov 7, 2022
e35a8cd
Update restaurantCard
Cugat Nov 7, 2022
6afa14e
Merge pull request #9 from projectmarcobravo/list
marcobravocosta Nov 7, 2022
204b549
Merge pull request #10 from projectmarcobravo/models4
marcobravocosta Nov 7, 2022
06d2517
restaurant list done, but styles not
proyectomarco Nov 7, 2022
cc968e6
Merge pull request #11 from projectmarcobravo/restaurantcard
marcobravocosta Nov 7, 2022
1bf6ae4
rates updated
Lunarcito Nov 8, 2022
6bc25d1
Merge pull request #12 from projectmarcobravo/rate
marcobravocosta Nov 8, 2022
1bd6d27
done
proyectomarco Nov 8, 2022
a50708c
Merge branch 'main' into restaurantcard
marcobravocosta Nov 8, 2022
afe75de
Merge pull request #13 from projectmarcobravo/restaurantcard
marcobravocosta Nov 8, 2022
5e1e809
done
proyectomarco Nov 8, 2022
8d1a5bd
petfriendly
Cugat Nov 8, 2022
8fcbc2f
Merge pull request #14 from projectmarcobravo/restaurantcard1
marcobravocosta Nov 8, 2022
1a508cf
Merge branch 'main' into models7
marcobravocosta Nov 8, 2022
41d2fcd
Merge pull request #15 from projectmarcobravo/models7
marcobravocosta Nov 8, 2022
b00a019
brunch3
Lunarcito Nov 8, 2022
122fd3b
Merge branch 'main' into brunch3
marcobravocosta Nov 8, 2022
d593670
Merge pull request #16 from projectmarcobravo/brunch3
marcobravocosta Nov 8, 2022
19ebd8f
rest routes update
Lunarcito Nov 8, 2022
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();
};
6 changes: 5 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,10 @@ const userSchema = new Schema(
type: String,
required: true,
},

rateIds: {
type: [{type: Schema.Types.ObjectId, ref:"Rate"}],
},
},
{
// 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;
34 changes: 34 additions & 0 deletions Project/models/rate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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"},

},
restaurant: {

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

},

rate: {
type: Number
},

review: {
type: String,
},

},

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

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

module.exports = Rate;
69 changes: 69 additions & 0 deletions Project/models/restaurant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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,
},


rateIds: {
type: [{type: Schema.Types.ObjectId, ref:"Rate"}],
},

},

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

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

module.exports = Restaurant;
Loading