This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anton Konev
committed
Jun 16, 2015
1 parent
3aa5dbd
commit 5811e02
Showing
8 changed files
with
151 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var configs = require('../configs/default'), | ||
db = require('./db'); | ||
|
||
module.exports = { | ||
index: function(req, res, next) { | ||
var data = configs.defaults(req), | ||
render = function() { | ||
return res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
}; | ||
|
||
data.contentType = 'userGoods'; | ||
|
||
db.getGoods(req.user.id, false, function (result) { | ||
data.userGoods = result; | ||
render(); | ||
}); | ||
}, | ||
|
||
users: function(req, res, next) { | ||
var data = configs.defaults(req), | ||
render = function() { | ||
return res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
}; | ||
|
||
data.contentType = 'users'; | ||
|
||
db.getUsers(false, function(result) { | ||
data.users = result; | ||
render(); | ||
}, true); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
var configs = require('../configs/default'), | ||
db = require('../lib/db'); | ||
var configs = require('../configs/default'); | ||
|
||
module.exports = { | ||
index: function(req, res, next) { | ||
var data = configs.defaults(req); | ||
var data = configs.defaults(req), | ||
render = function() { | ||
return res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
}; | ||
|
||
//TODO: Промисы для монги | ||
data.contentType = req.route.path === '/account' ? 'user' : data.contentType; | ||
data.contentType === 'user' && db.getUser(req.user.id, function (err, user) { | ||
data.user = user; | ||
}); | ||
|
||
res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
render(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var configs = require('../configs/default'), | ||
db = require('./db'); | ||
|
||
module.exports = { | ||
index: function(req, res, next) { | ||
var data = configs.defaults(req), | ||
render = function() { | ||
return res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
}; | ||
|
||
data.contentType = 'user'; | ||
|
||
db.getUser(req.user.id, function (err, user) { | ||
data.user = user; | ||
render(); | ||
}); | ||
}, | ||
|
||
users: function(req, res, next) { | ||
var data = configs.defaults(req), | ||
render = function() { | ||
return res.render('index', data, function(err, html) { | ||
if (err) { | ||
res.send(500, err); | ||
} else { | ||
res.send(html); | ||
} | ||
}); | ||
}; | ||
|
||
data.contentType = 'users'; | ||
|
||
db.getUsers(false, function (result) { | ||
data.users = result; | ||
render(); | ||
}, true); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
var MongoClient = require('mongodb').MongoClient, | ||
vow = require('vow'), | ||
var Promise = require("bluebird"), | ||
MongoClient = Promise.promisifyAll(require('mongodb').MongoClient), | ||
|
||
db_users, db_goods; | ||
|
||
MongoClient.connect('mongodb://localhost:27017/goods-shelf', function(err, db) { | ||
if (err) { | ||
MongoClient.connectAsync('mongodb://localhost:27017/goods-shelf') | ||
.then(function(db) { | ||
console.log("Connected to DB"); | ||
|
||
db_users = db.collection('users'); | ||
db_goods = db.collection('goods'); | ||
}) | ||
.catch(function(err) { | ||
console.log("I can't connect to DB. Is it running?"); | ||
throw err; | ||
} | ||
|
||
console.log("Connected to DB"); | ||
|
||
db_users = db.collection('users'); | ||
db_goods = db.collection('goods'); | ||
}); | ||
}); | ||
|
||
module.exports = { | ||
upsertUser: function(id, profile, clb) { | ||
db_users.update({ id: id }, { $set: { profile: profile }}, { upsert: true }, clb); | ||
upsertUser: function(id, profile, cb) { | ||
db_users.update({ id: id }, { $set: { profile: profile }}, { upsert: true }, cb); | ||
}, | ||
|
||
getUser: function(id, clb) { | ||
db_users.findOne({ id: id }, clb); | ||
getUser: function(id, cb) { | ||
db_users.findOne({ id: id }, cb); | ||
}, | ||
|
||
addUser: function(name) | ||
{ | ||
addUser: function(name) { | ||
db_users.insert({ name: name }, function(err, records) { console.log(records); }); | ||
}, | ||
|
||
getUsers: function(clb) | ||
{ | ||
db_users.find({}, clb); | ||
getUsers: function(cb) { | ||
db_users.find({}, cb); | ||
}, | ||
|
||
getUserGoods: function(id, cb) { | ||
var params = id !== undefined ? { "uid": id } : {}; | ||
|
||
db_goods.find(params, cb); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters