|
@@ -5,8 +5,50 @@ const async = require('async');
|
|
|
const db = require('../db');
|
|
|
const cache = require('../cache');
|
|
|
const utils = require('../utils');
|
|
|
+const logger = require('../logger');
|
|
|
const hooks = require('./hooks');
|
|
|
const songs = require('../songs');
|
|
|
+const reportableIssues = [
|
|
|
+ {
|
|
|
+ name: 'Video',
|
|
|
+ reasons: [
|
|
|
+ 'Doesn\'t exist',
|
|
|
+ 'It\'s private',
|
|
|
+ 'It\'s not available in my country'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'Title',
|
|
|
+ reasons: [
|
|
|
+ 'Incorrect',
|
|
|
+ 'Inappropriate'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'Duration',
|
|
|
+ reasons: [
|
|
|
+ 'Skips too soon',
|
|
|
+ 'Skips too late',
|
|
|
+ 'Starts too soon',
|
|
|
+ 'Skips too late'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'Artists',
|
|
|
+ reasons: [
|
|
|
+ 'Incorrect',
|
|
|
+ 'Inappropriate'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'Thumbnail',
|
|
|
+ reasons: [
|
|
|
+ 'Incorrect',
|
|
|
+ 'Inappropriate',
|
|
|
+ 'Doesn\'t exist'
|
|
|
+ ]
|
|
|
+ }
|
|
|
+];
|
|
|
|
|
|
cache.sub('report.resolve', reportId => {
|
|
|
utils.emitToRoom('admin.reports', 'event:admin.report.resolved', reportId);
|
|
@@ -19,29 +61,40 @@ cache.sub('report.create', report => {
|
|
|
module.exports = {
|
|
|
|
|
|
index: hooks.adminRequired((session, cb) => {
|
|
|
- db.models.report.find({ resolved: false }).sort({ released: 'desc' }).exec((err, reports) => {
|
|
|
+
|
|
|
+ async.waterfall([
|
|
|
+ (next) => {
|
|
|
+ db.models.report.find({ resolved: false }).sort({ released: 'desc' }).exec(next);
|
|
|
+ }
|
|
|
+ ], (err, reports) => {
|
|
|
if (err) {
|
|
|
- console.error(err);
|
|
|
- cb({ 'status': 'failure', 'message': 'Something went wrong'});
|
|
|
+ logger.log("REPORTS_INDEX", "ERROR", `Indexing reports failed. "${err.message}"`);
|
|
|
+ return cb({ 'status': 'failure', 'message': 'Something went wrong'});
|
|
|
}
|
|
|
+ logger.log("REPORTS_INDEX", "SUCCESS", "Indexing reports successful.");
|
|
|
cb({ status: 'success', data: reports });
|
|
|
});
|
|
|
}),
|
|
|
|
|
|
- resolve: hooks.adminRequired((session, _id, cb) => {
|
|
|
- db.models.report.findOne({ _id }).sort({ released: 'desc' }).exec((err, report) => {
|
|
|
+ resolve: hooks.adminRequired((session, reportId, cb, userId) => {
|
|
|
+ async.waterfall([
|
|
|
+ (next) => {
|
|
|
+ db.models.report.findOne({ _id: reportId }).sort({ released: 'desc' }).exec(next);
|
|
|
+ },
|
|
|
+
|
|
|
+ (report, next) => {
|
|
|
+ if (!report) return next('Report not found.');
|
|
|
+ db.models.update({ _id: reportId }, next);
|
|
|
+ }
|
|
|
+ ], (err) => {
|
|
|
if (err) {
|
|
|
- console.error(err);
|
|
|
- cb({ 'status': 'failure', 'message': 'Something went wrong'});
|
|
|
+ logger.log("REPORTS_RESOLVE", "ERROR", `Resolving report "${reportId}" failed. Mongo error. "${err.message}"`);
|
|
|
+ return cb({ 'status': 'failure', 'message': 'Something went wrong'});
|
|
|
+ } else {
|
|
|
+ cache.pub('report.resolve', reportId);
|
|
|
+ logger.log("REPORTS_RESOLVE", "SUCCESS", `"${userId}" resolved report "${reportId}".`);
|
|
|
+ cb({ status: 'success', message: 'Successfully resolved Report' });
|
|
|
}
|
|
|
- report.resolved = true;
|
|
|
- report.save(err => {
|
|
|
- if (err) console.error(err);
|
|
|
- else {
|
|
|
- cache.pub('report.resolve', _id);
|
|
|
- cb({ status: 'success', message: 'Successfully resolved Report' });
|
|
|
- }
|
|
|
- });
|
|
|
});
|
|
|
}),
|
|
|
|
|
@@ -49,60 +102,17 @@ module.exports = {
|
|
|
async.waterfall([
|
|
|
|
|
|
(next) => {
|
|
|
- songs.getSong(data.songId, (err, song) => {
|
|
|
- if (err) return next(err);
|
|
|
- if (!song) return next('Song does not exist in our Database');
|
|
|
- next();
|
|
|
- });
|
|
|
+ songs.getSong(data.songId, next);
|
|
|
},
|
|
|
|
|
|
- (next) => {
|
|
|
- let issues = [
|
|
|
- {
|
|
|
- name: 'Video',
|
|
|
- reasons: [
|
|
|
- 'Doesn\'t exist',
|
|
|
- 'It\'s private',
|
|
|
- 'It\'s not available in my country'
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Title',
|
|
|
- reasons: [
|
|
|
- 'Incorrect',
|
|
|
- 'Inappropriate'
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Duration',
|
|
|
- reasons: [
|
|
|
- 'Skips too soon',
|
|
|
- 'Skips too late',
|
|
|
- 'Starts too soon',
|
|
|
- 'Skips too late'
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Artists',
|
|
|
- reasons: [
|
|
|
- 'Incorrect',
|
|
|
- 'Inappropriate'
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Thumbnail',
|
|
|
- reasons: [
|
|
|
- 'Incorrect',
|
|
|
- 'Inappropriate',
|
|
|
- 'Doesn\'t exist'
|
|
|
- ]
|
|
|
- }
|
|
|
- ];
|
|
|
+ (song, next) => {
|
|
|
+ if (!song) return next('Song not found.');
|
|
|
+
|
|
|
|
|
|
for (let z = 0; z < data.issues.length; z++) {
|
|
|
- if (issues.filter(issue => { return issue.name == data.issues[z].name; }).length > 0) {
|
|
|
+ if (reportableIssues.filter(issue => { return issue.name == data.issues[z].name; }).length > 0) {
|
|
|
for (let r = 0; r < issues.length; r++) {
|
|
|
- if (issues[r].reasons.every(reason => data.issues[z].reasons.indexOf(reason) < -1)) {
|
|
|
+ if (reportableIssues[r].reasons.every(reason => data.issues[z].reasons.indexOf(reason) < -1)) {
|
|
|
return cb({ 'status': 'failure', 'message': 'Invalid data' });
|
|
|
}
|
|
|
}
|
|
@@ -131,9 +141,16 @@ module.exports = {
|
|
|
}
|
|
|
|
|
|
], (err, report) => {
|
|
|
- if (err) return cb({ 'status': 'failure', 'message': 'Something went wrong' });
|
|
|
+ if (err) {
|
|
|
+ let error = 'An error occurred.';
|
|
|
+ if (typeof err === "string") error = err;
|
|
|
+ else if (err.message) error = err.message;
|
|
|
+ logger.log("REPORTS_CREATE", "ERROR", `Creating report for "${data.songId}" failed. "${error}"`);
|
|
|
+ return cb({ 'status': 'failure', 'message': 'Something went wrong' });
|
|
|
+ }
|
|
|
else {
|
|
|
cache.pub('report.create', report);
|
|
|
+ logger.log("REPORTS_CREATE", "SUCCESS", `"${userId}" created report for "${data.songId}".`);
|
|
|
return cb({ 'status': 'success', 'message': 'Successfully created report' });
|
|
|
}
|
|
|
});
|