Commit 13639740 by jay

send lead while sign up (unsolved error)

1 parent 00989511
......@@ -29,6 +29,24 @@
},
"dialCode": {
"type": "string"
},
"httpsRequestBody": {
"type": "text"
},
"httpRequestHeaders": {
"type": "text"
},
"httpRequestUrl": {
"type": "text"
},
"httpRequestMethod": {
"type": "string"
},
"httpResposneBody": {
"type": "text"
},
"thirdPartyApiError": {
"type": "boolean"
}
}
}
......@@ -61,16 +61,11 @@ module.exports = factories.createCoreController(
});
// 5. change from draft to published.
await strapi.entityService.update(
"api::end-user.end-user",
endUser.id,
{
await strapi.entityService.update("api::end-user.end-user", endUser.id, {
data: {
publishedAt: new Date(),
},
}
);
});
// TODO: at this point we might have to invoke a Hiranandani API to send the newly registered user there.
ctx.send({ ok: true, message: "user registered" });
......@@ -78,9 +73,33 @@ module.exports = factories.createCoreController(
// Wrapping a core action (leaves core logic in place)
async create(ctx) {
console.log("ctx.request.body", ctx.request.body);
try {
const spretoLeadData = await strapi
.service("api::lead.lead")
.sendLeadToSperto(ctx.request.body.data);
// console.log("spretoLeadData.data", spretoLeadData.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
);
ctx.request.body.data.thirdPartyApiError = false;
} 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);
ctx.request.body.data.thirdPartyApiError = true;
}
const currentUser = ctx.state.user;
// 2. check if the current user already has an existing business listing (existingEndUser) against their name.
const existingEndUser = await strapi.entityService.findMany(
"api::end-user.end-user",
......
......@@ -12,7 +12,6 @@ module.exports = createCoreService(
"api::end-user.end-user",
({ strapi: Strapi }) => ({
async sendOTPToSpreto(data) {
console.log(data);
const headers = { "Content-Type": "application/json" };
const otpDetails = {
api_key: process.env.SPERTO_API_KEY,
......@@ -34,7 +33,76 @@ module.exports = createCoreService(
otpDetails,
{ headers: headers }
);
return spertoResponse;
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;
}
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 ;
},
// ({ 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;
// }})
})
);
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!