};
-// Updates an existing report in the DB.
-exports.update = function (req, res) {
- if (req.body._id) {
- delete req.body._id;
- }
- Report.findById(req.params.id, function (err, report) {
- if (err) {
- return handleError(res, err);
- }
- if (!report) {
- return res.status(404).send('Not Found');
- }
- var updated = _.merge(report, req.body);
- updated.save(function (err) {
- if (err) {
- return handleError(res, err);
- }
- return res.status(200).json(report);
- });
- });
-};
-
-// Deletes a report from the DB.
-exports.destroy = function (req, res) {
- Report.findById(req.params.id, function (err, report) {
- if (err) {
- return handleError(res, err);
- }
- if (!report) {
- return res.status(404).send('Not Found');
- }
- report.remove(function (err) {
- if (err) {
- return handleError(res, err);
- }
- return res.status(204).send('No Content');
- });
- });
-};
-
// Deletes all report from the DB as a user
-exports.purge = function (req, res) {
+exports.removeAll = function (req, res) {
Report.find({isGenerated: true}, function (err, reports) {
if (err) {
return handleError(res, err);
}
- if (!reports) {
- return res.status(404).send('Not Found');
- }
reports.forEach(function (report) {
var uuid = report.uuid;
report.remove(function (err) {
};
// Suppression de tous les rapports dans la base et dans le FS - Utilisé par le cron
-exports.removeAll = function () {
+exports.purge = function (cb) {
Report.remove({}, function (err, reportsRemoved) {
if (err) {
console.error(err);
// AND input files
utils.file.deleteFolderRecursive(appDir + "/components/worker/generator/input/", false);
console.info("Cron status : " + reportsRemoved);
+ if (typeof cb === 'function') {
+ cb();
+ }
});
};