Refactor processors to reduce duplicate code

This commit is contained in:
2023-05-05 10:17:55 +02:00
parent 7d574e3162
commit 5a5debb249
11 changed files with 86 additions and 74 deletions

View File

@@ -2,13 +2,14 @@ import SmppSession from "../../../SmppSession";
import Preprocessor from "../Preprocessor";
export default class DestinationEnumeratorProcessor extends Preprocessor {
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
private iterator: number = 0;
constructor(type: string) {
super(type);
}
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
protected doProcess(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
return new Promise<any>((resolve, reject) => {
if (!!pdu.destination_addr) {
pdu.destination_addr = pdu.destination_addr + this.padLeft(String(this.iterator++), '0', 5);
@@ -19,4 +20,4 @@ export default class DestinationEnumeratorProcessor extends Preprocessor {
private padLeft(str: string, pad: string, length: number): string {
return (new Array(length + 1).join(pad) + str).slice(-length);
}
}
}