update api errormanager

This commit is contained in:
Jay
2017-06-03 21:20:34 +08:00
parent e0dcf3bd6c
commit 2da1836d44
6 changed files with 24 additions and 13 deletions
+7 -3
View File
@@ -7,9 +7,13 @@ const tokenSchema = mongoose.Schema({
default: Date.now
}
});
// tokenSchema.method.clearExpire = function(cb) {
// return this.model('token').remove({ expire: { $lte: Date.now() } }, cb);
// }
tokenSchema.statics.clearExpire = function(cb) {
console.log(Date.now())
return this.remove({ expire: { $lte: Date.now() } }, cb);
}
tokenSchema.statics.renewToken = function(id, expire, cb) {
return this.update({ _id: mongoose.Schema.Types.ObjectId(id) }, { $set: { expire: Date.now() + 86400000 } }, cb);
}
const token = mongoose.model('token', tokenSchema, 'token');