Repository navigation
Expand file tree
/
Copy pathhandler.js
More file actions
51 lines (38 loc) · 1.46 KB
/
Copy pathhandler.js
File metadata and controls
51 lines (38 loc) · 1.46 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 postgresClient = require('./connections/PostgresConnection')('production');
const crypto = require('crypto');
postgresClient.authenticate()
.then(() => console.log('Database Connected Successfully'));
const Controller = require('./controller')(postgresClient);
module.exports.app = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
try {
const clientProfileController = Controller.clientProfileController;
const clientEmail = event.queryStringParameters.client_email;
const MagicWord = process.env.MAGIC_WORD;
const emailSalted = clientEmail + "" + MagicWord;
const clientId = crypto.createHash('sha256').update(emailSalted).digest('base64');
const profile = await clientProfileController.getClientProfile(clientId);
const response = {
MESSAGE: 'DONE',
RESPONSE: 'Client Profile Fetched!',
CODE: 'CLIENT_PROFILE_FETCHED',
PROFILE: profile
};
return {
statusCode: 200,
body: JSON.stringify(response)
};
} catch(err) {
console.error(`ERR: ${JSON.stringify(err.message)}`);
const response = {
ERR: err.message,
RESPONSE: 'Client Profile Fetching Failed!',
CODE: 'CLIENT_PROFILE_FETCH_FAILED'
};
return {
statusCode: 400,
body: JSON.stringify(response)
};
}
}