Browse Source

refactor(Admin/Reports): added update events when reports update

Kristian Vos 3 years ago
parent
commit
c45199345c
2 changed files with 33 additions and 0 deletions
  1. 28 0
      backend/logic/actions/reports.js
  2. 5 0
      frontend/src/pages/Admin/Songs/Reports.vue

+ 28 - 0
backend/logic/actions/reports.js

@@ -67,6 +67,24 @@ CacheModule.runJob("SUB", {
 		})
 });
 
+CacheModule.runJob("SUB", {
+	channel: "report.update",
+	cb: async data => {
+		const { reportId } = data;
+
+		const reportModel = await DBModule.runJob("GET_MODEL", {
+			modelName: "report"
+		});
+
+		reportModel.findOne({ _id: reportId }, (err, report) => {
+			WSModule.runJob("EMIT_TO_ROOMS", {
+				rooms: ["admin.reports", `view-report.${reportId}`],
+				args: ["event:admin.report.updated", { data: { report } }]
+			})
+		});
+	}
+});
+
 export default {
 	/**
 	 * Gets reports, used in the admin reports page by the AdvancedTable component
@@ -399,6 +417,11 @@ export default {
 					value: { reportId, songId, resolved }
 				});
 
+				CacheModule.runJob("PUB", {
+					channel: "report.update",
+					value: { reportId }
+				});
+
 				this.log(
 					"SUCCESS",
 					"REPORTS_RESOLVE",
@@ -458,6 +481,11 @@ export default {
 					value: { reportId, issueId, songId, resolved }
 				});
 
+				CacheModule.runJob("PUB", {
+					channel: "report.update",
+					value: { reportId }
+				});
+
 				this.log(
 					"SUCCESS",
 					"REPORTS_TOGGLE_ISSUE",

+ 5 - 0
frontend/src/pages/Admin/Songs/Reports.vue

@@ -237,6 +237,11 @@ export default {
 			],
 			events: {
 				adminRoom: "reports",
+				updated: {
+					event: "admin.report.updated",
+					id: "report._id",
+					item: "report"
+				},
 				removed: {
 					event: "admin.report.removed",
 					id: "reportId"