Skip to content

Commit

Permalink
* fixed an issue in SICEPAT is not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
egg- committed Nov 19, 2020
1 parent e979be7 commit 3c07148
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 286 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.5.5
* fixed an issue in SICEPAT is not working.

# 2.5.4
* fixed RTS issue in JNT.

Expand Down
84 changes: 26 additions & 58 deletions lib/courier/sicepat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var request = require('request')
var moment = require('moment')
var cheerio = require('cheerio')

var tracker = require('../')

Expand Down Expand Up @@ -78,85 +77,54 @@ var loadHandler = function (opts) {
}
}

var extractNumber = function (str) {
var matches = str.match(/(\d+)/)
return matches ? matches[1] : null
}

return {
trackingInfo: function (number) {
return {
method: 'POST',
url: 'https://www.sicepat.com/checkAwb',
rejectUnauthorized: false,
data: {
'textarea-awb': number
}
method: 'GET',
url: 'https://content-main-api-production.sicepat.com/public/check-awb/' + number,
json: true
}
},
parser: {
trace: function (body, number) {
var $ = cheerio.load(body)
trace: function (data, number) {
var courier = {
code: tracker.COURIER.SICEPAT.CODE,
name: tracker.COURIER.SICEPAT.NAME
}

var result = {
courier: courier,
number: number,
status: tracker.STATUS.PENDING,
checkpoints: []
number: data.waybill_number,
status: tracker.STATUS.PENDING
}

var checkpoints = []
var $body = $('#awb-list')
var $summary = $body.find('.res-item')

if ($summary.length > 0) {
var currentDate = null
result.number = extractNumber($summary.find('td').eq(1).text())

$body.find('.history-awb-timeline li').each(function (idx) {
var checkpoint = {
courier: courier,
location: '',
message: $(this).find('.history-detail p').eq(1).text().trim(),
status: tracker.STATUS.IN_TRANSIT
}
var date = $(this).find('.history-date h5').text().trim()
var time = $(this).find('.history-detail p').eq(0).text().trim()

if (date) {
currentDate = date
}

checkpoint.time = moment(currentDate + time + '+0700', 'DD-MMM-YYYYHH:mmZ').utc().format('YYYY-MM-DDTHH:mmZ')

if (checkpoint.message.indexOf('TERIMA PERMINTAAN PICK UP') !== -1) {
checkpoint.status = tracker.STATUS.INFO_RECEIVED
}

checkpoints.push(checkpoint)
})

result.checkpoints = checkpoints.reverse()
result.status = tracker.normalizeStatus(result.checkpoints)
for (var i = 0; i < data.track_history.length; i++) {
var item = data.track_history[i]
var checkpoint = {
courier: courier,
location: '',
message: item.city || item.receiver_name,
status: tracker.STATUS.IN_TRANSIT,
time: moment(item.date_time + '+0700', 'YYYY-MM-DD HH:mmZ').utc().format('YYYY-MM-DDTHH:mm:ssZ')
}

if ($summary.find('td').eq(7).text().trim() === 'DELIVERED') {
result.status = tracker.STATUS.DELIVERED
result.checkpoints[0].status = tracker.STATUS.DELIVERED
if (item.status === 'PICKREQ') {
checkpoint.status = tracker.STATUS.INFO_RECEIVED
} else if (item.status === 'DELIVERED') {
checkpoint.status = tracker.STATUS.DELIVERED
}
checkpoints.push(checkpoint)
}

result.checkpoints = checkpoints.reverse()
result.status = tracker.normalizeStatus(result.checkpoints)

return result
}
},
load: function (tracking, cb) {
request.post({
url: tracking.url,
form: tracking.data,
rejectUnauthorized: false
}, cb)
request(tracking, cb)
}
}
}
Expand All @@ -172,7 +140,7 @@ module.exports = function (opts) {
}

try {
var result = handler.parser.trace(body, number)
var result = handler.parser.trace(body.sicepat.result, number)
cb(result ? null : tracker.error(tracker.ERROR.INVALID_NUMBER), result)
} catch (e) {
cb(tracker.error(e.message))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delivery-tracker",
"version": "2.5.4",
"version": "2.5.5",
"author": {
"name": "egg",
"email": "[email protected]"
Expand Down
Loading

0 comments on commit 3c07148

Please sign in to comment.