lora-project/server-api/libs/mongo_model.js
2017-06-03 21:20:34 +08:00

22 lines
583 B
JavaScript

const mongoose = require('mongoose');
const tokenSchema = mongoose.Schema({
object: Object,
expire: {
type: Number,
default: Date.now
}
});
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');
module.exports = {
token
}