From f300bfa0f489012d4a8acbf5bc22f4833b6afe23 Mon Sep 17 00:00:00 2001 From: jay <jay@logicloop.io> Date: Sat, 18 Feb 2023 00:57:25 +0530 Subject: [PATCH] . --- src/api/channel-partner/content-types/channel-partner/schema.json | 18 ++++++++++++++++++ src/api/channel-partner/controllers/channel-partner.js | 43 +++++++++++++++++++++++++++++++++++++------ src/api/channel-partner/services/channel-partner.js | 10 +++++----- src/extensions/users-permissions/strapi-server.js | 49 +++++++++++++++++++++++-------------------------- 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/src/api/channel-partner/content-types/channel-partner/schema.json b/src/api/channel-partner/content-types/channel-partner/schema.json index 301f0ae..494eaf4 100644 --- a/src/api/channel-partner/content-types/channel-partner/schema.json +++ b/src/api/channel-partner/content-types/channel-partner/schema.json @@ -122,6 +122,24 @@ }, "token": { "type": "text" + }, + "httpRegisterCPResposneBody": { + "type": "text" + }, + "httpRegisterCPRequestMethod": { + "type": "text" + }, + "httpRegisterCPRequestUrl": { + "type": "text" + }, + "httpRegisterCPRequestHeaders": { + "type": "text" + }, + "httpsRegisterCPRequestBody": { + "type": "text" + }, + "thirdPartyApiRegisterCPError": { + "type": "boolean" } } } diff --git a/src/api/channel-partner/controllers/channel-partner.js b/src/api/channel-partner/controllers/channel-partner.js index 57fa836..6d40f53 100644 --- a/src/api/channel-partner/controllers/channel-partner.js +++ b/src/api/channel-partner/controllers/channel-partner.js @@ -10,10 +10,12 @@ module.exports = createCoreController( "api::channel-partner.channel-partner", ({ strapi: Strapi }) => ({ async create(ctx) { + console.log(ctx); // const currentChannelPartner = ctx.state.user; - const reraNumber = ctx.request.body?.data?.reraNumber; + const reraNumber = ctx.request.body?.data?.reraNumber; + console.log(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 @@ -24,28 +26,57 @@ module.exports = createCoreController( } ); if (existingChannelPartner && existingChannelPartner.length !== 0) { - return ctx.badRequest( + return ctx.badRequest( `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 { // const spertoCPOtp = await strapi.service // .service("api::channel-partner.channel-partner") // .getCPDataFromSperto(ctx.request.body.data); - // } catch (error) { - + // } // try { // const spertoCPData = await strapi // .service("api::channel-partner.channel-partner") // .getCPDataFromSperto(ctx.request.body.data); - + // ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify( // spertoCPData.headers // ); // ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = spertoCPData.config.method; + // ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = spertoCPData.config.url; // ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = spertoCPData.config.data; // ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify( diff --git a/src/api/channel-partner/services/channel-partner.js b/src/api/channel-partner/services/channel-partner.js index 052a041..a2424e7 100644 --- a/src/api/channel-partner/services/channel-partner.js +++ b/src/api/channel-partner/services/channel-partner.js @@ -14,7 +14,7 @@ module.exports = createCoreService( "api::channel-partner.channel-partner", ({ strapi: Strapi }) => ({ async sendCPToSperto(data) { - // console.log(data); + console.log(data); const headers = { "Content-Type": "application/json" }; const cpData = { api_key: process.env.SPERTO_API_KEY, @@ -33,7 +33,7 @@ module.exports = createCoreService( // scanned_pan_url: data.panFile, // rera_certificate_url: firm_name: data.companyName, - // sourcing_manager_id + sourcing_manager_id: 85 // gst_certificate_path: data. }; const spertoResponse = await axios.post( @@ -41,11 +41,11 @@ module.exports = createCoreService( cpData, { headers: headers } ); - // console.log("cp response", spertoResponse); + console.log("cp response", spertoResponse); return spertoResponse; }, async getCPDataFromSperto(data) { - // console.log(data); + console.log(data); const headers = { "Content-Type": "application/json" }; const cpData = { api_key: process.env.SPERTO_API_KEY, @@ -60,7 +60,7 @@ module.exports = createCoreService( cpData, { headers: headers } ); - // console.log("cp response",spertoCPOTPResponse); + console.log("cp response",spertoCPOTPResponse); return spertoCPOTPResponse; }, }) diff --git a/src/extensions/users-permissions/strapi-server.js b/src/extensions/users-permissions/strapi-server.js index 9703ee4..9afd29c 100644 --- a/src/extensions/users-permissions/strapi-server.js +++ b/src/extensions/users-permissions/strapi-server.js @@ -255,10 +255,8 @@ const userPermissionExtension = (plugin) => { plugin.controllers.user.startChannelPartnerOtpLogin = async (ctx) => { const { mahareraNumber, mobileNumber } = ctx.request.body; - if (!mahareraNumber || !mobileNumber) { - throw new ValidationError( - "Please specify both the maharera & mobile numbers." - ); + if (!mahareraNumber) { + throw new ValidationError("Please specify the maharera number."); } const pluginStore = await strapi.store({ @@ -273,21 +271,17 @@ const userPermissionExtension = (plugin) => { .findOne({ populate: ["user"], where: { - $and: [ - { publishedAt: { $notNull: true } }, - { reraNumber: mahareraNumber }, - { mobileNo: mobileNumber }, - ], + reraNumber: mahareraNumber, }, }); if (!channelPartner) { 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 .query("plugin::users-permissions.user") .findOne({ where: { id: channelPartner.user.id } }); @@ -344,17 +338,17 @@ const userPermissionExtension = (plugin) => { } const emailToSend = { oneTimePassword: oneTimePassword, - to: user.email, + // to: user.email, from: `contact@hiranandani.net`, replyTo: resetPasswordSettings.response_email, subject: `Your one time password 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.`, + // 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.`, }; const finalData = { emailToSend: emailToSend, mobileNo: mobileNumber, - fullName: channelPartner.contactPersonName, + fullName: '', }; try { // const spertoResponse = await axios.post( @@ -449,12 +443,17 @@ const userPermissionExtension = (plugin) => { httpEmailResposneBody: ctx.request.body.httpEmailResposneBody, httpEmailRequestHeaders: ctx.request.body.httpEmailRequestHeaders, - httpThirdPartyOTPApiRequestHeaders: ctx.request.body.httpThirdPartyOTPApiRequestHeaders, + httpThirdPartyOTPApiRequestHeaders: + ctx.request.body.httpThirdPartyOTPApiRequestHeaders, token: ctx.request.body.token, - httpThirdPartyOTPApiRequestMethod: ctx.request.body.httpThirdPartyOTPApiRequestMethod, - httpThirdPartyOTPApiRequestUrl: ctx.request.body.httpThirdPartyOTPApiRequestUrl, - httpsThirdPartyOTPApiRequestBody: ctx.request.body.httpsThirdPartyOTPApiRequestBody, - httpThirdPartyOTPApiResposneBody: ctx.request.body.httpThirdPartyOTPApiResposneBody + httpThirdPartyOTPApiRequestMethod: + ctx.request.body.httpThirdPartyOTPApiRequestMethod, + httpThirdPartyOTPApiRequestUrl: + ctx.request.body.httpThirdPartyOTPApiRequestUrl, + httpsThirdPartyOTPApiRequestBody: + ctx.request.body.httpsThirdPartyOTPApiRequestBody, + httpThirdPartyOTPApiResposneBody: + ctx.request.body.httpThirdPartyOTPApiResposneBody, }, } ); @@ -463,12 +462,12 @@ const userPermissionExtension = (plugin) => { // TODO: Send SMS. 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) => { const { oneTimePassword, mahareraNumber, mobileNumber } = ctx.request.body; - if (!oneTimePassword || !mobileNumber || !mahareraNumber) { + if (!oneTimePassword || !mahareraNumber) { throw new ValidationError( "Please specify the oneTimePassword, maharera number and mobile numbers." ); @@ -476,7 +475,6 @@ const userPermissionExtension = (plugin) => { console.log("{ oneTimePassword, mahareraNumber, mobileNumber }", { oneTimePassword, mahareraNumber, - mobileNumber, }); // Find the channel partner first. const channelPartner = await strapi @@ -487,7 +485,6 @@ const userPermissionExtension = (plugin) => { $and: [ { publishedAt: { $notNull: true } }, { reraNumber: mahareraNumber }, - { mobileNo: mobileNumber }, ], }, }); @@ -515,8 +512,8 @@ const userPermissionExtension = (plugin) => { oneTimePassword: null, password: oneTimePassword, }); - console.log("ctx"); - ctx.send({ ok: true, message: "otp updated" }); + console.log("ctx >>>>>>>>>", user); + ctx.send({ ok: true, message: "otp updated", data: user }); }; /** Example of overriding an existing route. */ -- libgit2 0.24.0