-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
48 lines (35 loc) · 1.13 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
/* eslint-disable consistent-return */
/* eslint-disable no-console */
require('dotenv').config();
const express = require('express');
const { connectAndListenRabbitMQ } = require('./services/rabbitmq.service');
const { addMailToUnsubscribe } = require('./services/mail.service');
const app = express();
const { decrypt } = require('./logics/cyrpto.logic');
const config = require('./config');
app.get('/health', (req, res) => res.status(200).send({
upTime:
`${Math.floor(Math.floor(process.uptime() * 1000) / 60000)} min.`,
status: 'OK',
}));
app.get('/unsubscribe', (req, res) => {
const { email } = req.query;
let decryptedEmail;
try {
decryptedEmail = decrypt(email);
}
catch (error) {
console.log(error);
}
if (!email || !decryptedEmail) {
return res.status(400).send({
message: 'Paramater Error!',
});
}
addMailToUnsubscribe({ decryptedEmail });
return res.status(200).send({
message: `${decryptedEmail} mail was removed from the list.`,
});
});
app.listen(config.port, () => console.log(`[*] rabbitmq-mail-consumer-server running on ${config.port}`));
connectAndListenRabbitMQ();