Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @module ProposalCalculations */
- const LAMBDA_NAME = 'securityTrax-editCustomer'
- const LambdaHelper = require('./LambdaHelperV2.js')
- const fs = require('fs')
- const request = require('request')
- exports.handler = async (event, context) => {
- const originalEvent = JSON.parse(JSON.stringify(event))
- try {
- console.log('HI', event)
- LambdaHelper.validateEvent(event, ['body', 'customer_id', 'ticket_id', 'account_fields_to_update', 'ticket_fields_to_update', 'appointment_fields_to_create', 'appointment_fields_to_update'])
- // LambdaHelper.validateEvent(event.body, ['customer_id', 'ticket_id', 'account_fields_to_update', 'ticket_fields_to_update', 'appointment_fields_to_create', 'appointment_fields_to_update'])
- LambdaHelper.validateEvent(event.body.account_fields_to_update, ['email'])
- LambdaHelper.validateEvent(event.body.appointment_fields_to_update, ['tech_service_type_id', 'start_time', 'user_id', 'duration', 'notes'])
- LambdaHelper.validateEvent(event.cookies, ['BIGipServer~stxna02~STX_K8S_EXTERNAL_HTTPS', 'PHPSESSID'])
- // LambdaHelper.validateEvent(event.body.fundSetup, ['Term_In_Months__c', 'Interest_Rate__c'])
- // LambdaHelper.validateEvent(event.body.fund, ['System_Price__c'])
- let createAppointmentResults = await createAppointment(event)
- console.log('RESULTS', createAppointmentResults)
- let editAppointmentResults = editAppointmentResults(createAppointmentResults)
- if (event.responseType == 'file') {
- await new Promise(function (resolve, reject) {
- fs.writeFile('myjsonfile.json', JSON.stringify(editAppointmentResults, null, 4), function (err) {
- if (err) {
- reject(err)
- } else {
- resolve('Saved JSON')
- }
- })
- })
- } else {
- return LambdaHelper.formatResponseData(null, originalEvent, editAppointmentResults, LAMBDA_NAME)
- }
- } catch (error) {
- return LambdaHelper.formatResponseData(error, originalEvent, null, LAMBDA_NAME)
- }
- }
- /**********************************************************************************************
- * @description Calls out to genability for the reduced usage savings
- * @param {JSON} event - event passed in
- * @param {JSON} proposalCalculationData - main proposal data
- * @return {JSON} response from genability-reducedUsageSavings lamba function
- ***********************************************************************************************/
- async function createAppointment(event) {
- // Here we want to run editcustomer, editTicket, and createAppointment all together
- for (let param of Object.keys(urlParamDict)) {
- if (urlParamDict.hasOwnProperty(param)) {
- URLSearchParams.push(param + '=' + urlParamDict[param])
- }
- }
- let editCustomerPayload = {
- "body": {
- "customer_id": "342516",
- "fields_to_update": {
- "email1": "shaddock@techforcenational.com"
- }
- },
- "cookies": {
- "BIGipServer~stxna02~STX_K8S_EXTERNAL_HTTPS": "!xpTGjhIWYQvpGut/tyRaV273yZ3/LDqGZ4ZaEcy9q8AMbFzIwniyvpIwy6cv11AsY1+cjZiYnFV+2nopMVAu++UY1qnYeEkIpPWwcZbg+Vk=",
- "PHPSESSID": "h73c1jpf4s947e9rccj1riuo39"
- }
- }
- let editTicketPayload = {
- "body": {
- "customer_id": "342516",
- "ticket_id": "512110",
- "fields_to_update": {
- "subject": "test1234"
- }
- },
- "cookies": {
- "BIGipServer~stxna02~STX_K8S_EXTERNAL_HTTPS": "!xpTGjhIWYQvpGut/tyRaV273yZ3/LDqGZ4ZaEcy9q8AMbFzIwniyvpIwy6cv11AsY1+cjZiYnFV+2nopMVAu++UY1qnYeEkIpPWwcZbg+Vk=",
- "PHPSESSID": "h73c1jpf4s947e9rccj1riuo39"
- }
- }
- let createAppointmentPayload = {
- "body": {
- "customer_id": "342516",
- "ticket_id": "512110",
- "fields_to_update": {
- "tech_service_type_id": "1",
- "start_time": "1575822600",
- "user_id": "2564",
- "duration": "1800"
- }
- },
- "cookies": {
- "BIGipServer~stxna02~STX_K8S_EXTERNAL_HTTPS": "!Aami8AWUFNsFLzF/tyRaV273yZ3/LF1kjlXKW6uvXuYM8HVHCIFIcJ2mSp36Njz6y9/+wFLrkI3oPc1zQLS80RonJrfW+IL7yC4C+4WsG7M=",
- "PHPSESSID": "22d0mgpumjib793u1jnlv1cqg1"
- }
- }
- let promises = [editCustomer(editCustomerPayload), editTicket(editTicketPayload), createAppointment(createAppointmentPayload)]
- console.log('PROMISE ALL', Promise.all(promises))
- return Promise.all(promises)
- }
- function editCustomer(options) {
- return new Promise(function (resolve, reject) {
- request(options, function (error, response, body) {
- if (error) {
- reject(error)
- } else {
- resolve(JSON.parse(body))
- }
- })
- })
- }
- function editTicket(options) {
- return new Promise(function (resolve, reject) {
- request(options, function (error, response, body) {
- if (error) {
- reject(error)
- } else {
- resolve(JSON.parse(body))
- }
- })
- })
- }
- function createAppointment(options) {
- return new Promise(function (resolve, reject) {
- request(options, function (error, response, body) {
- if (error) {
- reject(error)
- } else {
- resolve(JSON.parse(body))
- }
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement