2013-11-24 18:29:36 +04:00
|
|
|
var ghostBookshelf = require('./base'),
|
2014-02-19 17:57:26 +04:00
|
|
|
|
2014-07-14 16:29:45 +04:00
|
|
|
Basetoken;
|
2013-11-24 18:29:36 +04:00
|
|
|
|
2014-07-14 16:29:45 +04:00
|
|
|
Basetoken = ghostBookshelf.Model.extend({
|
2013-11-24 18:29:36 +04:00
|
|
|
|
2014-07-14 16:29:45 +04:00
|
|
|
user: function () {
|
|
|
|
return this.belongsTo('User');
|
|
|
|
},
|
|
|
|
|
|
|
|
client: function () {
|
|
|
|
return this.belongsTo('Client');
|
|
|
|
},
|
2014-04-03 17:03:09 +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());
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
}
|
2013-11-24 18:29:36 +04:00
|
|
|
|
|
|
|
}, {
|
2014-07-14 16:29:45 +04:00
|
|
|
destroyAllExpired: function (options) {
|
2014-05-06 05:45:08 +04:00
|
|
|
options = this.filterOptions(options, 'destroyAll');
|
2014-07-14 16:29:45 +04:00
|
|
|
return ghostBookshelf.Collection.forge([], {model: this})
|
|
|
|
.query('where', 'expires', '<', Date.now())
|
|
|
|
.fetch()
|
2014-02-27 06:44:09 +04:00
|
|
|
.then(function (collection) {
|
2013-11-24 18:29:36 +04:00
|
|
|
collection.invokeThen('destroy', options);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-14 16:29:45 +04:00
|
|
|
module.exports = Basetoken;
|