Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
107 lines (93 loc) · 2.25 KB
/
Copy pathindex.js
File metadata and controls
107 lines (93 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require("dotenv").config()
const express = require("express")
const fs = require('fs');
const path = require("path");
const ratingAPI = require('./ratingAPI');
const rating = new ratingAPI(process.env.ACCESSKEY, process.env.USERID, process.env.PASSWORD);
rating.setJsonResponse(true);
const app = express();
app.listen(5500, () => {
console.log("Server started on port 5500");
});
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname + "/index.html"));
});
app.get('/api', (req, res) => {
if (!(req.query.from && req.query.to && req.query.weight)) {
res.send({
error: 'Not enough parameters. The required parameters are: from, to, weight'
})
return
}
if (+req.query.weight > 150) {
res.send({
error: 'This API doesn\'t support LTL shipping. The weight should be under 150 lbs'
})
return
}
rating.makeRequest({
customerContext: "Rating and Service",
pickUpType: {
code: "07",
description: "Rate"
},
shipment: {
description: "",
name: "",
phoneNumber: "",
shipperNumber: "",
shipper: {
address: {
addressLine: "Address Line",
city: "City",
StateProvinceCode: "NJ",
PostalCode: "07430",
countryCode: "US"
}
},
shipTo: {
companyName: "",
phoneNumber: "",
address: {
addressLine: "",
city: "",
postalCode: req.query.to,
countryCode: "US"
}
},
shipFrom: {
companyName: "",
attentionName: "",
phoneNumber: "",
faxNumber: "",
address: {
addressLine: "",
city: "",
stateProvinceCode: "",
postalCode: req.query.from,
countryCode: "US"
}
},
service: {
code: "03"
},
paymentInformation: {
accountNumber: "Ship Number"
},
package: [
{
code: "02",
weight: req.query.weight,
dcisType: req.query.dcisType,
}
],
schedule: {
pickUpDay: "02",
method: "02"
}
}
}, function (data) {
const rating = data.RatingServiceSelectionResponse.RatedShipment;
res.send(rating)
});
})