-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (41 loc) · 1.41 KB
/
app.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
const express = require('express');
const bodyParser = require('body-parser');
const mysql = require('mysql');
const app = express();
app.use(express.static('public'));
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, () => console.log('listening at port 3000'));
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
database: 'wikimedia'
});
app.post('/donor', (request, response) => {
console.log(request.body);
const params = request.body;
pool.getConnection((error, connection) => {
if (error) {
throw error;
}
connection.query(
'INSERT INTO donations' +
'preferredPayment, frequency, amount, comments ' +
'(?, ?, ?, ?);' +
'INSERT INTO donors ' +
'lastName, firstName, streetAddress, city, state, country, postalCode, phoneNumber, email, preferredContact, donation ' +
'(?, ?, ?, ?, ?, ?, ?, ?, ?, LAST_INSERT_ID() );',
params,
(error, rows) => {
connection.release();
if (!error) {
console.log('donor information inserted!');
response.sendStatus(201, 'Success!');
} else {
console.log(error);
response.sendStatus(500);
}
});
});
});