giuroperto / thunder-waste

Ironhack's Module 2 Project
0 stars 0 forks source link

MVP - Part 1 #2

Open giuroperto opened 4 years ago

giuroperto commented 4 years ago

Create App

# Dependency directory node_modules # Environment Variables should NEVER be published .env

Create models

Seed the DB

let findAuthors = Promise.all(createAuthors) .then(authors => { return books.map(book => { return Author.findOne({name: book.author.name, lastName: book.author.lastName}) .then(author => { if (!author) { throw new Error(unknown author ${book.author.name} ${book.author.lastName}); } return Object.assign({}, book, {author: author._id}); }) }); }) .catch(error => { throw new Error(error) })

const saveBooks = findAuthors.then(findAuthors => { return Promise.all(findAuthors) .then(books => { return books.map(book => { const newBook = new Book(book); return newBook.save(); }) }) }).then(savedBooks => { Promise.all(savedBooks) .then(books => books.forEach(book => console.log(created ${book.title}))) .then(() => mongoose.connection.close()) .catch(err => console.log("Error while saving the book: ",err)) })

OTHER CONFIGS

app.js

ROUTES

INDEX ROUTES

OPEN

VIEWS

ALL

giuroperto commented 4 years ago

error when consoling the mongo db connection with x.connections[0].name

giuroperto commented 4 years ago

How to use ENUM: dishType: { type: String, enum: ['Breakfast', 'Dish', 'Snack', 'Drink', 'Dessert', 'Other'] },

giuroperto commented 4 years ago

Changed sectors to be: Heavy Industry, Light Industry, Manufacturing, Business, Cottage Industry

giuroperto commented 4 years ago

to push into a referencced obj Book.update({ _id: req.query.book_id }, { $push: { reviews: { user, comments