Browse Source

fix: Various minor fixes

Owen Diffey 1 year ago
parent
commit
d42faa9729

+ 3 - 2
backend/src/modules/APIModule.ts

@@ -8,6 +8,7 @@ import WebSocket from "../WebSocket";
 import { UserRole } from "../schemas/user";
 import { StationType } from "../schemas/station";
 import permissions from "../permissions";
+import Job from "../Job";
 
 export default class APIModule extends BaseModule {
 	private _subscriptions: Record<string, Set<string>>;
@@ -315,10 +316,10 @@ export default class APIModule extends BaseModule {
 					const promises = [];
 					for await (const socketId of socketIds.values()) {
 						promises.push(
-							this._jobQueue.runJob("api", "unsubscribe", {
+							new Job("unsubscribe", "api", {
 								socketId,
 								channel
-							})
+							}).execute()
 						);
 					}
 					return Promise.all(promises);

+ 5 - 2
backend/src/modules/DataModule.ts

@@ -5,7 +5,8 @@ import mongoose, {
 	isObjectIdOrHexString,
 	MongooseDefaultQueryMiddleware,
 	MongooseDistinctQueryMiddleware,
-	MongooseQueryOrDocumentMiddleware
+	MongooseQueryOrDocumentMiddleware,
+	Types
 } from "mongoose";
 import { patchHistoryPlugin, patchEventEmitter } from "ts-patch-mongoose";
 import { readdir } from "fs/promises";
@@ -123,7 +124,9 @@ export default class DataModule extends BaseModule {
 		this._dependentModules = ["events"];
 
 		this._jobConfig = {
-			getModel: false
+			getModel: false,
+			find: "disabled",
+			addC: "disabled"
 		};
 	}
 

+ 7 - 5
backend/src/modules/EventsModule.ts

@@ -216,7 +216,9 @@ export default class EventsModule extends BaseModule {
 		if (type === "schedule") {
 			if (!this._scheduleCallbacks[channel]) return;
 
-			const index = this._scheduleCallbacks[channel].indexOf(callback);
+			const index = this._scheduleCallbacks[channel].findIndex(
+				schedule => schedule.toString() === callback.toString()
+			);
 
 			if (index >= 0) this._scheduleCallbacks[channel].splice(index, 1);
 
@@ -225,7 +227,9 @@ export default class EventsModule extends BaseModule {
 
 		if (!this._subscriptions[channel]) return;
 
-		const index = this._subscriptions[channel].indexOf(callback);
+		const index = this._subscriptions[channel].findIndex(
+			subscription => subscription.toString() === callback.toString()
+		);
 
 		if (index < 0) return;
 
@@ -233,9 +237,7 @@ export default class EventsModule extends BaseModule {
 
 		if (this._subscriptions[channel].length === 0) {
 			delete this._subscriptions[channel];
-			await this._subClient.unsubscribe(channel, (...args) =>
-				this._subscriptionListener(...args)
-			);
+			await this._subClient.unsubscribe(channel); // TODO: Provide callback when unsubscribing
 		}
 	}