Browse Source

Renamed modules in backend actions

Kristian Vos 4 years ago
parent
commit
e6ade1a5fe

+ 6 - 7
backend/logic/actions/activities.js

@@ -1,10 +1,9 @@
 import async from "async";
 
 import { isLoginRequired } from "./hooks";
-import db from "../db";
-import utils from "../utils";
 
-// const logger = moduleManager.modules["logger"];
+import DBModule from "../db";
+import UtilsModule from "../utils";
 
 export default {
 	/**
@@ -16,7 +15,7 @@ export default {
 	 * @param {Function} cb - callback
 	 */
 	getSet: async (session, userId, set, cb) => {
-		const activityModel = await db.runJob("GET_MODEL", {
+		const activityModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "activity"
 		});
 		async.waterfall(
@@ -32,7 +31,7 @@ export default {
 			],
 			async (err, activities) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "ACTIVITIES_GET_SET", `Failed to get set ${set} from activities. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -51,7 +50,7 @@ export default {
 	 * @param cb
 	 */
 	hideActivity: isLoginRequired(async (session, activityId, cb) => {
-		const activityModel = await db.runJob("GET_MODEL", {
+		const activityModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "activity"
 		});
 		async.waterfall(
@@ -62,7 +61,7 @@ export default {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "ACTIVITIES_HIDE_ACTIVITY", `Failed to hide activity ${activityId}. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}

+ 9 - 13
backend/logic/actions/apis.js

@@ -1,14 +1,11 @@
 import config from "config";
-
 import async from "async";
-
 import request from "request";
+
 import { isAdminRequired } from "./hooks";
 // const moduleManager = require("../../index");
 
-import utils from "../utils";
-
-// const logger = moduleManager.modules["logger"];
+import UtilsModule from "../utils";
 
 export default {
 	/**
@@ -42,7 +39,7 @@ export default {
 				console.log(data.error);
 				if (err || data.error) {
 					if (!err) err = data.error.message;
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"APIS_SEARCH_YOUTUBE",
@@ -89,7 +86,7 @@ export default {
 			],
 			async (err, body) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"APIS_SEARCH_DISCOGS",
@@ -120,11 +117,10 @@ export default {
 	 */
 	joinRoom: (session, page, cb) => {
 		if (page === "home") {
-			utils
-				.runJob("SOCKET_JOIN_ROOM", {
-					socketId: session.socketId,
-					room: page
-				})
+			UtilsModule.runJob("SOCKET_JOIN_ROOM", {
+				socketId: session.socketId,
+				room: page
+			})
 				.then()
 				.catch(err => {
 					console.log("ERROR", `Joining room failed: ${err.message}`);
@@ -151,7 +147,7 @@ export default {
 			page === "statistics" ||
 			page === "punishments"
 		) {
-			utils.runJob("SOCKET_JOIN_ROOM", {
+			UtilsModule.runJob("SOCKET_JOIN_ROOM", {
 				socketId: session.socketId,
 				room: `admin.${page}`
 			});

+ 9 - 10
backend/logic/actions/hooks/adminRequired.js

@@ -1,22 +1,21 @@
 import async from "async";
 
-import db from "../../db";
-import cache from "../../cache";
-import utils from "../../utils";
+import DBModule from "../../db";
+import CacheModule from "../../cache";
+import UtilsModule from "../../utils";
 
 export default destination => async (session, ...args) => {
-	const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+	const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 	const cb = args[args.length - 1];
 
 	async.waterfall(
 		[
 			next => {
-				cache
-					.runJob("HGET", {
-						table: "sessions",
-						key: session.sessionId
-					})
+				CacheModule.runJob("HGET", {
+					table: "sessions",
+					key: session.sessionId
+				})
 					.then(session => {
 						next(null, session);
 					})
@@ -34,7 +33,7 @@ export default destination => async (session, ...args) => {
 		],
 		async err => {
 			if (err) {
-				err = await utils.runJob("GET_ERROR", { error: err });
+				err = await UtilsModule.runJob("GET_ERROR", { error: err });
 				console.log("INFO", "ADMIN_REQUIRED", `User failed to pass admin required check. "${err}"`);
 				return cb({ status: "failure", message: err });
 			}

+ 7 - 9
backend/logic/actions/hooks/loginRequired.js

@@ -1,8 +1,7 @@
 import async from "async";
 
-import cache from "../../cache";
-import utils from "../../utils";
-// const logger = moduleManager.modules["logger"];
+import CacheModule from "../../cache";
+import UtilsModule from "../../utils";
 
 export default destination => (session, ...args) => {
 	const cb = args[args.length - 1];
@@ -10,11 +9,10 @@ export default destination => (session, ...args) => {
 	async.waterfall(
 		[
 			next => {
-				cache
-					.runJob("HGET", {
-						table: "sessions",
-						key: session.sessionId
-					})
+				CacheModule.runJob("HGET", {
+					table: "sessions",
+					key: session.sessionId
+				})
 					.then(session => next(null, session))
 					.catch(next);
 			},
@@ -25,7 +23,7 @@ export default destination => (session, ...args) => {
 		],
 		async err => {
 			if (err) {
-				err = await utils.runJob("GET_ERROR", { error: err });
+				err = await UtilsModule.runJob("GET_ERROR", { error: err });
 				console.log("LOGIN_REQUIRED", `User failed to pass login required check.`);
 				return cb({ status: "failure", message: err });
 			}

+ 11 - 13
backend/logic/actions/hooks/ownerRequired.js

@@ -1,23 +1,22 @@
 import async from "async";
 
-import db from "../../db";
-import cache from "../../cache";
-import utils from "../../utils";
-import stations from "../../stations";
+import DBModule from "../../db";
+import CacheModule from "../../cache";
+import UtilsModule from "../../utils";
+import StationsModule from "../../stations";
 
 export default destination => async (session, stationId, ...args) => {
-	const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+	const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 	const cb = args[args.length - 1];
 
 	async.waterfall(
 		[
 			next => {
-				cache
-					.runJob("HGET", {
-						table: "sessions",
-						key: session.sessionId
-					})
+				CacheModule.runJob("HGET", {
+					table: "sessions",
+					key: session.sessionId
+				})
 					.then(session => {
 						next(null, session);
 					})
@@ -30,8 +29,7 @@ export default destination => async (session, stationId, ...args) => {
 			(user, next) => {
 				if (!user) return next("Login required.");
 				if (user.role === "admin") return next(true);
-				return stations
-					.runJob("GET_STATION", { stationId })
+				return StationsModule.runJob("GET_STATION", { stationId })
 					.then(station => {
 						next(null, station);
 					})
@@ -45,7 +43,7 @@ export default destination => async (session, stationId, ...args) => {
 		],
 		async err => {
 			if (err !== true) {
-				err = await utils.runJob("GET_ERROR", { error: err });
+				err = await UtilsModule.runJob("GET_ERROR", { error: err });
 				console.log(
 					"INFO",
 					"OWNER_REQUIRED",

+ 22 - 24
backend/logic/actions/news.js

@@ -2,36 +2,34 @@ import async from "async";
 
 import { isAdminRequired } from "./hooks";
 
-import db from "../db";
-import utils from "../utils";
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import CacheModule from "../cache";
 
-import cache from "../cache";
-// const logger = require("logger");
-
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "news.create",
 	cb: news => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.news",
 			args: ["event:admin.news.created", news]
 		});
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "news.remove",
 	cb: news => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.news",
 			args: ["event:admin.news.removed", news]
 		});
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "news.update",
 	cb: news => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.news",
 			args: ["event:admin.news.updated", news]
 		});
@@ -46,7 +44,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	index: async (session, cb) => {
-		const newsModel = await db.runJob("GET_MODEL", { modelName: "news" });
+		const newsModel = await DBModule.runJob("GET_MODEL", { modelName: "news" });
 		async.waterfall(
 			[
 				next => {
@@ -55,7 +53,7 @@ export default {
 			],
 			async (err, news) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "NEWS_INDEX", `Indexing news failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -73,7 +71,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	create: isAdminRequired(async (session, data, cb) => {
-		const newsModel = await db.runJob("GET_MODEL", { modelName: "news" });
+		const newsModel = await DBModule.runJob("GET_MODEL", { modelName: "news" });
 		async.waterfall(
 			[
 				next => {
@@ -84,11 +82,11 @@ export default {
 			],
 			async (err, news) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "NEWS_CREATE", `Creating news failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", { channel: "news.create", value: news });
+				CacheModule.runJob("PUB", { channel: "news.create", value: news });
 				console.log("SUCCESS", "NEWS_CREATE", `Creating news successful.`);
 				return cb({
 					status: "success",
@@ -105,7 +103,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	newest: async (session, cb) => {
-		const newsModel = await db.runJob("GET_MODEL", { modelName: "news" });
+		const newsModel = await DBModule.runJob("GET_MODEL", { modelName: "news" });
 		async.waterfall(
 			[
 				next => {
@@ -114,7 +112,7 @@ export default {
 			],
 			async (err, news) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "NEWS_NEWEST", `Getting the latest news failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -134,10 +132,10 @@ export default {
 	// TODO Pass in an id, not an object
 	// TODO Fix this
 	remove: isAdminRequired(async (session, news, cb) => {
-		const newsModel = await db.runJob("GET_MODEL", { modelName: "news" });
+		const newsModel = await DBModule.runJob("GET_MODEL", { modelName: "news" });
 		newsModel.deleteOne({ _id: news._id }, async err => {
 			if (err) {
-				err = await utils.runJob("GET_ERROR", { error: err });
+				err = await UtilsModule.runJob("GET_ERROR", { error: err });
 				console.log(
 					"ERROR",
 					"NEWS_REMOVE",
@@ -145,7 +143,7 @@ export default {
 				);
 				return cb({ status: "failure", message: err });
 			}
-			cache.runJob("PUB", { channel: "news.remove", value: news });
+			CacheModule.runJob("PUB", { channel: "news.remove", value: news });
 			console.log(
 				"SUCCESS",
 				"NEWS_REMOVE",
@@ -168,10 +166,10 @@ export default {
 	 */
 	// TODO Fix this
 	update: isAdminRequired(async (session, _id, news, cb) => {
-		const newsModel = await db.runJob("GET_MODEL", { modelName: "news" });
+		const newsModel = await DBModule.runJob("GET_MODEL", { modelName: "news" });
 		newsModel.updateOne({ _id }, news, { upsert: true }, async err => {
 			if (err) {
-				err = await utils.runJob("GET_ERROR", { error: err });
+				err = await UtilsModule.runJob("GET_ERROR", { error: err });
 				console.log(
 					"ERROR",
 					"NEWS_UPDATE",
@@ -179,7 +177,7 @@ export default {
 				);
 				return cb({ status: "failure", message: err });
 			}
-			cache.runJob("PUB", { channel: "news.update", value: news });
+			CacheModule.runJob("PUB", { channel: "news.update", value: news });
 			console.log("SUCCESS", "NEWS_UPDATE", `Updating news "${_id}" successful for user "${session.userId}".`);
 			return cb({
 				status: "success",

+ 74 - 93
backend/logic/actions/playlists.js

@@ -2,22 +2,20 @@ import async from "async";
 
 import { isLoginRequired } from "./hooks";
 
-import db from "../db";
-import utils from "../utils";
-import songs from "../songs";
-
-import cache from "../cache";
-
 import moduleManager from "../../index";
 
-import playlists from "../playlists";
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import SongsModule from "../songs";
+import CacheModule from "../cache";
+import PlaylistsModule from "../playlists";
 import YouTubeModule from "../youtube";
-import activities from "../activities";
+import ActivitiesModule from "../activities";
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.create",
 	cb: playlist => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: playlist.createdBy }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: playlist.createdBy }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.create", playlist);
 			});
@@ -25,10 +23,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.delete",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.delete", res.playlistId);
 			});
@@ -36,10 +34,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.moveSongToTop",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.moveSongToTop", {
 					playlistId: res.playlistId,
@@ -50,10 +48,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.moveSongToBottom",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.moveSongToBottom", {
 					playlistId: res.playlistId,
@@ -64,10 +62,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.addSong",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.addSong", {
 					playlistId: res.playlistId,
@@ -78,10 +76,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.removeSong",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.removeSong", {
 					playlistId: res.playlistId,
@@ -92,10 +90,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "playlist.updateDisplayName",
 	cb: res => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:playlist.updateDisplayName", {
 					playlistId: res.playlistId,
@@ -118,8 +116,7 @@ const lib = {
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -133,7 +130,7 @@ const lib = {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_GET_FIRST_SONG",
@@ -161,7 +158,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	indexForUser: isLoginRequired(async (session, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -172,7 +169,7 @@ const lib = {
 			],
 			async (err, playlists) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_INDEX_FOR_USER",
@@ -201,7 +198,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	create: isLoginRequired(async (session, data, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -223,7 +220,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_CREATE",
@@ -232,12 +229,12 @@ const lib = {
 					return cb({ status: "failure", message: err });
 				}
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.create",
 					value: playlist
 				});
 
-				activities.runJob("ADD_ACTIVITY", {
+				ActivitiesModule.runJob("ADD_ACTIVITY", {
 					userId: session.userId,
 					activityType: "created_playlist",
 					payload: [playlist._id]
@@ -271,8 +268,7 @@ const lib = {
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -286,7 +282,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_GET",
@@ -318,8 +314,7 @@ const lib = {
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -328,7 +323,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLISTS_GET_PLAYLIST_FOR_ACTIVITY",
@@ -361,7 +356,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	update: isLoginRequired(async (session, playlistId, playlist, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -376,8 +371,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -386,7 +380,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_UPDATE",
@@ -415,7 +409,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	shuffle: isLoginRequired(async (session, playlistId, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -426,8 +420,7 @@ const lib = {
 				},
 
 				(playlist, next) => {
-					utils
-						.runJob("SHUFFLE", { array: playlist.songs })
+					UtilsModule.runJob("SHUFFLE", { array: playlist.songs })
 						.then(result => {
 							next(null, result.array);
 						})
@@ -439,8 +432,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -449,7 +441,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_SHUFFLE",
@@ -481,15 +473,14 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	addSongToPlaylist: isLoginRequired(async (session, isSet, songId, playlistId, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							if (!playlist || playlist.createdBy !== session.userId)
 								return next("Something went wrong when trying to get the playlist");
@@ -506,8 +497,7 @@ const lib = {
 						.catch(next);
 				},
 				next => {
-					songs
-						.runJob("GET_SONG", { id: songId })
+					SongsModule.runJob("GET_SONG", { id: songId })
 						.then(response => {
 							const { song } = response;
 							next(null, {
@@ -530,8 +520,7 @@ const lib = {
 						{ runValidators: true },
 						err => {
 							if (err) return next(err);
-							return playlists
-								.runJob("UPDATE_PLAYLIST", { playlistId })
+							return PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 								.then(playlist => next(null, playlist, newSong))
 								.catch(next);
 						}
@@ -540,7 +529,7 @@ const lib = {
 			],
 			async (err, playlist, newSong) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_ADD_SONG",
@@ -554,13 +543,13 @@ const lib = {
 					`Successfully added song "${songId}" to private playlist "${playlistId}" for user "${session.userId}".`
 				);
 				if (!isSet)
-					activities.runJob("ADD_ACTIVITY", {
+					ActivitiesModule.runJob("ADD_ACTIVITY", {
 						userId: session.userId,
 						activityType: "added_song_to_playlist",
 						payload: [{ songId, playlistId }]
 					});
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.addSong",
 					value: {
 						playlistId: playlist._id,
@@ -633,8 +622,7 @@ const lib = {
 				},
 
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -648,7 +636,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_IMPORT",
@@ -656,7 +644,7 @@ const lib = {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				activities.runJob("ADD_ACTIVITY", {
+				ActivitiesModule.runJob("ADD_ACTIVITY", {
 					userId: session.userId,
 					activityType: "added_songs_to_playlist",
 					payload: addedSongs
@@ -690,7 +678,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	removeSongFromPlaylist: isLoginRequired(async (session, songId, playlistId, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -702,8 +690,7 @@ const lib = {
 				},
 
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -716,8 +703,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -726,7 +712,7 @@ const lib = {
 			],
 			async (err, playlist) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_REMOVE_SONG",
@@ -739,7 +725,7 @@ const lib = {
 					"PLAYLIST_REMOVE_SONG",
 					`Successfully removed song "${songId}" from private playlist "${playlistId}" for user "${session.userId}".`
 				);
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.removeSong",
 					value: {
 						playlistId: playlist._id,
@@ -764,7 +750,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateDisplayName: isLoginRequired(async (session, playlistId, displayName, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
@@ -779,8 +765,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -789,7 +774,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_UPDATE_DISPLAY_NAME",
@@ -802,7 +787,7 @@ const lib = {
 					"PLAYLIST_UPDATE_DISPLAY_NAME",
 					`Successfully updated display name to "${displayName}" for private playlist "${playlistId}" for user "${session.userId}".`
 				);
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.updateDisplayName",
 					value: {
 						playlistId,
@@ -827,14 +812,13 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	moveSongToTop: isLoginRequired(async (session, playlistId, songId, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -879,8 +863,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -889,7 +872,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_MOVE_SONG_TO_TOP",
@@ -904,7 +887,7 @@ const lib = {
 					`Successfully moved song "${songId}" to the top for private playlist "${playlistId}" for user "${session.userId}".`
 				);
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.moveSongToTop",
 					value: {
 						playlistId,
@@ -930,14 +913,13 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	moveSongToBottom: isLoginRequired(async (session, playlistId, songId, cb) => {
-		const playlistModel = await db.runJob("GET_MODEL", {
+		const playlistModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "playlist"
 		});
 		async.waterfall(
 			[
 				next => {
-					playlists
-						.runJob("GET_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -979,8 +961,7 @@ const lib = {
 				},
 
 				(res, next) => {
-					playlists
-						.runJob("UPDATE_PLAYLIST", { playlistId })
+					PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId })
 						.then(playlist => {
 							next(null, playlist);
 						})
@@ -989,7 +970,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_MOVE_SONG_TO_BOTTOM",
@@ -1004,7 +985,7 @@ const lib = {
 					`Successfully moved song "${songId}" to the bottom for private playlist "${playlistId}" for user "${session.userId}".`
 				);
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.moveSongToBottom",
 					value: {
 						playlistId,
@@ -1029,14 +1010,14 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	remove: isLoginRequired(async (session, playlistId, cb) => {
-		const stationModel = await db.runJob("GET_MODEL", {
+		const stationModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "station"
 		});
 
 		async.waterfall(
 			[
 				next => {
-					playlists.runJob("DELETE_PLAYLIST", { playlistId }).then(next).catch(next);
+					PlaylistsModule.runJob("DELETE_PLAYLIST", { playlistId }).then(next).catch(next);
 				},
 
 				next => {
@@ -1068,7 +1049,7 @@ const lib = {
 												})
 												.then(station => next(null, station))
 												.catch(next);
-											cache.runJob("PUB", {
+											CacheModule.runJob("PUB", {
 												channel: "privatePlaylist.selected",
 												value: {
 													playlistId: null,
@@ -1092,7 +1073,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"PLAYLIST_REMOVE",
@@ -1107,7 +1088,7 @@ const lib = {
 					`Successfully removed private playlist "${playlistId}" for user "${session.userId}".`
 				);
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "playlist.delete",
 					value: {
 						userId: session.userId,
@@ -1115,7 +1096,7 @@ const lib = {
 					}
 				});
 
-				activities.runJob("ADD_ACTIVITY", {
+				ActivitiesModule.runJob("ADD_ACTIVITY", {
 					userId: session.userId,
 					activityType: "deleted_playlist",
 					payload: [playlistId]

+ 18 - 22
backend/logic/actions/punishments.js

@@ -1,24 +1,21 @@
 import async from "async";
 
 import { isAdminRequired } from "./hooks";
-import db from "../db";
 // const moduleManager = require("../../index");
 
-// const logger = require("logger");
-import utils from "../utils";
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import CacheModule from "../cache";
+import PunishmentsModule from "../punishments";
 
-import cache from "../cache";
-
-import punishments from "../punishments";
-
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "ip.ban",
 	cb: data => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.punishments",
 			args: ["event:admin.punishment.added", data.punishment]
 		});
-		utils.runJob("SOCKETS_FROM_IP", { ip: data.ip }).then(sockets => {
+		UtilsModule.runJob("SOCKETS_FROM_IP", { ip: data.ip }).then(sockets => {
 			sockets.forEach(socket => {
 				socket.disconnect(true);
 			});
@@ -34,7 +31,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	index: isAdminRequired(async (session, cb) => {
-		const punishmentModel = await db.runJob("GET_MODEL", {
+		const punishmentModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "punishment"
 		});
 		async.waterfall(
@@ -45,7 +42,7 @@ export default {
 			],
 			async (err, punishments) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "PUNISHMENTS_INDEX", `Indexing punishments failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -112,14 +109,13 @@ export default {
 				},
 
 				next => {
-					punishments
-						.runJob("ADD_PUNISHMENT", {
-							type: "banUserIp",
-							value,
-							reason,
-							expiresAt,
-							punishedBy: session.userId
-						})
+					PunishmentsModule.runJob("ADD_PUNISHMENT", {
+						type: "banUserIp",
+						value,
+						reason,
+						expiresAt,
+						punishedBy: session.userId
+					})
 						.then(punishment => {
 							next(null, punishment);
 						})
@@ -128,7 +124,7 @@ export default {
 			],
 			async (err, punishment) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"BAN_IP",
@@ -141,7 +137,7 @@ export default {
 					"BAN_IP",
 					`User ${session.userId} has successfully banned IP address ${value} with the reason ${reason}.`
 				);
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "ip.ban",
 					value: { ip: value, punishment }
 				});

+ 27 - 30
backend/logic/actions/queueSongs.js

@@ -4,22 +4,19 @@ import async from "async";
 
 import { isAdminRequired, isLoginRequired } from "./hooks";
 
-import db from "../db";
-
-import utils from "../utils";
+import DBModule from "../db";
+import UtilsModule from "../utils";
 import YouTubeModule from "../youtube";
+import CacheModule from "../cache";
 
-import cache from "../cache";
-// const logger = moduleManager.modules["logger"];
-
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "queue.newSong",
 	cb: async songId => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		queueSongModel.findOne({ _id: songId }, (err, song) => {
-			utils.runJob("EMIT_TO_ROOM", {
+			UtilsModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.queue",
 				args: ["event:admin.queueSong.added", song]
 			});
@@ -27,24 +24,24 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "queue.removedSong",
 	cb: songId => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.queue",
 			args: ["event:admin.queueSong.removed", songId]
 		});
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "queue.update",
 	cb: async songId => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		queueSongModel.findOne({ _id: songId }, (err, song) => {
-			utils.runJob("EMIT_TO_ROOM", {
+			UtilsModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.queue",
 				args: ["event:admin.queueSong.updated", song]
 			});
@@ -60,7 +57,7 @@ const lib = {
 	 * @param cb
 	 */
 	length: isAdminRequired(async (session, cb) => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		async.waterfall(
@@ -71,7 +68,7 @@ const lib = {
 			],
 			async (err, count) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "QUEUE_SONGS_LENGTH", `Failed to get length from queue songs. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -89,7 +86,7 @@ const lib = {
 	 * @param cb
 	 */
 	getSet: isAdminRequired(async (session, set, cb) => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		async.waterfall(
@@ -104,7 +101,7 @@ const lib = {
 			],
 			async (err, songs) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "QUEUE_SONGS_GET_SET", `Failed to get set from queue songs. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -123,7 +120,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	update: isAdminRequired(async (session, songId, updatedSong, cb) => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		async.waterfall(
@@ -150,7 +147,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"QUEUE_UPDATE",
@@ -158,7 +155,7 @@ const lib = {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", { channel: "queue.update", value: songId });
+				CacheModule.runJob("PUB", { channel: "queue.update", value: songId });
 				console.log(
 					"SUCCESS",
 					"QUEUE_UPDATE",
@@ -180,7 +177,7 @@ const lib = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	remove: isAdminRequired(async (session, songId, cb) => {
-		const queueSongModel = await db.runJob("GET_MODEL", {
+		const queueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 		async.waterfall(
@@ -191,7 +188,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"QUEUE_REMOVE",
@@ -199,7 +196,7 @@ const lib = {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "queue.removedSong",
 					value: songId
 				});
@@ -225,9 +222,9 @@ const lib = {
 	 */
 	add: isLoginRequired(async (session, songId, cb) => {
 		const requestedAt = Date.now();
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const QueueSongModel = await db.runJob("GET_MODEL", {
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const QueueSongModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "queueSong"
 		});
 
@@ -283,7 +280,7 @@ const lib = {
 			],
 			async (err, newSong) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"QUEUE_ADD",
@@ -291,7 +288,7 @@ const lib = {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "queue.newSong",
 					value: newSong._id
 				});
@@ -347,7 +344,7 @@ const lib = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"QUEUE_IMPORT",

+ 22 - 25
backend/logic/actions/reports.js

@@ -2,12 +2,10 @@ import async from "async";
 
 import { isAdminRequired, isLoginRequired } from "./hooks";
 
-import db from "../db";
-import utils from "../utils";
-// const logger = require("../logger");
-import songs from "../songs";
-
-import cache from "../cache";
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import SongsModule from "../songs";
+import CacheModule from "../cache";
 
 const reportableIssues = [
 	{
@@ -32,20 +30,20 @@ const reportableIssues = [
 	}
 ];
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "report.resolve",
 	cb: reportId => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.reports",
 			args: ["event:admin.report.resolved", reportId]
 		});
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "report.create",
 	cb: report => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.reports",
 			args: ["event:admin.report.created", report]
 		});
@@ -60,7 +58,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	index: isAdminRequired(async (session, cb) => {
-		const reportModel = await db.runJob("GET_MODEL", {
+		const reportModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "report"
 		});
 		async.waterfall(
@@ -71,7 +69,7 @@ export default {
 			],
 			async (err, reports) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "REPORTS_INDEX", `Indexing reports failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -89,7 +87,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	findOne: isAdminRequired(async (session, reportId, cb) => {
-		const reportModel = await db.runJob("GET_MODEL", {
+		const reportModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "report"
 		});
 		async.waterfall(
@@ -100,7 +98,7 @@ export default {
 			],
 			async (err, report) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "REPORTS_FIND_ONE", `Finding report "${reportId}" failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -118,7 +116,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	getReportsForSong: isAdminRequired(async (session, songId, cb) => {
-		const reportModel = await db.runJob("GET_MODEL", {
+		const reportModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "report"
 		});
 		async.waterfall(
@@ -140,7 +138,7 @@ export default {
 			],
 			async (err, data) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"GET_REPORTS_FOR_SONG",
@@ -162,7 +160,7 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	resolve: isAdminRequired(async (session, reportId, cb) => {
-		const reportModel = await db.runJob("GET_MODEL", {
+		const reportModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "report"
 		});
 		async.waterfall(
@@ -182,7 +180,7 @@ export default {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"REPORTS_RESOLVE",
@@ -190,7 +188,7 @@ export default {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "report.resolve",
 					value: reportId
 				});
@@ -211,10 +209,10 @@ export default {
 	 * @param {Function} cb - gets called with the result
 	 */
 	create: isLoginRequired(async (session, data, cb) => {
-		const reportModel = await db.runJob("GET_MODEL", {
+		const reportModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "report"
 		});
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -223,8 +221,7 @@ export default {
 
 				(song, next) => {
 					if (!song) return next("Song not found.");
-					return songs
-						.runJob("GET_SONG", { id: song._id })
+					return SongsModule.runJob("GET_SONG", { id: song._id })
 						.then(response => {
 							next(null, response.song);
 						})
@@ -284,7 +281,7 @@ export default {
 			],
 			async (err, report) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"REPORTS_CREATE",
@@ -292,7 +289,7 @@ export default {
 					);
 					return cb({ status: "failure", message: err });
 				}
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "report.create",
 					value: report
 				});

+ 69 - 74
backend/logic/actions/songs.js

@@ -4,31 +4,30 @@ import { isAdminRequired, isLoginRequired } from "./hooks";
 
 // const moduleManager = require("../../index");
 
-import db from "../db";
-import utils from "../utils";
-import cache from "../cache";
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import CacheModule from "../cache";
+import SongsModule from "../songs";
+import ActivitiesModule from "../activities";
 
-import songs from "../songs";
 import queueSongs from "./queueSongs";
-import activities from "../activities";
-// const logger = moduleManager.modules["logger"];
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.removed",
 	cb: songId => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: "admin.songs",
 			args: ["event:admin.song.removed", songId]
 		});
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.added",
 	cb: async songId => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		songModel.findOne({ _id: songId }, (err, song) => {
-			utils.runJob("EMIT_TO_ROOM", {
+			UtilsModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.songs",
 				args: ["event:admin.song.added", song]
 			});
@@ -36,12 +35,12 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.updated",
 	cb: async songId => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		songModel.findOne({ _id: songId }, (err, song) => {
-			utils.runJob("EMIT_TO_ROOM", {
+			UtilsModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.songs",
 				args: ["event:admin.song.updated", song]
 			});
@@ -49,10 +48,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.like",
 	cb: data => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: `song.${data.songId}`,
 			args: [
 				"event:song.like",
@@ -63,7 +62,7 @@ cache.runJob("SUB", {
 				}
 			]
 		});
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:song.newRatings", {
 					songId: data.songId,
@@ -75,10 +74,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.dislike",
 	cb: data => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: `song.${data.songId}`,
 			args: [
 				"event:song.dislike",
@@ -89,7 +88,7 @@ cache.runJob("SUB", {
 				}
 			]
 		});
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:song.newRatings", {
 					songId: data.songId,
@@ -101,10 +100,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.unlike",
 	cb: data => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: `song.${data.songId}`,
 			args: [
 				"event:song.unlike",
@@ -115,7 +114,7 @@ cache.runJob("SUB", {
 				}
 			]
 		});
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:song.newRatings", {
 					songId: data.songId,
@@ -127,10 +126,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "song.undislike",
 	cb: data => {
-		utils.runJob("EMIT_TO_ROOM", {
+		UtilsModule.runJob("EMIT_TO_ROOM", {
 			room: `song.${data.songId}`,
 			args: [
 				"event:song.undislike",
@@ -141,7 +140,7 @@ cache.runJob("SUB", {
 				}
 			]
 		});
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:song.newRatings", {
 					songId: data.songId,
@@ -161,7 +160,7 @@ export default {
 	 * @param cb
 	 */
 	length: isAdminRequired(async (session, cb) => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -170,7 +169,7 @@ export default {
 			],
 			async (err, count) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "SONGS_LENGTH", `Failed to get length from songs. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -188,7 +187,7 @@ export default {
 	 * @param cb
 	 */
 	getSet: isAdminRequired(async (session, set, cb) => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -201,7 +200,7 @@ export default {
 			],
 			async (err, songs) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "SONGS_GET_SET", `Failed to get set from songs. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -222,8 +221,7 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					songs
-						.runJob("GET_SONG_FROM_ID", { songId })
+					SongsModule.runJob("GET_SONG_FROM_ID", { songId })
 						.then(song => {
 							next(null, song);
 						})
@@ -234,7 +232,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "SONGS_GET_SONG", `Failed to get song ${songId}. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -255,15 +253,14 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					songs
-						.runJob("GET_SONG_FROM_ID", { songId })
+					SongsModule.runJob("GET_SONG_FROM_ID", { songId })
 						.then(response => next(null, response.song))
 						.catch(next);
 				}
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -310,7 +307,7 @@ export default {
 	 * @param {Function} cb
 	 */
 	update: isAdminRequired(async (session, songId, song, cb) => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -318,8 +315,7 @@ export default {
 				},
 
 				(res, next) => {
-					songs
-						.runJob("UPDATE_SONG", { songId })
+					SongsModule.runJob("UPDATE_SONG", { songId })
 						.then(song => {
 							next(null, song);
 						})
@@ -328,7 +324,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log("ERROR", "SONGS_UPDATE", `Failed to update song "${songId}". "${err}"`);
 
@@ -337,7 +333,7 @@ export default {
 
 				console.log("SUCCESS", "SONGS_UPDATE", `Successfully updated song "${songId}".`);
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "song.updated",
 					value: song.songId
 				});
@@ -359,7 +355,7 @@ export default {
 	 * @param cb
 	 */
 	remove: isAdminRequired(async (session, songId, cb) => {
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -368,8 +364,7 @@ export default {
 
 				(res, next) => {
 					// TODO Check if res gets returned from above
-					cache
-						.runJob("HDEL", { table: "songs", key: songId })
+					CacheModule.runJob("HDEL", { table: "songs", key: songId })
 						.then(() => {
 							next();
 						})
@@ -378,7 +373,7 @@ export default {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log("ERROR", "SONGS_UPDATE", `Failed to remove song "${songId}". "${err}"`);
 
@@ -387,7 +382,7 @@ export default {
 
 				console.log("SUCCESS", "SONGS_UPDATE", `Successfully remove song "${songId}".`);
 
-				cache.runJob("PUB", { channel: "song.removed", value: songId });
+				CacheModule.runJob("PUB", { channel: "song.removed", value: songId });
 
 				return cb({
 					status: "success",
@@ -405,7 +400,7 @@ export default {
 	 * @param cb
 	 */
 	add: isAdminRequired(async (session, song, cb) => {
-		const SongModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -432,7 +427,7 @@ export default {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log("ERROR", "SONGS_ADD", `User "${session.userId}" failed to add song. "${err}"`);
 
@@ -445,7 +440,7 @@ export default {
 					`User "${session.userId}" successfully added song "${song.songId}".`
 				);
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "song.added",
 					value: song.songId
 				});
@@ -467,8 +462,8 @@ export default {
 	 * @param cb
 	 */
 	like: isLoginRequired(async (session, songId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -482,7 +477,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"SONGS_LIKE",
@@ -538,9 +533,9 @@ export default {
 														message: "Something went wrong while liking this song."
 													});
 
-												songs.runJob("UPDATE_SONG", { songId });
+												SongsModule.runJob("UPDATE_SONG", { songId });
 
-												cache.runJob("PUB", {
+												CacheModule.runJob("PUB", {
 													channel: "song.like",
 													value: JSON.stringify({
 														songId: oldSongId,
@@ -550,7 +545,7 @@ export default {
 													})
 												});
 
-												activities.runJob("ADD_ACTIVITY", {
+												ActivitiesModule.runJob("ADD_ACTIVITY", {
 													userId: session.userId,
 													activityType: "liked_song",
 													payload: [songId]
@@ -584,8 +579,8 @@ export default {
 	 * @param cb
 	 */
 	dislike: isLoginRequired(async (session, songId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -599,7 +594,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"SONGS_DISLIKE",
@@ -653,8 +648,8 @@ export default {
 														message: "Something went wrong while disliking this song."
 													});
 
-												songs.runJob("UPDATE_SONG", { songId });
-												cache.runJob("PUB", {
+												SongsModule.runJob("UPDATE_SONG", { songId });
+												CacheModule.runJob("PUB", {
 													channel: "song.dislike",
 													value: JSON.stringify({
 														songId: oldSongId,
@@ -692,8 +687,8 @@ export default {
 	 * @param cb
 	 */
 	undislike: isLoginRequired(async (session, songId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -707,7 +702,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"SONGS_UNDISLIKE",
@@ -757,8 +752,8 @@ export default {
 														status: "failure",
 														message: "Something went wrong while undisliking this song."
 													});
-												songs.runJob("UPDATE_SONG", { songId });
-												cache.runJob("PUB", {
+												SongsModule.runJob("UPDATE_SONG", { songId });
+												CacheModule.runJob("PUB", {
 													channel: "song.undislike",
 													value: JSON.stringify({
 														songId: oldSongId,
@@ -795,8 +790,8 @@ export default {
 	 * @param cb
 	 */
 	unlike: isLoginRequired(async (session, songId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -810,7 +805,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"SONGS_UNLIKE",
@@ -859,8 +854,8 @@ export default {
 														status: "failure",
 														message: "Something went wrong while unliking this song."
 													});
-												songs.runJob("UPDATE_SONG", { songId });
-												cache.runJob("PUB", {
+												SongsModule.runJob("UPDATE_SONG", { songId });
+												CacheModule.runJob("PUB", {
 													channel: "song.unlike",
 													value: JSON.stringify({
 														songId: oldSongId,
@@ -897,8 +892,8 @@ export default {
 	 * @param cb
 	 */
 	getOwnSongRatings: isLoginRequired(async (session, songId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const songModel = await db.runJob("GET_MODEL", { modelName: "song" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
 		async.waterfall(
 			[
 				next => {
@@ -912,7 +907,7 @@ export default {
 			],
 			async (err, song) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"SONGS_GET_OWN_RATINGS",
@@ -932,7 +927,7 @@ export default {
 					}
 					return cb({
 						status: "failure",
-						message: await utils.runJob("GET_ERROR", {
+						message: await UtilsModule.runJob("GET_ERROR", {
 							error: err
 						})
 					});

File diff suppressed because it is too large
+ 168 - 202
backend/logic/actions/stations.js


+ 136 - 147
backend/logic/actions/users.js

@@ -9,19 +9,17 @@ import { isAdminRequired, isLoginRequired } from "./hooks";
 
 // const moduleManager = require("../../index");
 
-import db from "../db";
-import utils from "../utils";
-import cache from "../cache";
-
-import mail from "../mail";
-import punishments from "../punishments";
-// const logger = require("../logger");
-import activities from "../activities";
-
-cache.runJob("SUB", {
+import DBModule from "../db";
+import UtilsModule from "../utils";
+import CacheModule from "../cache";
+import MailModule from "../mail";
+import PunishmentsModule from "../punishments";
+import ActivitiesModule from "../activities";
+
+CacheModule.runJob("SUB", {
 	channel: "user.updateUsername",
 	cb: user => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: user._id }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: user._id }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.username.changed", user.username);
 			});
@@ -29,10 +27,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.removeSessions",
 	cb: userId => {
-		utils.runJob("SOCKETS_FROM_USER_WITHOUT_CACHE", { userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER_WITHOUT_CACHE", { userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("keep.event:user.session.removed");
 			});
@@ -40,10 +38,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.linkPassword",
 	cb: userId => {
-		utils.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.linkPassword");
 			});
@@ -51,10 +49,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.unlinkPassword",
 	cb: userId => {
-		utils.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.unlinkPassword");
 			});
@@ -62,10 +60,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.linkGithub",
 	cb: userId => {
-		utils.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.linkGithub");
 			});
@@ -73,10 +71,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.unlinkGithub",
 	cb: userId => {
-		utils.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.unlinkGithub");
 			});
@@ -84,10 +82,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.ban",
 	cb: data => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("keep.event:banned", data.punishment);
 				socket.disconnect(true);
@@ -96,10 +94,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.favoritedStation",
 	cb: data => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.favoritedStation", data.stationId);
 			});
@@ -107,10 +105,10 @@ cache.runJob("SUB", {
 	}
 });
 
-cache.runJob("SUB", {
+CacheModule.runJob("SUB", {
 	channel: "user.unfavoritedStation",
 	cb: data => {
-		utils.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
+		UtilsModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(response => {
 			response.sockets.forEach(socket => {
 				socket.emit("event:user.unfavoritedStation", data.stationId);
 			});
@@ -126,7 +124,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	index: isAdminRequired(async (session, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 		async.waterfall(
 			[
@@ -136,7 +134,7 @@ const thisExport = {
 			],
 			async (err, users) => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "USER_INDEX", `Indexing users failed. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -173,8 +171,8 @@ const thisExport = {
 	 */
 	login: async (session, identifier, password, cb) => {
 		identifier = identifier.toLowerCase();
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const sessionSchema = await cache.runJob("GET_SCHEMA", {
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const sessionSchema = await CacheModule.runJob("GET_SCHEMA", {
 			schemaName: "session"
 		});
 
@@ -205,18 +203,17 @@ const thisExport = {
 				},
 
 				(user, next) => {
-					utils.runJob("GUID", {}).then(sessionId => {
+					UtilsModule.runJob("GUID", {}).then(sessionId => {
 						next(null, user, sessionId);
 					});
 				},
 
 				(user, sessionId, next) => {
-					cache
-						.runJob("HSET", {
-							table: "sessions",
-							key: sessionId,
-							value: sessionSchema(sessionId, user._id)
-						})
+					CacheModule.runJob("HSET", {
+						table: "sessions",
+						key: sessionId,
+						value: sessionSchema(sessionId, user._id)
+					})
 						.then(() => {
 							next(null, sessionId);
 						})
@@ -225,7 +222,7 @@ const thisExport = {
 			],
 			async (err, sessionId) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"USER_PASSWORD_LOGIN",
@@ -262,11 +259,11 @@ const thisExport = {
 	 */
 	async register(session, username, email, password, recaptcha, cb) {
 		email = email.toLowerCase();
-		const verificationToken = await utils.runJob("GENERATE_RANDOM_STRING", {
+		const verificationToken = await UtilsModule.runJob("GENERATE_RANDOM_STRING", {
 			length: 64
 		});
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
-		const verifyEmailSchema = await mail.runJob("GET_SCHEMA", {
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
+		const verifyEmailSchema = await MailModule.runJob("GET_SCHEMA", {
 			schemaName: "verifyEmail"
 		});
 
@@ -279,7 +276,7 @@ const thisExport = {
 				},
 
 				next => {
-					if (!db.passwordValid(password))
+					if (!DBModule.passwordValid(password))
 						return next("Invalid password. Check if it meets all the requirements.");
 					return next();
 				},
@@ -332,7 +329,7 @@ const thisExport = {
 				},
 
 				(hash, next) => {
-					utils.runJob("GENERATE_RANDOM_STRING", { length: 12 }).then(_id => {
+					UtilsModule.runJob("GENERATE_RANDOM_STRING", { length: 12 }).then(_id => {
 						next(null, hash, _id);
 					});
 				},
@@ -356,17 +353,15 @@ const thisExport = {
 
 				// generate the url for gravatar avatar
 				(user, next) => {
-					utils
-						.runJob("CREATE_GRAVATAR", {
-							email: user.email.address
-						})
-						.then(url => {
-							user.avatar = {
-								type: "gravatar",
-								url
-							};
-							next(null, user);
-						});
+					UtilsModule.runJob("CREATE_GRAVATAR", {
+						email: user.email.address
+					}).then(url => {
+						user.avatar = {
+							type: "gravatar",
+							url
+						};
+						next(null, user);
+					});
 				},
 
 				// save the new user to the database
@@ -383,7 +378,7 @@ const thisExport = {
 			],
 			async (err, user) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"USER_PASSWORD_REGISTER",
@@ -400,7 +395,7 @@ const thisExport = {
 					if (result.status === "success") {
 						obj.SID = result.SID;
 					}
-					activities.runJob("ADD_ACTIVITY", {
+					ActivitiesModule.runJob("ADD_ACTIVITY", {
 						userId: user._id,
 						activityType: "created_account"
 					});
@@ -425,11 +420,10 @@ const thisExport = {
 		async.waterfall(
 			[
 				next => {
-					cache
-						.runJob("HGET", {
-							table: "sessions",
-							key: session.sessionId
-						})
+					CacheModule.runJob("HGET", {
+						table: "sessions",
+						key: session.sessionId
+					})
 						.then(session => {
 							next(null, session);
 						})
@@ -442,11 +436,10 @@ const thisExport = {
 				},
 
 				(session, next) => {
-					cache
-						.runJob("HDEL", {
-							table: "sessions",
-							key: session.sessionId
-						})
+					CacheModule.runJob("HDEL", {
+						table: "sessions",
+						key: session.sessionId
+					})
 						.then(() => {
 							next();
 						})
@@ -455,7 +448,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "USER_LOGOUT", `Logout failed. "${err}" `);
 					cb({ status: "failure", message: err });
 				} else {
@@ -477,7 +470,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	removeSessions: isLoginRequired(async (session, userId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -490,8 +483,7 @@ const thisExport = {
 				},
 
 				next => {
-					cache
-						.runJob("HGETALL", { table: "sessions" })
+					CacheModule.runJob("HGETALL", { table: "sessions" })
 						.then(sessions => {
 							next(null, sessions);
 						})
@@ -507,7 +499,7 @@ const thisExport = {
 				},
 
 				(keys, sessions, next) => {
-					cache.runJob("PUB", {
+					CacheModule.runJob("PUB", {
 						channel: "user.removeSessions",
 						value: userId
 					});
@@ -516,11 +508,10 @@ const thisExport = {
 						(sessionId, callback) => {
 							const session = sessions[sessionId];
 							if (session.userId === userId) {
-								cache
-									.runJob("HDEL", {
-										channel: "sessions",
-										key: sessionId
-									})
+								CacheModule.runJob("HDEL", {
+									channel: "sessions",
+									key: sessionId
+								})
 									.then(() => {
 										callback(null);
 									})
@@ -535,7 +526,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"REMOVE_SESSIONS_FOR_USER",
@@ -560,7 +551,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	findByUsername: async (session, username, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 		async.waterfall(
 			[
@@ -575,7 +566,7 @@ const thisExport = {
 			],
 			async (err, account) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log("ERROR", "FIND_BY_USERNAME", `User not found for username "${username}". "${err}"`);
 
@@ -609,7 +600,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	getUsernameFromId: async (session, userId, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		userModel
 			.findById(userId)
 			.then(user => {
@@ -635,7 +626,7 @@ const thisExport = {
 			})
 			.catch(async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"GET_USERNAME_FROM_ID",
@@ -654,16 +645,15 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	findBySession: async (session, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 		async.waterfall(
 			[
 				next => {
-					cache
-						.runJob("HGET", {
-							table: "sessions",
-							key: session.sessionId
-						})
+					CacheModule.runJob("HGET", {
+						table: "sessions",
+						key: session.sessionId
+					})
 						.then(session => {
 							next(null, session);
 						})
@@ -686,7 +676,7 @@ const thisExport = {
 			],
 			async (err, user) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "FIND_BY_SESSION", `User not found. "${err}"`);
 					return cb({ status: "failure", message: err });
 				}
@@ -723,7 +713,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateUsername: isLoginRequired(async (session, updatingUserId, newUsername, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 		async.waterfall(
@@ -766,7 +756,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -777,7 +767,7 @@ const thisExport = {
 					return cb({ status: "failure", message: err });
 				}
 
-				cache.runJob("PUB", {
+				CacheModule.runJob("PUB", {
 					channel: "user.updateUsername",
 					value: {
 						username: newUsername,
@@ -809,12 +799,12 @@ const thisExport = {
 	 */
 	updateEmail: isLoginRequired(async (session, updatingUserId, newEmail, cb) => {
 		newEmail = newEmail.toLowerCase();
-		const verificationToken = await utils.runJob("GENERATE_RANDOM_STRING", { length: 64 });
+		const verificationToken = await UtilsModule.runJob("GENERATE_RANDOM_STRING", { length: 64 });
 
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
-		const verifyEmailSchema = await mail.runJob("GET_SCHEMA", {
+		const verifyEmailSchema = await MailModule.runJob("GET_SCHEMA", {
 			schemaName: "verifyEmail"
 		});
 
@@ -849,7 +839,7 @@ const thisExport = {
 
 				// regenerate the url for gravatar avatar
 				next => {
-					utils.runJob("CREATE_GRAVATAR", { email: newEmail }).then(url => {
+					UtilsModule.runJob("CREATE_GRAVATAR", { email: newEmail }).then(url => {
 						next(null, url);
 					});
 				},
@@ -882,7 +872,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -916,7 +906,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateName: isLoginRequired(async (session, updatingUserId, newName, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 
@@ -944,7 +934,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UPDATE_NAME",
@@ -975,7 +965,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateLocation: isLoginRequired(async (session, updatingUserId, newLocation, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 
@@ -1003,7 +993,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -1037,7 +1027,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateBio: isLoginRequired(async (session, updatingUserId, newBio, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 
@@ -1065,7 +1055,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UPDATE_BIO",
@@ -1096,7 +1086,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updateAvatarType: isLoginRequired(async (session, updatingUserId, newType, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 
@@ -1124,7 +1114,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UPDATE_AVATAR_TYPE",
@@ -1157,7 +1147,7 @@ const thisExport = {
 	 */
 	updateRole: isAdminRequired(async (session, updatingUserId, newRole, cb) => {
 		newRole = newRole.toLowerCase();
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 		async.waterfall(
@@ -1182,7 +1172,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -1216,7 +1206,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	updatePassword: isLoginRequired(async (session, previousPassword, newPassword, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
 		async.waterfall(
 			[
@@ -1237,7 +1227,7 @@ const thisExport = {
 				},
 
 				next => {
-					if (!db.passwordValid(newPassword))
+					if (!DBModule.passwordValid(newPassword))
 						return next("Invalid new password. Check if it meets all the requirements.");
 					return next();
 				},
@@ -1265,7 +1255,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UPDATE_PASSWORD",
@@ -1291,11 +1281,11 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	requestPassword: isLoginRequired(async (session, cb) => {
-		const code = await utils.runJob("GENERATE_RANDOM_STRING", { length: 8 });
-		const passwordRequestSchema = await mail.runJob("GET_SCHEMA", {
+		const code = await UtilsModule.runJob("GENERATE_RANDOM_STRING", { length: 8 });
+		const passwordRequestSchema = await MailModule.runJob("GET_SCHEMA", {
 			schemaName: "passwordRequest"
 		});
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1332,7 +1322,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 
 					console.log(
 						"ERROR",
@@ -1365,7 +1355,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	verifyPasswordCode: isLoginRequired(async (session, code, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1387,7 +1377,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "VERIFY_PASSWORD_CODE", `Code '${code}' failed to verify. '${err}'`);
 					cb({ status: "failure", message: err });
 				} else {
@@ -1410,7 +1400,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	changePasswordWithCode: isLoginRequired(async (session, code, newPassword, cb) => {
-		const userModel = await db.runJob("GET_MODEL", {
+		const userModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "user"
 		});
 		async.waterfall(
@@ -1427,7 +1417,7 @@ const thisExport = {
 				},
 
 				next => {
-					if (!db.passwordValid(newPassword))
+					if (!DBModule.passwordValid(newPassword))
 						return next("Invalid password. Check if it meets all the requirements.");
 					return next();
 				},
@@ -1457,12 +1447,12 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "ADD_PASSWORD_WITH_CODE", `Code '${code}' failed to add password. '${err}'`);
 					cb({ status: "failure", message: err });
 				} else {
 					console.log("SUCCESS", "ADD_PASSWORD_WITH_CODE", `Code '${code}' successfully added password.`);
-					cache.runJob("PUB", {
+					CacheModule.runJob("PUB", {
 						channel: "user.linkPassword",
 						value: session.userId
 					});
@@ -1482,7 +1472,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	unlinkPassword: isLoginRequired(async (session, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1498,7 +1488,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UNLINK_PASSWORD",
@@ -1511,7 +1501,7 @@ const thisExport = {
 						"UNLINK_PASSWORD",
 						`Unlinking password successful for userId '${session.userId}'.`
 					);
-					cache.runJob("PUB", {
+					CacheModule.runJob("PUB", {
 						channel: "user.unlinkPassword",
 						value: session.userId
 					});
@@ -1531,7 +1521,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	unlinkGitHub: isLoginRequired(async (session, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1547,7 +1537,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"UNLINK_GITHUB",
@@ -1560,7 +1550,7 @@ const thisExport = {
 						"UNLINK_GITHUB",
 						`Unlinking GitHub successful for userId '${session.userId}'.`
 					);
-					cache.runJob("PUB", {
+					CacheModule.runJob("PUB", {
 						channel: "user.unlinkGithub",
 						value: session.userId
 					});
@@ -1581,10 +1571,10 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	requestPasswordReset: async (session, email, cb) => {
-		const code = await utils.runJob("GENERATE_RANDOM_STRING", { length: 8 });
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const code = await UtilsModule.runJob("GENERATE_RANDOM_STRING", { length: 8 });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 
-		const resetPasswordRequestSchema = await mail.runJob("GET_SCHEMA", {
+		const resetPasswordRequestSchema = await MailModule.runJob("GET_SCHEMA", {
 			schemaName: "resetPasswordRequest"
 		});
 
@@ -1627,7 +1617,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"REQUEST_PASSWORD_RESET",
@@ -1657,7 +1647,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	verifyPasswordResetCode: async (session, code, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1673,7 +1663,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "VERIFY_PASSWORD_RESET_CODE", `Code '${code}' failed to verify. '${err}'`);
 					cb({ status: "failure", message: err });
 				} else {
@@ -1696,7 +1686,7 @@ const thisExport = {
 	 * @param {Function} cb - gets called with the result
 	 */
 	changePasswordWithResetCode: async (session, code, newPassword, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1711,7 +1701,7 @@ const thisExport = {
 				},
 
 				next => {
-					if (!db.passwordValid(newPassword))
+					if (!DBModule.passwordValid(newPassword))
 						return next("Invalid password. Check if it meets all the requirements.");
 					return next();
 				},
@@ -1741,7 +1731,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"CHANGE_PASSWORD_WITH_RESET_CODE",
@@ -1820,20 +1810,19 @@ const thisExport = {
 				},
 
 				next => {
-					punishments
-						.runJob("ADD_PUNISHMENT", {
-							type: "banUserId",
-							value: userId,
-							reason,
-							expiresAt,
-							punishedBy: "" // needs changed
-						})
+					PunishmentsModule.runJob("ADD_PUNISHMENT", {
+						type: "banUserId",
+						value: userId,
+						reason,
+						expiresAt,
+						punishedBy: "" // needs changed
+					})
 						.then(punishment => next(null, punishment))
 						.catch(next);
 				},
 
 				(punishment, next) => {
-					cache.runJob("PUB", {
+					CacheModule.runJob("PUB", {
 						channel: "user.ban",
 						value: { userId, punishment }
 					});
@@ -1842,7 +1831,7 @@ const thisExport = {
 			],
 			async err => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"BAN_USER_BY_ID",
@@ -1865,7 +1854,7 @@ const thisExport = {
 	}),
 
 	getFavoriteStations: isLoginRequired(async (session, cb) => {
-		const userModel = await db.runJob("GET_MODEL", { modelName: "user" });
+		const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" });
 		async.waterfall(
 			[
 				next => {
@@ -1879,7 +1868,7 @@ const thisExport = {
 			],
 			async (err, user) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log(
 						"ERROR",
 						"GET_FAVORITE_STATIONS",

+ 5 - 5
backend/logic/actions/utils.js

@@ -2,14 +2,14 @@ import async from "async";
 
 import { isAdminRequired } from "./hooks";
 
-import utils from "../utils";
+import UtilsModule from "../utils";
 
 export default {
 	getModules: isAdminRequired((session, cb) => {
 		async.waterfall(
 			[
 				next => {
-					next(null, utils.moduleManager.modules);
+					next(null, UtilsModule.moduleManager.modules);
 				},
 
 				(modules, next) => {
@@ -33,7 +33,7 @@ export default {
 			],
 			async (err, modules) => {
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "GET_MODULES", `User ${session.userId} failed to get modules. '${err}'`);
 					cb({ status: "failure", message: err });
 				} else {
@@ -56,13 +56,13 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					next(null, utils.moduleManager.modules[moduleName]);
+					next(null, UtilsModule.moduleManager.modules[moduleName]);
 				}
 			],
 			async (err, module) => {
 				// console.log(module.runningJobs);
 				if (err && err !== true) {
-					err = await utils.runJob("GET_ERROR", { error: err });
+					err = await UtilsModule.runJob("GET_ERROR", { error: err });
 					console.log("ERROR", "GET_MODULE", `User ${session.userId} failed to get module. '${err}'`);
 					cb({ status: "failure", message: err });
 				} else {

+ 0 - 4
backend/logic/utils.js

@@ -11,10 +11,6 @@ class _UtilsModule extends CoreClass {
 	constructor() {
 		super("utils");
 
-		this.youtubeRequestCallbacks = [];
-		this.youtubeRequestsPending = 0;
-		this.youtubeRequestsActive = false;
-
 		UtilsModule = this;
 	}
 

Some files were not shown because too many files changed in this diff