/
server.js
151 lines (119 loc) · 3.64 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require("nodemailer");
const app = express();
const port = process.env.PORT || 5000;
var db = require('./backend/queries');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/api/hello', (req, res) => {
res.send({ express: 'Hello From Express' });
});
app.get('/api/avgProperties', (req, res) => {
db.avgProperties(req, res);
});
app.post('/api/world', (req, res) => {
console.log(req.body);
res.send(
`I received your POST request. This is what you sent me: ${req.body.post}`,
);
});
app.post('/api/login', (req, res) => {
// Authenticate (existing) user
if(req.body.signUp == false) {
db.authenticateUser(req,res,null);
} else {
// Create new user
db.createUser(req,res,null);
}
});
app.post('/api/approve_agreement', (req, res) => {
db.approveAgreement(req);
res.send(
`Agreement approved by agent.`
);
});
app.post('/api/permissions', (req, res) => {
console.log(req.body);
db.getPermissions(req, res, null);
});
app.get('/api/users', (req, res) => {
db.getAllUsers(req, res);
});
app.get('/api/allProperties', (req, res) => {
db.getAllProperties(req, res);
});
app.get('/api/property/:id', (req, res) => {
db.getProperty(req, res);
});
app.put('/api/addProperty', (req, res) => {
db.addProperty(req, res);
});
app.put('/api/updateProperty', (req, res) => {
db.updateProperty(req, res);
});
app.delete('/api/deleteUser', (req, res) => {
db.deleteUser(req, res);
});
app.post('/api/propertiesByOwner', (req, res) => {
db.getPropertiesByOwner(req, res);
});
app.post('/api/getUserInfo', (req, res) => {
db.getUserData(req, res);
});
app.post('/api/updateUserName', (req, res) => {
db.updateUserName(req, res);
});
app.post('/api/updateUserPassword', (req, res) => {
db.updateUserPassword(req, res);
});
app.post('/api/getUserOrders' , (req, res) => {
db.getUserOrders(req, res);
});
app.put('/api/buyProperty', (req, res) => {
db.buyProperty(req, res);
});
app.put('/api/cancelPurchase', (req, res) => {
db.cancelPurchase(req, res);
});
app.delete('/api/deleteProperty', (req, res) => {
db.deleteProperty(req, res);
});
app.post('/api/properties', db.getAllProperties);
app.post('/api/countProperties', db.countProperties);
app.post('/api/createOrder', db.createOrder);
app.post('/api/createPayment', db.createPayment);
app.get('/api/agreements', db.getAllBuyingAgreements);
app.get('/api/boughtAllProperties', db.boughtAllProperties);
app.get('/api/maxPrice', db.maxPrice);
app.post('/api/send_agreement_form', (req, res) => {
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'cs304.getProperties@gmail.com',
pass: 'cs304project'
},
tls:{
rejectUnauthorized: false
}
});
const mailOptions = {
from: '"GetProperties" <cs304.getProperties@gmail.com>', // sender address
to: 'frances.sin31@gmail.com,daniel.anatolie@gmail.com', // list of receivers
subject: 'GetProperties Buying Agreement', // Subject line
html: `<h3>${req.body.title}</h3>
<p>Your request to buy Property #${req.body.propertynumber} for $${req.body.price}
has been reviewed and approved by one of our agents!<br/><br/>
This request was submitted on ${req.body.date}.<br/>
If you have any questions, please email us at cs304getProperties@gmail.com.</p>`
};
transporter.sendMail(mailOptions, function (err, info) {
if(err)
console.log(err)
else
console.log(info);
});
});
app.listen(port, () => console.log(`Listening on port ${port}`))