@iletimerkezi/iletimerkezi-node
Version:
İleti Merkezi Node.js SDK
100 lines • 3.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportResponse = void 0;
const BaseResponse_1 = require("./BaseResponse");
class ReportResponse extends BaseResponse_1.BaseResponse {
constructor(data, statusCode, page) {
super(data, statusCode);
this.currentPage = 1;
this.currentPage = page;
}
getOrderId() {
return this.data?.order?.id || '';
}
getOrderStatus() {
const status = this.data?.order?.status?.toString() || '';
return ReportResponse.ORDER_STATUS_MESSAGES[status] || status;
}
getOrderStatusCode() {
return parseInt(this.data?.order?.status?.toString() || '0', 10);
}
getTotal() {
return this.data?.order?.total || 0;
}
getDelivered() {
return this.data?.order?.delivered || 0;
}
getUndelivered() {
return this.data?.order?.undelivered || 0;
}
getWaiting() {
return this.data?.order?.waiting || 0;
}
getSubmitAt() {
return this.data?.order?.submitAt || '';
}
getSendAt() {
return this.data?.order?.sendAt || '';
}
getSender() {
return this.data?.order?.sender || '';
}
getMessages() {
return this.data?.order?.message || [];
}
getMessageCount() {
return this.getMessages().length;
}
getCurrentPage() {
return this.currentPage;
}
getTotalPages() {
return Math.ceil(this.getTotal() / (this.currentPage * 1000));
}
hasMorePages() {
return this.getCurrentPage() < this.getTotalPages();
}
getMessageStatus(index) {
const status = this.getMessages()[index]?.status?.toString() || '';
return ReportResponse.MESSAGE_STATUS_MESSAGES[status] || status;
}
getMessageStatusCode(index) {
return parseInt(this.getMessages()[index]?.status?.toString() || '0', 10);
}
toJSON() {
return {
success: this.ok(),
statusCode: this.getStatusCode(),
message: this.getMessage(),
order: {
id: this.getOrderId(),
status: this.getOrderStatus(),
statusCode: this.getOrderStatusCode(),
total: this.getTotal(),
delivered: this.getDelivered(),
undelivered: this.getUndelivered(),
waiting: this.getWaiting(),
submitAt: this.getSubmitAt(),
sendAt: this.getSendAt(),
sender: this.getSender(),
messages: this.getMessages().map((msg, index) => ({
number: msg.number,
status: this.getMessageStatus(index),
statusCode: this.getMessageStatusCode(index)
}))
}
};
}
}
exports.ReportResponse = ReportResponse;
ReportResponse.ORDER_STATUS_MESSAGES = {
'113': 'SENDING',
'114': 'COMPLETED',
'115': 'CANCELED'
};
ReportResponse.MESSAGE_STATUS_MESSAGES = {
'110': 'WAITING',
'111': 'DELIVERED',
'112': 'UNDELIVERED'
};
//# sourceMappingURL=ReportResponse.js.map