Last active
August 29, 2015 14:07
-
-
Save suissa/feaf2ba037d5e763751a to your computer and use it in GitHub Desktop.
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
module.exports = function(app) { | |
var Schema = require('mongoose').Schema; | |
var People = Schema({ | |
Name: String, | |
Address: { | |
type: Schema.Types.ObjectId, | |
ref: 'Address' | |
}, | |
Number: String, | |
Type: String, | |
Complement: String, | |
}); | |
return People; | |
}; |
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
show: function(req, res) { | |
var _id = req.params.id; | |
peopleRepositoy.findById(_id, function(err, result) { | |
if (err) { | |
return res.send(404, { | |
'error': err | |
}) | |
}; | |
return res.send(result); | |
}); | |
}, | |
create: function(req, res) { | |
var model = req.body; | |
peopleRepositoy.create(model, function(err, result) { | |
if (err) return res.send(422, { | |
'error': err | |
}); | |
return res.send(result); | |
}); | |
}, |
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
module.exports = function(app) { | |
var PeopleSchema = app.models.People; | |
var People = db.model('People', PeopleSchema); | |
var PeopleRepositoy = { | |
create: function(model, callback) { | |
People.create(model, callback); | |
}, | |
find: function(callback) { | |
People.find({}).find().populate('Addresses.Address').exec(callback); | |
}, | |
findById: function(id, callback) { | |
People.findById(id, function(err, doc) { | |
callback(err, doc); | |
}) | |
}, | |
} | |
return PeopleRepositoy | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment