| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | 
							- 'use strict';
 
- const coreClass = require("../core");
 
- const async = require('async');
 
- const mongoose = require('mongoose');
 
- module.exports = class extends coreClass {
 
- 	constructor(name, moduleManager) {
 
- 		super(name, moduleManager);
 
- 		this.dependsOn = ["db", "utils"];
 
- 	}
 
- 	initialize() {
 
- 		return new Promise((resolve, reject) => {
 
- 			this.setStage(1);
 
- 			this.db = this.moduleManager.modules["db"];
 
- 			this.io = this.moduleManager.modules["io"];
 
- 			this.utils = this.moduleManager.modules["utils"];
 
- 			resolve();
 
- 		});
 
- 	}
 
- 	/**
 
- 	 * 
 
- 	 * @param {String} userId - the id of the user 
 
- 	 * @param {String} activityType - what type of activity the user has completed e.g. liked a song
 
- 	 * @param {Array} payload - what the activity was specifically related to e.g. the liked song(s)
 
- 	 */
 
- 	async addActivity(userId, activityType, payload) {
 
- 		try { await this._validateHook(); } catch { return; }
 
- 		async.waterfall([
 
- 			next => {
 
- 				const activity = new this.db.models.activity({
 
- 					userId,
 
- 					activityType,
 
- 					payload
 
- 				});
 
- 				activity.save((err, activity) => {
 
- 					if (err) return next(err);
 
- 					next(null, activity);
 
- 				});
 
- 			},
 
- 			(activity, next) => {
 
- 				this.utils.socketsFromUser(activity.userId, sockets => {
 
- 					sockets.forEach(socket => {
 
- 						socket.emit('event:activity.create', activity);
 
- 					});
 
- 				});
 
- 			}
 
- 		], (err, activity) => {
 
- 			// cb(err, activity);
 
- 		});
 
- 	}
 
- }
 
 
  |