c02ebb0dcf
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
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
var ghostBookshelf = require('./base'),
|
|
|
|
Session,
|
|
Sessions;
|
|
|
|
Session = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'sessions',
|
|
|
|
// 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());
|
|
}
|
|
|
|
}, {
|
|
destroyAll: function (options) {
|
|
options = this.filterOptions(options, 'destroyAll');
|
|
return ghostBookshelf.Collection.forge([], {model: this}).fetch()
|
|
.then(function (collection) {
|
|
collection.invokeThen('destroy', options);
|
|
});
|
|
}
|
|
});
|
|
|
|
Sessions = ghostBookshelf.Collection.extend({
|
|
model: Session
|
|
});
|
|
|
|
module.exports = {
|
|
Session: Session,
|
|
Sessions: Sessions
|
|
};
|