channel-partner.js 2.58 KB
"use strict";

/**
 * channel-partner controller
 */

const { createCoreController } = require("@strapi/strapi").factories;

module.exports = createCoreController(
  "api::channel-partner.channel-partner",
  ({ strapi: Strapi }) => ({
    async create(ctx) {
      //   const currentChannelPartner = ctx.state.user;
          const reraNumber = ctx.request.body?.data?.reraNumber;
      if (!reraNumber) {
       return ctx.bad(`Please specify your rera number.`);
      }

      // 1. check if the channel  partner already  exist
      const existingChannelPartner = await strapi.entityService.findMany(
        "api::channel-partner.channel-partner",
        {
          filters: { reraNumber: reraNumber },
        }
      );
      if (existingChannelPartner && existingChannelPartner.length !== 0) {
       return ctx.badRequest(
          `Channel Partner Already Exist with the Given rera number ${reraNumber}`
        );
      }
      // 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(
      //     spertoCPData.data
      //   );
      //   ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=false;
      // } catch (error) {
      //   ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
      //     error.config.headers
      //   );
      //   ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = error.config.method;
      //   ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = error.config.url;
      //   ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = error.config.data;
      //   ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(error.message);
      //   ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=true;
      // }
      return await super.create(ctx);
    },
  })
);