2015-10-06 16:36:56 +03:00
|
|
|
/**
|
|
|
|
* Dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Promise = require('bluebird'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
|
|
|
|
exports,
|
2014-07-13 15:17:18 +04:00
|
|
|
models;
|
2013-06-01 18:47:41 +04:00
|
|
|
|
2015-10-06 16:36:56 +03:00
|
|
|
/**
|
|
|
|
* Expose all models
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports = module.exports;
|
|
|
|
|
|
|
|
models = [
|
|
|
|
'accesstoken',
|
|
|
|
'app-field',
|
|
|
|
'app-setting',
|
|
|
|
'app',
|
|
|
|
'client-trusted-domain',
|
|
|
|
'client',
|
|
|
|
'permission',
|
|
|
|
'post',
|
|
|
|
'refreshtoken',
|
|
|
|
'role',
|
|
|
|
'settings',
|
|
|
|
'tag',
|
|
|
|
'user'
|
|
|
|
];
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
exports.Base = require('./base');
|
|
|
|
|
|
|
|
models.forEach(function (name) {
|
|
|
|
_.extend(exports, require('./' + name));
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: move to some other place
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ### deleteAllContent
|
|
|
|
// Delete all content from the database (posts, tags, tags_posts)
|
|
|
|
exports.deleteAllContent = function deleteAllContent() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
return self.Post.findAll().then(function then(posts) {
|
|
|
|
return Promise.all(_.map(posts.toJSON(), function mapper(post) {
|
|
|
|
return self.Post.destroy({id: post.id});
|
|
|
|
}));
|
|
|
|
}).then(function () {
|
|
|
|
return self.Tag.findAll().then(function then(tags) {
|
|
|
|
return Promise.all(_.map(tags.toJSON(), function mapper(tag) {
|
|
|
|
return self.Tag.destroy({id: tag.id});
|
2014-03-24 17:49:23 +04:00
|
|
|
}));
|
2013-12-25 04:05:20 +04:00
|
|
|
});
|
2015-10-06 16:36:56 +03:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
};
|
2014-07-13 15:17:18 +04:00
|
|
|
|
2015-10-06 16:36:56 +03:00
|
|
|
/**
|
|
|
|
* Expose `init`
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.init = init;
|