Generify serialize
This commit is contained in:
@@ -148,20 +148,9 @@ export default class Center extends SmppSession {
|
||||
this.server.close();
|
||||
}
|
||||
|
||||
serialize(): object {
|
||||
return {
|
||||
id: this._id,
|
||||
port: this.port,
|
||||
username: this._username,
|
||||
password: this._password,
|
||||
status: this._status,
|
||||
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||
preprocessors: this.processors.Preprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
postprocessors: this.processors.Postprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
availablePreprocessors: ProcessorManager.getPreprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
availablePostprocessors: ProcessorManager.getPostprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
};
|
||||
postSerialize(obj: any): object {
|
||||
obj.port = this.port;
|
||||
return obj;
|
||||
}
|
||||
|
||||
updateStatus(): void {
|
||||
@@ -220,4 +209,4 @@ export default class Center extends SmppSession {
|
||||
this.pendingSessions = this.pendingSessions.filter((s: any) => s !== session);
|
||||
this.updateStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,21 +116,9 @@ export default class Client extends SmppSession {
|
||||
});
|
||||
}
|
||||
|
||||
serialize(): object {
|
||||
// TODO: Generify this further by moving it to smpp session and creating a... "postSerialize" that is abstract
|
||||
return {
|
||||
id: this._id,
|
||||
url: this.url,
|
||||
username: this._username,
|
||||
password: this._password,
|
||||
status: this._status,
|
||||
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||
preprocessors: this.processors.Preprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
postprocessors: this.processors.Postprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
availablePreprocessors: ProcessorManager.getPreprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
availablePostprocessors: ProcessorManager.getPostprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
};
|
||||
postSerialize(obj: any): object {
|
||||
obj.url = this.url;
|
||||
return obj;
|
||||
}
|
||||
|
||||
close(): Promise<void> {
|
||||
@@ -292,4 +280,4 @@ export default class Client extends SmppSession {
|
||||
reject(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import PduProcessor from "./PDUProcessor/PduProcessor";
|
||||
import Postprocessor from "./PDUProcessor/Postprocessor/Postprocessor";
|
||||
import LongSmsProcessor from "./PDUProcessor/Preprocessor/Client/LongSmsProcessor";
|
||||
import Preprocessor from "./PDUProcessor/Preprocessor/Preprocessor";
|
||||
import ProcessorManager from "./PDUProcessor/ProcessorManager";
|
||||
|
||||
const NanoTimer = require("nanotimer");
|
||||
const smpp = require("smpp");
|
||||
@@ -149,7 +150,23 @@ export default abstract class SmppSession {
|
||||
|
||||
abstract close(): Promise<void>;
|
||||
|
||||
abstract serialize(): object;
|
||||
serialize(): object {
|
||||
let obj = {
|
||||
id: this._id,
|
||||
username: this._username,
|
||||
password: this._password,
|
||||
status: this._status,
|
||||
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||
preprocessors: this.processors.Preprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
postprocessors: this.processors.Postprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
availablePreprocessors: ProcessorManager.getPreprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
availablePostprocessors: ProcessorManager.getPostprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
};
|
||||
return this.postSerialize(obj);
|
||||
}
|
||||
|
||||
abstract postSerialize(obj: object): object;
|
||||
|
||||
on(event: string, callback: (...args: any[]) => void): void {
|
||||
this.eventEmitter.on(event, callback);
|
||||
|
||||
Reference in New Issue
Block a user