-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
52 lines (39 loc) · 1.55 KB
/
handler.js
File metadata and controls
52 lines (39 loc) · 1.55 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
52
'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;
try {
const Controller = require('./controller')(postgresClient);
const clientSyncController = Controller.syncUpdateController;
const MagicWord = process.env.MAGIC_WORD;
const clientEmail = event.queryStringParameters.client_email;
const clientEmailSalted = clientEmail + "" + MagicWord;
const clientId = crypto.createHash('sha256').update(clientEmailSalted).digest('base64');
const syncContent = await clientSyncController.syncClient(clientId);
const response = {
MESSAGE: 'DONE',
RESPONSE: 'Client Message Fetched Successfully!',
CODE: 'CLIENT_MESSAGE_FETCHED',
CONTENT: syncContent
};
return {
statusCode: 200,
body: JSON.stringify(response)
};
} catch(err) {
console.error(`ERR: ${JSON.stringify(err.message)}`);
const response = {
ERR: err.message,
RESPONSE: 'Client Message Fetching Failed',
CODE: 'CLIENT_MESSAGE_FETCH_FAILED'
};
return {
statusCode: 400,
body: JSON.stringify(response)
};
}
}