1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2026-01-06 17:29:15 +00:00

Something is up

This commit is contained in:
Scott Tolksdorf
2017-01-05 20:49:45 -05:00
parent 537a75b2ab
commit 3dc4c13178
8 changed files with 79 additions and 65 deletions

View File

@@ -1,7 +1,6 @@
const _ = require('lodash');
const shortid = require('shortid');
const mongoose = require('mongoose');
mongoose.Promise = Promise;
const mongoose = require('./db.js').instance;
const utils = require('./utils.js');
@@ -78,15 +77,22 @@ const BrewData = {
return Brew.findOne(query).exec();
},
create : (brew) => {
console.log('here');
delete brew.shareId;
delete brew.editId;
if(!brew.title) brew.title = utils.getGoodBrewTitle(brew.text);
const newBrew = new Brew(brew);
//TODO: add error decorators to the catches
return newBrew.save();
//TODO: add error decorators to the catches
const temp = newBrew.save().then(()=>{
console.log('SAVED');
});
console.log(typeof temp, _.keys(temp), temp);
return temp;
},
update : (newBrew) => {
return Brew.findOneAndUpdate({ editId : newBrew.editId },

View File

@@ -1,18 +1,23 @@
const mongoose = require('mongoose');
mongoose.Promise = Promise;
const dbPath = process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/homebrewery';
module.exports = {
connect : ()=>{
return new Promise((resolve, reject)=>{
require('mongoose')
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/homebrewery',
(err) => {
if(err){
console.log('Error : Could not connect to a Mongo Database.');
console.log(' If you are running locally, make sure mongodb.exe is running.');
return reject();
}
return resolve();
mongoose.createConnection(dbPath,
(err) => {
if(err){
console.log('Error : Could not connect to a Mongo Database.');
console.log(' If you are running locally, make sure mongodb.exe is running.');
return reject(err);
}
);
return resolve();
}
);
});
}
},
instance : mongoose,
clearDatabase : ()=>{}
}