-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
96 lines (74 loc) · 1.89 KB
/
server.js
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
var express = require("express");
var bodyParser = require('body-parser')
var app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(express.static("public"))
app.set("views","display")
app.set("view engine", "ejs");
let port = process.env.PORT;
if (port == null || port == "") {
port = 8000;
}
app.listen(port);
//controller
app.get("/home", function(req,res){
res.render("home", {data:null});
});
app.post("/home" ,urlencodedParser, function(req,res){
//console.log(req.body)
var num = calculate(req.body.weight,req.body.type)
var data = {data:num};
res.render("home",data)
});
//model
function calculate(weight, type){
let LTS = [0.55,0.70,0.85,1];
let LTM = [0.50,0.65,0.80,0.95];
let LEF = [1,1.20,1.40,1.60,1.80];
let FCP = [3.80,4.60]
//console.log(type);
//console.log(weight);
var price = 0;
if(type == "LTS"){
if(weight < 1){
price = LTS[0];
}else if(weight < 2){
price = LTS[1];
}else if(weight < 3){
price = LTS[2];
}else{
price = LTS[3];
}
}
if(type == "LTM"){
if(weight < 1){
price = LTM[0];
}else if(weight < 2){
price = LTM[1];
}else if(weight < 3){
price = LTM[2];
}else{
price = LTM[3];
}
}
if(type == "LEF"){
if(weight < 1){
price = LEF[0];
}else if(weight < 2){
price = LEF[1];
}else if(weight < 3){
price = LEF[2];
}else{
price = LEF[3];
}
}
if(type == "FCP"){
if(weight < 4){
price = FCP[0];
}else{
price = FCP[1];
}
}
console.log(price);
return "Your shipping cost is of: $" + (weight*price).toFixed(2) + ". Thank you for your business!";
}