Commit f086ee3d by kashif ansari

spreto added for lead

1 parent a0f93740
......@@ -15,6 +15,7 @@
"@strapi/provider-email-nodemailer": "^4.3.8",
"@strapi/provider-upload-aws-s3": "^4.3.9",
"@strapi/strapi": "4.3.6",
"axios": "^1.1.3",
"better-sqlite3": "7.4.6",
"pg": "^8.8.0",
"strapi-plugin-ckeditor5": "^2.1.1-rc.1"
......
......@@ -28,6 +28,21 @@
"type": "relation",
"relation": "oneToOne",
"target": "api::project.project"
},
"httpsRequestBody": {
"type": "text"
},
"httpRequestHeaders": {
"type": "text"
},
"httpRequestUrl": {
"type": "string"
},
"httpRequestMethod": {
"type": "string"
},
"httpResposneBody": {
"type": "text"
}
}
}
'use strict';
"use strict";
/**
* lead controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController('api::lead.lead');
module.exports = createCoreController("api::lead.lead", () => ({
async sendLeads(ctx) {},
async create(ctx) {
try {
const spretoLeadData = await strapi
.service("api::lead.lead")
.sendLeadToSperto(ctx.request.body.data);
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
spretoLeadData.headers
);
ctx.request.body.data.httpRequestMethod = spretoLeadData.config.method;
ctx.request.body.data.httpRequestUrl = spretoLeadData.config.url;
ctx.request.body.data.httpsRequestBody = spretoLeadData.config.data;
ctx.request.body.data.httpResposneBody = JSON.stringify(
spretoLeadData.data
);
} catch (error) {
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.data.httpRequestMethod = error.config.method;
ctx.request.body.data.httpRequestUrl = error.config.url;
ctx.request.body.data.httpsRequestBody = error.config.data;
ctx.request.body.data.httpResposneBody = JSON.stringify(error.message);
}
const leadData = await super.create(ctx);
return ctx.send({
leadData,
});
},
}));
'use strict';
"use strict";
const axios = require("axios");
/**
* lead service
*/
const { createCoreService } = require('@strapi/strapi').factories;
const { createCoreService } = require("@strapi/strapi").factories;
module.exports = createCoreService("api::lead.lead", ({ strapi: Strapi }) => ({
async sendLeadToSperto(data) {
const headers = { "Content-Type": "application/json" };
const leadData = {
api_key: "REALATTE-16072021-HVV14-KKJD4-GTCNJ",
lead_category: "W",
campaign_key: "",
customer_name: data.fullName,
mobile1_isd: data.mobileNumber,
mobile_no1: data.mobileNumber,
email_id1: data.email,
};
module.exports = createCoreService('api::lead.lead');
const abc = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
leadData,
{ headers: headers }
);
return abc;
},
}));
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!