Fix issue with job pdu messages being parsed as objects instead of strings

This commit is contained in:
David Majdandžić
2023-03-31 21:31:15 +02:00
parent 085745f0c6
commit d920fd75d7
2 changed files with 17 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ export type PDU = {
schedule_delivery_time?: string, schedule_delivery_time?: string,
sequence_number?: number, sequence_number?: number,
service_type?: string, service_type?: string,
short_message?: string, short_message?: any,
sm_default_msg_id?: number, sm_default_msg_id?: number,
source_addr?: string, source_addr?: string,
source_addr_npi?: number, source_addr_npi?: number,

View File

@@ -8,6 +8,9 @@ export class Job {
private eventEmitter: EventEmitter = new EventEmitter(); private eventEmitter: EventEmitter = new EventEmitter();
constructor(pdu: PDU, perSecond?: number, count?: number) { 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._pdu = pdu;
this._perSecond = perSecond; this._perSecond = perSecond;
this._count = count; this._count = count;
@@ -54,6 +57,18 @@ export class Job {
return new Job({}, 1, 1); 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 { update(req: any): void {
if (req.body.source != this._pdu.source_addr) { if (req.body.source != this._pdu.source_addr) {
this._pdu.source_addr = req.body.source; 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 { serialize(): SerializedJob {
return { return {
// todo fix issue where pdu hass short message of type buffer
pdu: this.pdu, pdu: this.pdu,
perSecond: this.perSecond, perSecond: this.perSecond,
count: this.count count: this.count