mirror of
https://github.com/wassname/talk.git
synced 2026-07-25 13:30:59 +08:00
Adds one method.
This commit is contained in:
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user