-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (33 loc) · 928 Bytes
/
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
"use strict";
"use esversion:6";
const datalayer = require("./companydata");
const express = require("express");
const app = express();
const port = 8080;
const bodyParser = require("body-parser");
const routes = [
require("./routes/department"),
require("./routes/employee"),
require("./routes/timecard"),
];
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const root = "/CompanyServices";
routes.forEach((req) => app.use(root, req));
/**
* Deletes the company being queried.
*/
app.delete(`${root}/company`, (req, res) => {
try {
const company = req.query.company;
datalayer.deleteCompany(company)
? res.json({ success: `${company} was deleted.` })
: res.json({ error: `${company} wasn't found.` });
} catch (err) {
res.json({
error: err,
});
}
});
app.listen(port, console.log(`\nlistening on port: ${port}\n`));
module.exports = app;