-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
116 lines (115 loc) · 4.25 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const url = require("url");
const cookieParser = require("cookie-parser");
const PORT = process.env.PORT || 5000;
var sfUsername, sfPassword, username;
const db = require("./db.js");
express()
.use(express.static(path.join(__dirname, "public")))
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.use(cookieParser())
.set("views", path.join(__dirname, "views"))
.set("view engine", "ejs")
.get("/", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/index", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/announce", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/announce", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/order", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/order", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/customize", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/customize", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/manufacturing", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/manufacturing", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/dashboard", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/dashboard", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/dberror", function (request, response) {
var username = request.cookies.username;
db.getAccountAndVehicleByUsername(username, data => {
response.render("pages/dberror", {
account: data.account,
vehicle: data.vehicle
});
});
})
.get("/api/account", function (req, res) {
var username = req.query.username;
//db.getAccountByUsername(username, function (account) {
db.getContactByUsername(username, function (account) {
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(account, null, 3));
});
})
.get("/api/vehicle", function (req, res) {
var username = req.query.username;
db.getVehicleByUsername(username, function (vehicle) {
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(vehicle, null, 3));
});
})
.post("/api/vehicle", function (req, res) {
var vehicle = req.body;
db.updateVehicle(vehicle, function (updatedVehicle) {
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(updatedVehicle, null, 3));
});
})
.post("/api/pricequote", function (req, res) {
var vehicle = req.body;
var data = db.getPrice(vehicle);
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(data, null, 3));
})
.post("/api/loan", function (req, res) {
console.log('Creating loan...');
var loan = req.body;
db.createLoan(loan, function (newLoan) {
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(newLoan, null, 3));
});
})
.listen(PORT, () => console.log(`Listening on ${PORT}`));