Просмотр исходного кода

refactor: Allow configuring default job config to disabled

Owen Diffey 1 год назад
Родитель
Сommit
2198914e61

+ 5 - 4
backend/src/BaseModule.ts

@@ -20,7 +20,7 @@ export default abstract class BaseModule {
 
 	protected _dependentModules: (keyof Modules)[];
 
-	protected _jobApiDefault: boolean;
+	protected _jobConfigDefault: boolean | "disabled";
 
 	protected _jobConfig: Record<
 		string,
@@ -50,7 +50,7 @@ export default abstract class BaseModule {
 		this._name = name;
 		this._status = ModuleStatus.LOADED;
 		this._dependentModules = [];
-		this._jobApiDefault = true;
+		this._jobConfigDefault = true;
 		this._jobConfig = {};
 		this._jobs = {};
 		this.log(`Module (${this._name}) loaded`);
@@ -111,13 +111,14 @@ export default abstract class BaseModule {
 
 				const options = this._jobConfig[property];
 
-				let api = this._jobApiDefault;
+				let api = this._jobConfigDefault === true;
 				if (
 					typeof options === "object" &&
 					typeof options.api === "boolean"
 				)
 					api = options.api;
 				else if (typeof options === "boolean") api = options;
+				else if (this._jobConfigDefault === "disabled") return;
 
 				this._jobs[property] = {
 					api,
@@ -144,7 +145,7 @@ export default abstract class BaseModule {
 				if (this._jobs[name])
 					throw new Error(`Job "${name}" is already defined`);
 
-				let api = this._jobApiDefault;
+				let api = this._jobConfigDefault === true;
 
 				if (
 					typeof options === "object" &&

+ 11 - 1
backend/src/modules/DataModule.ts

@@ -540,7 +540,7 @@ export class DataModule extends BaseModule {
 									return;
 								}
 
-								let api = this._jobApiDefault;
+								let api = this._jobConfigDefault === true;
 
 								let method;
 
@@ -558,6 +558,16 @@ export class DataModule extends BaseModule {
 									method = configOptions;
 								else if (typeof configOptions === "boolean")
 									api = configOptions;
+								else if (
+									this._jobConfigDefault === "disabled"
+								) {
+									if (this._jobConfig[`${modelName}.${name}`])
+										delete this._jobConfig[
+											`${modelName}.${name}`
+										];
+
+									return;
+								}
 
 								if (
 									typeof options === "object" &&

+ 1 - 1
backend/src/modules/WebSocketModule.ts

@@ -24,7 +24,7 @@ export class WebSocketModule extends BaseModule {
 	public constructor() {
 		super("websocket");
 
-		this._jobApiDefault = false;
+		this._jobConfigDefault = false;
 
 		this._jobConfig = {
 			getSocket: "disabled",