channel-partner.js 1.11 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;
          console.log(`Rera Number  ${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 },
        }
      );
          console.log('Existing Channel Partner');
          console.log(existingChannelPartner);
      if (existingChannelPartner && existingChannelPartner.length !== 0) {
       return ctx.badRequest(
          `Channel Partner Already Exist with the Given rera number ${reraNumber}`
        );
      }

      return await super.create(ctx);
    },
  })
);