Commit f300bfa0 by jay

.

1 parent d821e6c9
...@@ -122,6 +122,24 @@ ...@@ -122,6 +122,24 @@
}, },
"token": { "token": {
"type": "text" "type": "text"
},
"httpRegisterCPResposneBody": {
"type": "text"
},
"httpRegisterCPRequestMethod": {
"type": "text"
},
"httpRegisterCPRequestUrl": {
"type": "text"
},
"httpRegisterCPRequestHeaders": {
"type": "text"
},
"httpsRegisterCPRequestBody": {
"type": "text"
},
"thirdPartyApiRegisterCPError": {
"type": "boolean"
} }
} }
} }
...@@ -10,10 +10,12 @@ module.exports = createCoreController( ...@@ -10,10 +10,12 @@ module.exports = createCoreController(
"api::channel-partner.channel-partner", "api::channel-partner.channel-partner",
({ strapi: Strapi }) => ({ ({ strapi: Strapi }) => ({
async create(ctx) { async create(ctx) {
console.log(ctx);
// const currentChannelPartner = ctx.state.user; // const currentChannelPartner = ctx.state.user;
const reraNumber = ctx.request.body?.data?.reraNumber; const reraNumber = ctx.request.body?.data?.reraNumber;
console.log(reraNumber);
if (!reraNumber) { if (!reraNumber) {
return ctx.bad(`Please specify your rera number.`); return ctx.bad(`Please specify your rera number.`);
} }
// 1. check if the channel partner already exist // 1. check if the channel partner already exist
...@@ -24,28 +26,57 @@ module.exports = createCoreController( ...@@ -24,28 +26,57 @@ module.exports = createCoreController(
} }
); );
if (existingChannelPartner && existingChannelPartner.length !== 0) { if (existingChannelPartner && existingChannelPartner.length !== 0) {
return ctx.badRequest( return ctx.badRequest(
`Channel Partner Already Exist with the Given rera number ${reraNumber}` `Channel Partner Already Exist with the Given rera number ${reraNumber}`
); );
} }
try {
console.log("Helllo >>>>>>>>", ctx.request.body.data);
const spertoRegisterCP = await strapi
.service("api::channel-partner.channel-partner")
.sendCPToSperto(ctx.request.body.data);
ctx.request.body.data.httpRegisterCPRequestHeaders = JSON.stringify(
spertoRegisterCP.headers
);
ctx.request.body.data.httpRegisterCPRequestMethod =
spertoRegisterCP.config.method;
ctx.request.body.data.httpRegisterCPRequestUrl =
spertoRegisterCP.config.url;
ctx.request.body.data.httpsRegisterCPRequestBody =
spertoRegisterCP.config.data;
ctx.request.body.data.httpRegisterCPResposneBody = JSON.stringify(
spertoRegisterCP.data
);
ctx.request.body.data.thirdPartyApiRegisterCPError = false;
} catch (error) {
ctx.request.body.data.httpRegisterCPRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.data.httpRegisterCPRequestMethod = error.config.method;
ctx.request.body.data.httpRegisterCPRequestUrl = error.config.url;
ctx.request.body.data.httpsRegisterCPRequestBody = error.config.data;
ctx.request.body.data.httpRegisterCPResposneBody = JSON.stringify(error.message);
ctx.request.body.data.thirdPartyApiRegisterCPError=true;
}
// try { // try {
// const spertoCPOtp = await strapi.service // const spertoCPOtp = await strapi.service
// .service("api::channel-partner.channel-partner") // .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data); // .getCPDataFromSperto(ctx.request.body.data);
// } catch (error) { // } catch (error) {
// } // }
// try { // try {
// const spertoCPData = await strapi // const spertoCPData = await strapi
// .service("api::channel-partner.channel-partner") // .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data); // .getCPDataFromSperto(ctx.request.body.data);
// ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify( // ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
// spertoCPData.headers // spertoCPData.headers
// ); // );
// ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = spertoCPData.config.method; // ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = spertoCPData.config.method;
// ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = spertoCPData.config.url; // ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = spertoCPData.config.url;
// ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = spertoCPData.config.data; // ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = spertoCPData.config.data;
// ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify( // ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(
......
...@@ -14,7 +14,7 @@ module.exports = createCoreService( ...@@ -14,7 +14,7 @@ module.exports = createCoreService(
"api::channel-partner.channel-partner", "api::channel-partner.channel-partner",
({ strapi: Strapi }) => ({ ({ strapi: Strapi }) => ({
async sendCPToSperto(data) { async sendCPToSperto(data) {
// console.log(data); console.log(data);
const headers = { "Content-Type": "application/json" }; const headers = { "Content-Type": "application/json" };
const cpData = { const cpData = {
api_key: process.env.SPERTO_API_KEY, api_key: process.env.SPERTO_API_KEY,
...@@ -33,7 +33,7 @@ module.exports = createCoreService( ...@@ -33,7 +33,7 @@ module.exports = createCoreService(
// scanned_pan_url: data.panFile, // scanned_pan_url: data.panFile,
// rera_certificate_url: // rera_certificate_url:
firm_name: data.companyName, firm_name: data.companyName,
// sourcing_manager_id sourcing_manager_id: 85
// gst_certificate_path: data. // gst_certificate_path: data.
}; };
const spertoResponse = await axios.post( const spertoResponse = await axios.post(
...@@ -41,11 +41,11 @@ module.exports = createCoreService( ...@@ -41,11 +41,11 @@ module.exports = createCoreService(
cpData, cpData,
{ headers: headers } { headers: headers }
); );
// console.log("cp response", spertoResponse); console.log("cp response", spertoResponse);
return spertoResponse; return spertoResponse;
}, },
async getCPDataFromSperto(data) { async getCPDataFromSperto(data) {
// console.log(data); console.log(data);
const headers = { "Content-Type": "application/json" }; const headers = { "Content-Type": "application/json" };
const cpData = { const cpData = {
api_key: process.env.SPERTO_API_KEY, api_key: process.env.SPERTO_API_KEY,
...@@ -60,7 +60,7 @@ module.exports = createCoreService( ...@@ -60,7 +60,7 @@ module.exports = createCoreService(
cpData, cpData,
{ headers: headers } { headers: headers }
); );
// console.log("cp response",spertoCPOTPResponse); console.log("cp response",spertoCPOTPResponse);
return spertoCPOTPResponse; return spertoCPOTPResponse;
}, },
}) })
......
...@@ -255,10 +255,8 @@ const userPermissionExtension = (plugin) => { ...@@ -255,10 +255,8 @@ const userPermissionExtension = (plugin) => {
plugin.controllers.user.startChannelPartnerOtpLogin = async (ctx) => { plugin.controllers.user.startChannelPartnerOtpLogin = async (ctx) => {
const { mahareraNumber, mobileNumber } = ctx.request.body; const { mahareraNumber, mobileNumber } = ctx.request.body;
if (!mahareraNumber || !mobileNumber) { if (!mahareraNumber) {
throw new ValidationError( throw new ValidationError("Please specify the maharera number.");
"Please specify both the maharera & mobile numbers."
);
} }
const pluginStore = await strapi.store({ const pluginStore = await strapi.store({
...@@ -273,21 +271,17 @@ const userPermissionExtension = (plugin) => { ...@@ -273,21 +271,17 @@ const userPermissionExtension = (plugin) => {
.findOne({ .findOne({
populate: ["user"], populate: ["user"],
where: { where: {
$and: [ reraNumber: mahareraNumber,
{ publishedAt: { $notNull: true } },
{ reraNumber: mahareraNumber },
{ mobileNo: mobileNumber },
],
}, },
}); });
if (!channelPartner) { if (!channelPartner) {
throw new ValidationError( throw new ValidationError(
"No channel partner registered with specified maharera number, mobile number combination." "No channel partner registered with specified maharera number."
); );
} }
// Find the linked user next. // // Find the linked user next.
const user = await strapi const user = await strapi
.query("plugin::users-permissions.user") .query("plugin::users-permissions.user")
.findOne({ where: { id: channelPartner.user.id } }); .findOne({ where: { id: channelPartner.user.id } });
...@@ -344,17 +338,17 @@ const userPermissionExtension = (plugin) => { ...@@ -344,17 +338,17 @@ const userPermissionExtension = (plugin) => {
} }
const emailToSend = { const emailToSend = {
oneTimePassword: oneTimePassword, oneTimePassword: oneTimePassword,
to: user.email, // to: user.email,
from: `contact@hiranandani.net`, from: `contact@hiranandani.net`,
replyTo: resetPasswordSettings.response_email, replyTo: resetPasswordSettings.response_email,
subject: `Your one time password is: ${oneTimePassword}`, subject: `Your one time password is: ${oneTimePassword}`,
text: `Hello ${channelPartner.contactPersonName}, Your one time password to login to your partner portal is ${oneTimePassword}`, // text: `Hello ${channelPartner.contactPersonName}, Your one time password to login to your partner portal is ${oneTimePassword}`,
html: `<p>Hello ${channelPartner.contactPersonName}, <br></br>Your one time password to login to your partner portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`, // html: `<p>Hello ${channelPartner.contactPersonName}, <br></br>Your one time password to login to your partner portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`,
}; };
const finalData = { const finalData = {
emailToSend: emailToSend, emailToSend: emailToSend,
mobileNo: mobileNumber, mobileNo: mobileNumber,
fullName: channelPartner.contactPersonName, fullName: '',
}; };
try { try {
// const spertoResponse = await axios.post( // const spertoResponse = await axios.post(
...@@ -449,12 +443,17 @@ const userPermissionExtension = (plugin) => { ...@@ -449,12 +443,17 @@ const userPermissionExtension = (plugin) => {
httpEmailResposneBody: ctx.request.body.httpEmailResposneBody, httpEmailResposneBody: ctx.request.body.httpEmailResposneBody,
httpEmailRequestHeaders: ctx.request.body.httpEmailRequestHeaders, httpEmailRequestHeaders: ctx.request.body.httpEmailRequestHeaders,
httpThirdPartyOTPApiRequestHeaders: ctx.request.body.httpThirdPartyOTPApiRequestHeaders, httpThirdPartyOTPApiRequestHeaders:
ctx.request.body.httpThirdPartyOTPApiRequestHeaders,
token: ctx.request.body.token, token: ctx.request.body.token,
httpThirdPartyOTPApiRequestMethod: ctx.request.body.httpThirdPartyOTPApiRequestMethod, httpThirdPartyOTPApiRequestMethod:
httpThirdPartyOTPApiRequestUrl: ctx.request.body.httpThirdPartyOTPApiRequestUrl, ctx.request.body.httpThirdPartyOTPApiRequestMethod,
httpsThirdPartyOTPApiRequestBody: ctx.request.body.httpsThirdPartyOTPApiRequestBody, httpThirdPartyOTPApiRequestUrl:
httpThirdPartyOTPApiResposneBody: ctx.request.body.httpThirdPartyOTPApiResposneBody ctx.request.body.httpThirdPartyOTPApiRequestUrl,
httpsThirdPartyOTPApiRequestBody:
ctx.request.body.httpsThirdPartyOTPApiRequestBody,
httpThirdPartyOTPApiResposneBody:
ctx.request.body.httpThirdPartyOTPApiResposneBody,
}, },
} }
); );
...@@ -463,12 +462,12 @@ const userPermissionExtension = (plugin) => { ...@@ -463,12 +462,12 @@ const userPermissionExtension = (plugin) => {
// TODO: Send SMS. // TODO: Send SMS.
console.log("responseBody", responseBody); console.log("responseBody", responseBody);
ctx.send({ ok: true, message: "otp sent", data: responseBody.data }); ctx.send({ data: responseBody.data });
}; };
plugin.controllers.user.finishChannelPartnerOtpLogin = async (ctx) => { plugin.controllers.user.finishChannelPartnerOtpLogin = async (ctx) => {
const { oneTimePassword, mahareraNumber, mobileNumber } = ctx.request.body; const { oneTimePassword, mahareraNumber, mobileNumber } = ctx.request.body;
if (!oneTimePassword || !mobileNumber || !mahareraNumber) { if (!oneTimePassword || !mahareraNumber) {
throw new ValidationError( throw new ValidationError(
"Please specify the oneTimePassword, maharera number and mobile numbers." "Please specify the oneTimePassword, maharera number and mobile numbers."
); );
...@@ -476,7 +475,6 @@ const userPermissionExtension = (plugin) => { ...@@ -476,7 +475,6 @@ const userPermissionExtension = (plugin) => {
console.log("{ oneTimePassword, mahareraNumber, mobileNumber }", { console.log("{ oneTimePassword, mahareraNumber, mobileNumber }", {
oneTimePassword, oneTimePassword,
mahareraNumber, mahareraNumber,
mobileNumber,
}); });
// Find the channel partner first. // Find the channel partner first.
const channelPartner = await strapi const channelPartner = await strapi
...@@ -487,7 +485,6 @@ const userPermissionExtension = (plugin) => { ...@@ -487,7 +485,6 @@ const userPermissionExtension = (plugin) => {
$and: [ $and: [
{ publishedAt: { $notNull: true } }, { publishedAt: { $notNull: true } },
{ reraNumber: mahareraNumber }, { reraNumber: mahareraNumber },
{ mobileNo: mobileNumber },
], ],
}, },
}); });
...@@ -515,8 +512,8 @@ const userPermissionExtension = (plugin) => { ...@@ -515,8 +512,8 @@ const userPermissionExtension = (plugin) => {
oneTimePassword: null, oneTimePassword: null,
password: oneTimePassword, password: oneTimePassword,
}); });
console.log("ctx"); console.log("ctx >>>>>>>>>", user);
ctx.send({ ok: true, message: "otp updated" }); ctx.send({ ok: true, message: "otp updated", data: user });
}; };
/** Example of overriding an existing route. */ /** Example of overriding an existing route. */
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!