-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (88 loc) · 2.93 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const FormSubmission = require('./models/FormSubmission');
const path = require('path');
const app = express();
const port = 3000;
const fs = require('fs')
const bodyParser = require('body-parser');
const mongoPass = process.env['mongoPass']
const mongoFHB = process.env['mongoFHB']
// Connect to MongoDB
// mongoose.connect(`mongodb+srv://pdao:${mongoPass}@atlascluster.9zfnrrz.mongodb.net/Work`, {
// useNewUrlParser: true,
// useUnifiedTopology: true
// });
mongoose.connect(`mongodb+srv://fhb:${mongoPass}@fhbdev.c3d6xha.mongodb.net/?retryWrites=true&w=majority`, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// Routes
// Main page
app.get('/', (req, res) => {
res.sendFile(path.resolve('./public/index.html'))
})
// Thank you / confirmation page
app.get('/confirmation', (req, res) => {
res.sendFile(path.resolve('./public/confirmation.html'))
})
// Admin portal
app.get('/admin', (req, res) => {
res.sendFile(path.resolve('./public/admin.html'))
})
// Middleware
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// Form Submission Route
app.post('/submit', async (req, res) => {
if (Array.isArray(req.body.option2)) {
var opt2toString = req.body.option2.join(',');
req.body.option2 = opt2toString
}
const formData = req.body;
const timestamp = new Date().toLocaleString()
const status = 'submitted';
formData.timestamp = timestamp;
formData.status = status;
const Submission = new FormSubmission({
timeStamp: formData.timestamp,
status: formData.status,
locationVal: req.body.location,
appAccountVal: req.body.applicable,
accountNameVal: req.body.account,
ssnTinVal: req.body.ssn,
dateOfTxnVal: req.body.datetxn,
dateOfDiscVal: req.body.datediscovered,
indivResVal: req.body.indivres,
employeeVal: req.body.employee,
positionVal: req.body.position,
chargeOffAmountVal: req.body.chargeoffamount,
cashingLimitVal: req.body.cashinglimit,
dropdownOpt1Val: req.body.option1,
dropdownOpt2Val: req.body.option2,
dropdownOpt2OtherVal: req.body.option2other,
dropdownOpt4OtherVal: req.body.option4other,
dropdownOpt3Val: req.body.option3,
dropdownOpt4Val: req.body.option4,
checkInfoMakerVal: req.body.checkinfomaker,
checkInfoPayeeVal: req.body.checkinfopayee,
checkInfoDrawnOnVal: req.body.checkinfodrawnon,
checkInfoOgAmountVal: req.body.checkinfoogamount,
checkInfoExpensesVal: req.body.checkinfoplusexpenses,
checkInfoRecoveriesVal: req.body.checkinfolessrecoveries,
checkInfoNetCoVal: req.body.checkinfonetchargeoff,
individualComments: req.body.indivcomments,
supervisorComments: req.body.supervisorcomments,
});
try {
await Submission.save();
res.redirect('/confirmation');
} catch (err) {
res.status(400).send(err);
}
});
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});