Adds one method.

This commit is contained in:
gaba
2016-11-02 09:21:05 -07:00
parent 4494c44677
commit 85b7096cec
3 changed files with 44 additions and 3 deletions
+19
View File
@@ -17,6 +17,25 @@ const AssetSchema = new Schema({
_id: false
});
/**
* Finds an asset by the id.
* @param {String} id identifier of the asset (uuid)
*/
AssetSchema.methods.findById = function(id, done) {
Asset.findOne({
id : id
}, (err, asset) => {
if (err) {
return done(err);
}
if (!asset) {
return done(null, false);
}
return done(null, asset);
});
};
const Asset = mongoose.model('Asset', AssetSchema);
module.exports = Asset;
+2 -2
View File
@@ -49,8 +49,8 @@ const CommentSchema = new Schema({
});
/**
* Finds a user by the id.
* @param {String} id identifier of the user (uuid)
* Finds a comment by the id.
* @param {String} id identifier of the comment (uuid)
*/
CommentSchema.methods.findById = function(id, done) {
Comment.findOne({
+23 -1
View File
@@ -10,13 +10,35 @@ const UserSchema = new Schema({
default: uuid.v4,
unique: true
},
name: String,
name: {
type: String,
unique: true
},
created_at: { type: Date, default: Date.now },
updated_at: { type: Date, default: Date.now }
},{
_id: false
});
/**
* Finds a user by the id.
* @param {String} id identifier of the user (uuid)
*/
UserSchema.methods.findById = function(id, done) {
User.findOne({
id : id
}, (err, user) => {
if (err) {
return done(err);
}
if (!user) {
return done(null, false);
}
return done(null, user);
});
};
const User = mongoose.model('User', UserSchema);
module.exports = User;