-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetShippingCost.js
More file actions
43 lines (38 loc) · 1.1 KB
/
GetShippingCost.js
File metadata and controls
43 lines (38 loc) · 1.1 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
export const handler = async (event, context, callback) => {
try {
let response;
const bodyObj = event.body;
// check if shippingAddress is empty
if (!bodyObj.shippingAddress) {
response = {
statusCode: 400,
body: JSON.stringify({ "message": "empty_shipping_address" }),
}
return response
}
// make some operaton to create fake shipping cost
let shippingAddress = bodyObj.shippingAddress
let shippingCost = 0
if (shippingAddress.city === "spagna") {
shippingCost = 10
}
else {
shippingCost = 20
}
bodyObj.shippingCost = shippingCost
response = {
statusCode: 200,
body: bodyObj,
};
return response;
}
catch (error) {
const myErrorObj = {
message: error.message,
errorType: "InternalServerError",
httpStatus: 500,
requestId: context.awsRequestId,
};
callback(JSON.stringify(myErrorObj));
}
};