avatar
Separating Concerns Using Lambda Expressions Javascript

Separating Concerns (SoC) Using Lambda Expressions involves leveraging Lambda expressions in programming to isolate and organize different functionalities or concerns within a software system.

» LogCustomExternal.js

const https = require('https');

const LogCustomExternal = async (payload) => {

    const apiEndpoint = 'https://www.flagtickgroup.com/api/auth/external-log';
    const response = await new Promise((resolve, reject) => {
        const postData = JSON.stringify({ payload }); 
        const options = {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
        };
        const req = https.request(apiEndpoint, options, (res) => {
            let data = '';
            res.on('data', (chunk) => {
                data += chunk;
            });
            res.on('end', () => {
                resolve({
                    statusCode: res.statusCode,
                    body: data,
                });
            });
        });
        req.on('error', (error) => {
            reject({
                statusCode: 500,
                body: JSON.stringify({ message: `Error: ${error.message}` }),
            });
        });
        req.write(postData);
        req.end();
    });


    return response;
};
module.exports = LogCustomExternal;

» index.js

const crypto = require('crypto');
const LogCustomExternal = require('./LogCustomExternal.js');

exports.handler = async (event) => {
  let verificationCode = '';
  let phoneNumber = event.request.userAttributes['phone_number'];

  try {
    if (event.request.session.length > 0) {
      verificationCode = crypto.randomInt(100000, 999999).toString();
      const temp = { message: `${verificationCode}` };
      await LogCustomExternal(temp);
      ....



You need to login to do this manipulation!