From d920fd75d7475ac173b9dc4b470552e461e11e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Fri, 31 Mar 2023 21:31:15 +0200 Subject: [PATCH] Fix issue with job pdu messages being parsed as objects instead of strings --- src/CommonObjects.ts | 2 +- src/Job/Job.ts | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/CommonObjects.ts b/src/CommonObjects.ts index e4d5010..549f15d 100644 --- a/src/CommonObjects.ts +++ b/src/CommonObjects.ts @@ -17,7 +17,7 @@ export type PDU = { schedule_delivery_time?: string, sequence_number?: number, service_type?: string, - short_message?: string, + short_message?: any, sm_default_msg_id?: number, source_addr?: string, source_addr_npi?: number, diff --git a/src/Job/Job.ts b/src/Job/Job.ts index b6acd26..7d997b2 100644 --- a/src/Job/Job.ts +++ b/src/Job/Job.ts @@ -8,6 +8,9 @@ export class Job { private eventEmitter: EventEmitter = new EventEmitter(); constructor(pdu: PDU, perSecond?: number, count?: number) { + if (pdu.short_message && pdu.short_message.type === "Buffer") { + pdu.short_message = String(pdu.short_message.data); + } this._pdu = pdu; this._perSecond = perSecond; this._count = count; @@ -54,6 +57,18 @@ export class Job { return new Job({}, 1, 1); } + static deserialize(serialized: SerializedJob): Job { + if (!serialized.pdu || !serialized.pdu.command) { + if (!serialized.perSecond && !serialized.count) { + return Job.createEmptySingle(); + } else { + return Job.createEmptyMultiple(); + } + } + let pdu: PDU = new smpp.PDU(serialized.pdu.command, serialized.pdu); + return new Job(pdu, serialized.perSecond, serialized.count); + } + update(req: any): void { if (req.body.source != this._pdu.source_addr) { this._pdu.source_addr = req.body.source; @@ -72,20 +87,9 @@ export class Job { } } - static deserialize(serialized: SerializedJob): Job { - if (!serialized.pdu || !serialized.pdu.command) { - if (!serialized.perSecond && !serialized.count) { - return Job.createEmptySingle(); - } else { - return Job.createEmptyMultiple(); - } - } - let pdu: PDU = new smpp.PDU(serialized.pdu.command, serialized.pdu); - return new Job(pdu, serialized.perSecond, serialized.count); - } - serialize(): SerializedJob { return { + // todo fix issue where pdu hass short message of type buffer pdu: this.pdu, perSecond: this.perSecond, count: this.count