Browse Source

Added pub/sub for creating reports

theflametrooper 8 years ago
parent
commit
f7e419751f
2 changed files with 12 additions and 2 deletions
  1. 9 2
      backend/logic/actions/reports.js
  2. 3 0
      frontend/components/Admin/Reports.vue

+ 9 - 2
backend/logic/actions/reports.js

@@ -12,6 +12,10 @@ cache.sub('report.resolve', reportId => {
 	utils.emitToRoom('admin.reports', 'event:admin.report.resolved', reportId);
 });
 
+cache.sub('report.create', report => {
+	utils.emitToRoom('admin.reports', 'event:admin.report.created', report);
+});
+
 module.exports = {
 
 	index: hooks.adminRequired((session, cb) => {
@@ -114,9 +118,12 @@ module.exports = {
 				db.models.report.create(data, next);
 			}
 
-		], err => {
+		], (err, report) => {
 			if (err) return cb({ 'status': 'failure', 'message': 'Something went wrong'});
-			return cb({ 'status': 'success', 'message': 'Successfully created report' });
+			else {
+				cache.pub('report.create', report);
+				return cb({ 'status': 'success', 'message': 'Successfully created report' });
+			}
 		});
 	})
 

+ 3 - 0
frontend/components/Admin/Reports.vue

@@ -78,6 +78,9 @@
 						return report._id !== reportId;
 					});
 				});
+				_this.socket.on('event:admin.report.created', report => {
+					_this.reports.push(report);
+				});
 				io.onConnect(() => {
 					_this.init();
 				});