Browse Source

fix: fixed report modal and added song's _id to reports

Kristian Vos 5 years ago
parent
commit
e507cf9ab7

+ 8 - 3
backend/logic/actions/reports.js

@@ -110,7 +110,7 @@ module.exports = {
 	}),
 
 	/**
-	 * Gets all reports for a songId
+	 * Gets all reports for a songId (_id)
 	 *
 	 * @param {Object} session - the session object automatically added by socket.io
 	 * @param {String} songId - the id of the song to index reports for
@@ -119,7 +119,7 @@ module.exports = {
 	getReportsForSong: hooks.adminRequired((session, songId, cb) => {
 		async.waterfall([
 			(next) => {
-				db.models.report.find({ songId, resolved: false }).sort({ released: 'desc' }).exec(next);
+				db.models.report.find({ song: { _id: songId }, resolved: false }).sort({ released: 'desc' }).exec(next);
 			},
 
 			(reports, next) => {
@@ -199,6 +199,11 @@ module.exports = {
 			(song, next) => {
 				if (!song) return next('Song not found.');
 
+				delete data.songId;
+				data.song = {
+					_id: song._id,
+					songId: song.songId
+				}
 
 				for (let z = 0; z < data.issues.length; z++) {
 					if (reportableIssues.filter(issue => { return issue.name == data.issues[z].name; }).length > 0) {
@@ -234,7 +239,7 @@ module.exports = {
 		], async (err, report) => {
 			if (err) {
 				err = await utils.getError(err);
-				logger.error("REPORTS_CREATE", `Creating report for "${data.songId}" failed by user "${userId}". "${err}"`);
+				logger.error("REPORTS_CREATE", `Creating report for "${data.song._id}" failed by user "${userId}". "${err}"`);
 				return cb({ 'status': 'failure', 'message': err });
 			} else {
 				cache.pub('report.create', report);

+ 4 - 1
backend/logic/db/schemas/report.js

@@ -1,6 +1,9 @@
 module.exports = {
 	resolved: { type: Boolean, default: false, required: true },
-	songId: { type: String, required: true },
+	song: {
+		_id: { type: String, required: true },
+		songId: { type: String, required: true },
+	},
 	description: { type: String },
 	issues: [{
 		name: String,

+ 5 - 1
frontend/components/Admin/Reports.vue

@@ -15,7 +15,11 @@
 				<tbody>
 					<tr v-for="(report, index) in reports" :key="index">
 						<td>
-							<span>{{ report.songId }}</span>
+							<span>
+								{{ report.song.songId }}
+								<br />
+								{{ report.song._id }}
+							</span>
 						</td>
 						<td>
 							<user-id-to-username

+ 3 - 1
frontend/components/Modals/Report.vue

@@ -164,7 +164,7 @@ export default {
 			isCurrentSongActive: true,
 			report: {
 				resolved: false,
-				songId: this.currentSong.songId,
+				songId: "",
 				description: "",
 				issues: [
 					{ name: "Video", reasons: [] },
@@ -215,6 +215,8 @@ export default {
 		io.getSocket(socket => {
 			this.socket = socket;
 		});
+
+		this.report.songId = this.currentSong.songId;
 	},
 	methods: {
 		create() {

+ 1 - 1
frontend/store/modules/station.js

@@ -6,7 +6,7 @@ const state = {
 	userCount: 0,
 	users: [],
 	currentSong: {},
-	previousSong: {},
+	previousSong: null,
 	songsList: [],
 	paused: true,
 	noSong: true