Commit ecaede34 by jay

send lead while enduser sign up

1 parent 1009d8b2
......@@ -76,7 +76,7 @@ module.exports = factories.createCoreController(
console.log("ctx.request.body", ctx.request.body);
try {
const spretoLeadData = await strapi
.service("api::lead.lead")
.service("api::end-user.end-user")
.sendLeadToSperto(ctx.request.body.data);
// console.log("spretoLeadData.data", spretoLeadData.data);
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
......
......@@ -7,102 +7,114 @@ const { default: axios } = require("axios");
*/
const { createCoreService } = require("@strapi/strapi").factories;
module.exports = createCoreService("api::end-user.end-user",
({ strapi: Strapi }) => ({
async sendLeadToSperto(data) {
console.log(">>>",data);
const headers = { "Content-Type": "application/json" };
const leadData = {
api_key: process.env.SPERTO_API_KEY,
lead_category: "W",
campaign_key: process.env.CAMPAIGN_KEY,
customer_name: data.fullName,
mobile1_isd: "",
mobile_no1: data.mobileNo,
email_id1: data.email,
otp_verified_yn: "N",
};
// console.log("lead data", leadData);
// if (data.comments) {
// leadData.comments = data.comments;
// }
if (data?.project) {
const projectData = await strapi.db
.query("api::project.project")
.findOne({
where: {
id: data?.project,
},
});
leadData.project_name = projectData.projectName;
}
module.exports = createCoreService(
"api::end-user.end-user",
({ strapi: Strapi }) => ({
async sendOTPToSpreto(data) {
const headers = { "Content-Type": "application/json" };
const otpDetails = {
api_key: process.env.SPERTO_API_KEY,
from_name: data.from_name,
from_mail: data.from_mail,
to: data.to,
subject: data.subject,
body: data.body,
// lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName,
// mobile1_isd: "",
// mobile_no1: data.mobileNumber,
// email_id1: data.email,
// otp_verified_yn: "N",
};
const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails,
{ headers: headers }
);
const spertoLeadResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
leadData,
{ headers: headers }
);
console.log("spertoLeadResponse",spertoLeadResponse);
return spertoLeadResponse;
},
const leadData = {
api_key: process.env.SPERTO_API_KEY,
lead_category: "W",
campaign_key: process.env.CAMPAIGN_KEY,
customer_name: data.fullName,
mobile1_isd: "",
mobile_no1: data.mobileNo,
email_id1: data.email,
otp_verified_yn: "N",
};
// console.log("lead data", leadData);
if (data.comments) {
leadData.comments = data.comments;
}
if (data?.project) {
const projectData = await strapi.db
.query("api::project.project")
.findOne({
where: {
id: data?.project,
},
});
leadData.project_name = projectData.projectName;
}
async sendOTPToSpreto(data) {
const headers = { "Content-Type": "application/json" };
const otpDetails = {
api_key: process.env.SPERTO_API_KEY,
from_name: data.from_name,
from_mail: data.from_mail,
to: data.to,
subject: data.subject,
body: data.body,
// lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName,
// mobile1_isd: "",
// mobile_no1: data.mobileNumber,
// email_id1: data.email,
// otp_verified_yn: "N",
};
const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails,
{ headers: headers }
);
const spertoLeadResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
leadData,
{ headers: headers }
);
// console.log("spertoLeadResponse", spertoLeadResponse);
return spertoLeadResponse, spertoResponse;
// return ;
return spertoResponse;
// return ;
},
// ({ strapi: Strapi }) => ({async sendLeadToSperto(data) {
// console.log(data);
// const headers = { "Content-Type": "application/json" };
// const leadData = {
// api_key: process.env.SPERTO_API_KEY,
// lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName,
// mobile1_isd: "",
// mobile_no1: data.mobileNo,
// email_id1: data.email,
// otp_verified_yn: "N",
// };
// if (data.comments) {
// leadData.comments = data.comments;
// }
// if (data?.project) {
// const projectData = await strapi.db
// .query("api::project.project")
// .findOne({
// where: {
// id: data?.project,
// },
// });
// leadData.project_name = projectData.projectName;
// }
},
}))
// module.exports = createCoreService(
// "api::end-user.end-user",
// ({ strapi: Strapi }) => ({
// // ({ strapi: Strapi }) => ({async sendLeadToSperto(data) {
// // console.log(data);
// // const headers = { "Content-Type": "application/json" };
// // const leadData = {
// // api_key: process.env.SPERTO_API_KEY,
// // lead_category: "W",
// // campaign_key: process.env.CAMPAIGN_KEY,
// // customer_name: data.fullName,
// // mobile1_isd: "",
// // mobile_no1: data.mobileNo,
// // email_id1: data.email,
// // otp_verified_yn: "N",
// // };
// // if (data.comments) {
// // leadData.comments = data.comments;
// // }
// // if (data?.project) {
// // const projectData = await strapi.db
// // .query("api::project.project")
// // .findOne({
// // where: {
// // id: data?.project,
// // },
// // });
// // leadData.project_name = projectData.projectName;
// // }
// // const spertoResponse = await axios.post(
// // "https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
// // leadData,
// // { headers: headers }
// // );
// // return spertoResponse;
// // }})
// })
// );
// const spertoResponse = await axios.post(
// "https://net4hgc.sperto.co.in/_api/api_auth_post_lead_json.php",
// leadData,
// { headers: headers }
// );
// return spertoResponse;
// }})
})
);
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!