-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
51 lines (39 loc) · 1.56 KB
/
handler.js
File metadata and controls
51 lines (39 loc) · 1.56 KB
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
'use strict';
const crypto = require('crypto');
const postgresClient = require('./connections/PostgresConnection')('production');
postgresClient.authenticate()
.then(() => console.log('Database Connected Successfully'))
.catch((err) => console.log(`Database Connection Failed! ERR: ${err}`));
module.exports.app = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
const MagicWord = process.env.MAGIC_WORD;
try {
const Controller = require('./controller')(postgresClient);
const clientSyncController = Controller.syncUpdateController;
const clientEmail = event.queryStringParameters.client_email;
const messageId = event.queryStringParameters.message_id;
const clientEmailSalted = clientEmail + "" + MagicWord;
const clientId = crypto.createHash('sha256').update(clientEmailSalted).digest('base64');
await clientSyncController.deleteSyncRecord(clientId, messageId);
const response = {
MESSAGE: 'DONE',
RESPONSE: 'Client Message Deleted!',
CODE: 'CLIENT_MESSAGE_DELETED',
};
return {
statusCode: 200,
body: JSON.stringify(response)
};
} catch(err) {
console.error(`ERR: ${JSON.stringify(err.message)}`);
const response = {
ERR: err.message,
RESPONSE: 'Client Message Delete Failed!',
CODE: 'CLIENT_MESSAGE_DELETE_FAILED',
};
return {
statusCode: 400,
body: JSON.stringify(response)
};
}
}