Undefined binding(s) detected when compiling WHERE. Undefined column(s

I found how to solve my issue. I’ve created a specific type which aggregate the datas.
Now I’m able to get my computed elements

"use strict";

module.exports =
  (strapi, toEntityResponseCollection, toEntityResponse) =>
  ({ nexus }) => ({
    typeDefs: `
    type PopularityResponse {      
      id: ImpressionEntityResponseCollection
      startDate: String
      endDate: String
      branding: String
      aggregated: aggregateInput
    }

    type aggregateInput {
      brand: [singleAggregate]
      nobrand: [singleAggregate]
    }

    type singleAggregate {
      date_debut: String
      search_impression_share: Int
    }

    extend type Query {
      popularity(id: ID!, startDate: String, endDate: String, branding: String): PopularityResponse
    }
  `,
    resolvers: {
      Query: {
        popularity: {
          resolve: async (parent, args, context) => ({
            id: args.id,
            startDate: args.startDate,
            endDate: args.endDate,
            branding: args.branding,
          }),
        },
      },
      PopularityResponse: {
        aggregated: {
          resolve: async (parent, args, ctx) => {
            let compile = await strapi.entityService.findMany(
              "api::impression.impression",
              {
                filters: {
                  googleid: {
                    id: {
                      $eq: parent.id,
                    },
                  },
                  date_debut: {
                    $gte: parent.startDate,
                  },
                  date_fin: {
                    $lte: parent.endDate,
                  },
                },
              },
              args
            );

            // console.log(compile);

            let aggregate = compile.reduce(
              (acc, key) => {
                // vérifie si la campagne est dans la liste
                if (
                  [parent.branding].some((elem) => {
                    let reg = new RegExp(elem);
                    return reg.test(key.campaignName);
                  })
                ) {
                  let brandingIndex = acc.branding.findIndex(
                    (el) => el.date_debut == key.date_debut
                  );
                  if (brandingIndex !== -1) {
                    // si on a un élément
                    acc.branding[brandingIndex].search_impression_share +=
                      parseInt(key.search_impression_share);
                  } else {
                    acc.branding.push({
                      search_impression_share: parseInt(
                        key.search_impression_share
                      ),
                      date_debut: key.date_debut,
                    });
                  }
                } else {
                  let nobrandingIndex = acc.nobranding.findIndex(
                    (el) => el.date_debut == key.date_debut
                  );
                  if (nobrandingIndex !== -1) {
                    // si on a un élément
                    acc.nobranding[nobrandingIndex].search_impression_share +=
                      parseInt(key.search_impression_share);
                  } else {
                    acc.nobranding.push({
                      search_impression_share: parseInt(
                        key.search_impression_share
                      ),
                      date_debut: key.date_debut,
                    });
                  }
                }

                return acc;
              },
              { branding: [], nobranding: [] }
            );
            return {
              brand: aggregate.branding,
              nobrand: () => {
                return aggregate.nobranding;
              },
            };
          },
        },        
      },
    },
    resolversConfig: {
      "Query.popularity": {
        auth: {
          scope: [
            "api::impression.impression.findOne",
            "api::impression.impression.find",
          ],
        },
      },
    },
  });
1 Like