/
index.js
71 lines (58 loc) · 1.62 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
import express from "express";
import path from "path";
import AbandonedCarts from "./zid.js";
import AddCoupon from "./addCoupon.js";
import sendMail from "./mail.js";
import Loyalty from "./loyality.js";
const __dirname = path.resolve();
var app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.use(express.static(path.join(__dirname, "public")));
app.get("/carts", async (req, res) => {
const response = await AbandonedCarts();
const renderedData = response["abandoned-carts"];
res.render("abandoned", { renderedData });
});
app.get("/", async (req, res) => {
res.render("index");
});
app.get("/loyalty", async (req, res) => {
res.render("loyalty");
});
app.get("/coupon", async (req, res) => {
res.render("coupon");
});
app.get("/error", (req, res) => {
res.render("error");
});
app.post("/loyalty", async (req, res) => {
const response = await Loyalty();
res.send(response);
});
app.post("/add-coupon", async (req, res) => {
const data = req.body;
const dataToSend = Object.assign({}, data);
const response = await AddCoupon(dataToSend);
if (response) {
res.redirect("/");
} else {
res.redirect("/error");
}
});
app.post("/mail", async (req, res) => {
const data = req.body;
const dataToSend = Object.assign({}, data);
const send = await sendMail(dataToSend);
if (send) {
res.send("mail has been sent");
} else {
res.send("there was an error");
}
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server started on ${port}`);
});