2014-06-30 16:58:10 +04:00
|
|
|
var ghostBookshelf = require('./base'),
|
|
|
|
|
|
|
|
Accesstoken,
|
|
|
|
Accesstokens;
|
|
|
|
|
|
|
|
Accesstoken = ghostBookshelf.Model.extend({
|
|
|
|
|
|
|
|
tableName: 'accesstokens',
|
|
|
|
|
|
|
|
user: function () {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsTo('User');
|
2014-06-30 16:58:10 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
client: function () {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsTo('Client');
|
2014-06-30 16:58:10 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// override for base function since we don't have
|
|
|
|
// a created_by field for sessions
|
|
|
|
creating: function (newObj, attr, options) {
|
|
|
|
/*jshint unused:false*/
|
|
|
|
},
|
|
|
|
|
|
|
|
// override for base function since we don't have
|
|
|
|
// a updated_by field for sessions
|
|
|
|
saving: function (newObj, attr, options) {
|
|
|
|
/*jshint unused:false*/
|
|
|
|
// Remove any properties which don't belong on the model
|
|
|
|
this.attributes = this.pick(this.permittedAttributes());
|
|
|
|
}
|
|
|
|
|
|
|
|
}, {
|
|
|
|
destroyAllExpired: function (options) {
|
|
|
|
options = this.filterOptions(options, 'destroyAll');
|
|
|
|
return ghostBookshelf.Collection.forge([], {model: this})
|
|
|
|
.query('where', 'expires', '<', Date.now())
|
|
|
|
.fetch()
|
|
|
|
.then(function (collection) {
|
|
|
|
collection.invokeThen('destroy', options);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Accesstokens = ghostBookshelf.Collection.extend({
|
|
|
|
model: Accesstoken
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
2014-07-13 15:17:18 +04:00
|
|
|
Accesstoken: ghostBookshelf.model('Accesstoken', Accesstoken),
|
|
|
|
Accesstokens: ghostBookshelf.collection('Accesstokens', Accesstokens)
|
2014-06-30 16:58:10 +04:00
|
|
|
};
|