2014-08-17 10:17:23 +04:00
|
|
|
var _ = require('lodash'),
|
|
|
|
Promise = require('bluebird'),
|
2014-08-14 01:58:12 +04:00
|
|
|
requireTree = require('../require-tree'),
|
2014-07-13 15:17:18 +04:00
|
|
|
models;
|
2013-06-01 18:47:41 +04:00
|
|
|
|
2014-07-13 15:17:18 +04:00
|
|
|
models = {
|
2015-06-14 18:58:49 +03:00
|
|
|
excludeFiles: ['_messages', 'base', 'index.js'],
|
2013-11-24 18:29:36 +04:00
|
|
|
|
2014-08-14 01:58:12 +04:00
|
|
|
// ### init
|
|
|
|
// Scan all files in this directory and then require each one and cache
|
|
|
|
// the objects exported onto this `models` object so that every other
|
|
|
|
// module can safely access models without fear of introducing circular
|
|
|
|
// dependency issues.
|
|
|
|
// @returns {Promise}
|
2015-06-14 18:58:49 +03:00
|
|
|
init: function init() {
|
2014-08-14 01:58:12 +04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// One off inclusion of Base file.
|
|
|
|
self.Base = require('./base');
|
|
|
|
|
|
|
|
// Require all files in this directory
|
2015-06-14 18:58:49 +03:00
|
|
|
return requireTree.readAll(__dirname, {followSymlinks: false}).then(function then(modelFiles) {
|
2014-08-14 01:58:12 +04:00
|
|
|
// For each found file, excluding those we don't want,
|
|
|
|
// we will require it and cache it here.
|
2015-06-14 18:58:49 +03:00
|
|
|
_.each(modelFiles, function each(path, fileName) {
|
2014-08-14 01:58:12 +04:00
|
|
|
// Return early if this fileName is one of the ones we want
|
|
|
|
// to exclude.
|
|
|
|
if (_.contains(self.excludeFiles, fileName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Require the file.
|
|
|
|
var file = require(path);
|
|
|
|
|
|
|
|
// Cache its `export` object onto this object.
|
|
|
|
_.extend(self, file);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
});
|
2013-08-03 19:11:16 +04:00
|
|
|
},
|
2013-12-25 04:05:20 +04:00
|
|
|
// ### deleteAllContent
|
|
|
|
// Delete all content from the database (posts, tags, tags_posts)
|
2015-06-14 18:58:49 +03:00
|
|
|
deleteAllContent: function deleteAllContent() {
|
2013-12-25 04:05:20 +04:00
|
|
|
var self = this;
|
|
|
|
|
2015-06-14 18:58:49 +03:00
|
|
|
return self.Post.findAll().then(function then(posts) {
|
|
|
|
return Promise.all(_.map(posts.toJSON(), function mapper(post) {
|
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
|
|
|
return self.Post.destroy({id: post.id});
|
2014-03-24 17:49:23 +04:00
|
|
|
}));
|
2013-12-25 04:05:20 +04:00
|
|
|
}).then(function () {
|
2015-06-14 18:58:49 +03:00
|
|
|
return self.Tag.findAll().then(function then(tags) {
|
|
|
|
return Promise.all(_.map(tags.toJSON(), function mapper(tag) {
|
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
|
|
|
return self.Tag.destroy({id: tag.id});
|
2014-03-24 17:49:23 +04:00
|
|
|
}));
|
2013-12-25 04:05:20 +04:00
|
|
|
});
|
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
}
|
|
|
|
};
|
2014-07-13 15:17:18 +04:00
|
|
|
|
|
|
|
module.exports = models;
|