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

done #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

done #41

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
28 changes: 24 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,35 @@ const MONGODB_URI = 'mongodb://localhost:27017/recipe-app';

// Connection to the database "recipe-app"
mongoose
.connect(MONGODB_URI)
.connect("mongodb://localhost:27017/Recipie",{
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(x => {
console.log(`Connected to the database: "${x.connection.name}"`);
// Before adding any recipes to the database, let's remove all existing ones
return Recipe.deleteMany()

})
.then(() => {
// Run your code here, after you have insured that the connection was made
})
.catch(error => {
console.error('Error connecting to the database', error);
return Recipe.create({
title: 'Spaghetti Carbonara',
level: 'Easy Peasy',
ingredients: ['spaghetti', 'egg', 'cheese', 'bacon', 'pepper'],
cuisine: 'Italian',
dishType: 'main_course',
duration: 30,
creator: 'Chef Luigi',
});
})
.then((recipe) => {
console.log(`Recipe created: ${recipe.title}`);
})
.catch((error) => {
console.error('Error creating recipe:', error);
})
.finally(() => {
mongoose.connection.close();
});

35 changes: 35 additions & 0 deletions models/Recipe.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ const Schema = mongoose.Schema;

const recipeSchema = new Schema({
// TODO: write the schema
title: {
type: String,
required: true,
unique: true,
},
level: {
type: String,
enum: ['Easy Peasy', 'Amateur Chef', 'UltraPro Chef'],
},
ingredients: {
type: [String],
},
cuisine: {
type: String,
required: true,
},
dishType: {
type: String,
enum: ['breakfast', 'main_course', 'soup', 'snack', 'drink', 'dessert', 'other'],
},
image: {
type: String,
default: 'https://images.media-allrecipes.com/images/75131.jpg',
},
duration: {
type: Number,
min: 0,
},
creator: {
type: String,
},
created: {
type: Date,
default: Date.now,
},
});

const Recipe = mongoose.model('Recipe', recipeSchema);
Expand Down