Add lambda scrub functionality and remove vehicle lookup.
This commit is contained in:
@@ -1,15 +1,62 @@
|
||||
// You can require shared code from the lib folder
|
||||
// const { dbConnect } = require('../lib/db');
|
||||
const axios = require('axios');
|
||||
const FormData = require('form-data');
|
||||
const ES_USER = process.env.ES_USER;
|
||||
const ES_PASSWORD = process.env.ES_PASSWORD;
|
||||
const ES_ENDPOINT = process.env.ES_ENDPOINT;
|
||||
const getVehicleType = require("../lib/vehicleTypes/vehicleType").getVehicleType;
|
||||
|
||||
exports.handler = async (event) => {
|
||||
// Path parameters are automatically parsed for you
|
||||
//Take the estimate details, add them to the database, scrub it, and then retrun the result and add the scrubbed results to database.
|
||||
try {
|
||||
const { esApiKey, estimate } = event.body ? JSON.parse(event.body) : {};
|
||||
//TODO: Replace the previous vehicle logic with just getting it here.
|
||||
|
||||
estimate.v_type = getVehicleType(estimate.v_model).type;
|
||||
estimate.sendingEntityId = "87330f61-412b-4251-baaa-d026565b23c5";
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify({
|
||||
message: `Scrub Path`,
|
||||
data: { id: 1, name: "Alice" }
|
||||
})
|
||||
};
|
||||
console.log("Updated type", estimate.v_type);
|
||||
|
||||
const fileName = `${esApiKey}-${estimate.clm_no}-${Date.now()}`;
|
||||
const formData = new FormData();
|
||||
const jsonString = JSON.stringify(estimate);
|
||||
formData.append(
|
||||
"file",
|
||||
Buffer.from(jsonString),
|
||||
{
|
||||
filename: `${fileName}.json`,
|
||||
contentType: 'application/json'
|
||||
}
|
||||
);
|
||||
const result = await axios.post(
|
||||
`${ES_ENDPOINT}/api/sendems`,
|
||||
formData,
|
||||
{
|
||||
auth: {
|
||||
username: ES_USER,
|
||||
password: ES_PASSWORD,
|
||||
},
|
||||
headers: {
|
||||
APIkey: esApiKey,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const resultPDFUrl = result?.data?.report_link;
|
||||
const reportIssueUrl = `https://insurtechtoolkit.com/pcontactUs.aspx?apiKey=${esApiKey}&file=${fileName}.json`;
|
||||
|
||||
return {
|
||||
resultPDFUrl, reportIssueUrl
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
return {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify({
|
||||
message: `Error scrubbing estimate.`,
|
||||
error: error.response.data || error.message || 'Unknown error',
|
||||
})
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user