How can i make the following downloadData controller  async downloadData(req: Request, res: Response, next: NextFunction) {
    try {
      const filter: Prisma.QuestionnaireWhereInput = {} as any;
      if (req.user?.role && req.user.role === rolesNum["DATA COLLECTOR"])
        filter.designatedRole = req.user.role;
      let regionCodes: number[];
      if (req.user?.role === rolesNum["DATA COLLECTOR"]) {
        const marketplace = await prisma.marketplace.findUnique({
          where: { code: req.user.marketplaceCode },
          select: { regionCode: true },
        });
        if (!marketplace)
          return res
            .status(httpStatusCodes.NOT_FOUND)
            .json(
              new ResponseJSON(
                "User does not have a region",
                true,
                httpStatusCodes.NOT_FOUND
              )
            );
        regionCodes = [marketplace.regionCode];
      } else {
        const branch = await prisma.branch.findUnique({
          where: { code: req.user?.branchCode },
          select: {
            // woreda: { select: { zone: { select: { regionCode: true } } } },
            marketplace: { select: { regionCode: true } },
          },
        });
        if (!branch)
          return res
            .status(httpStatusCodes.NOT_FOUND)
            .json(
              new ResponseJSON(
                "User does not have a region",
                true,
                httpStatusCodes.NOT_FOUND
              )
            );
        regionCodes = branch.marketplace.map(
          (marketplace) => marketplace.regionCode
        );
      }
      const [questionnaire, categories] = await prisma.$transaction([
        prisma.questionnaire.findFirst({
          orderBy: [{ startDate: "desc" }],
          where: {
            ...filter,
            approved: true,
            disabled: false,
            endDate: {
              gte: addDays(new Date(), -5),
            },
            startDate: {
              lte: new Date(),
            },
            isDraft: false,
          },
          include: {
            questionnaireItems: {
              where: {
                disabled: false,
              },
              include: {
                item: {
                  include: {
                    translation: true,
                    itemMeasurements: true,
                  },
                },
              },
            },
            questionnaireRegionStatus: {
              where: { regionCode: { in: regionCodes } },
            },
          },
        }),
        prisma.division.findMany({
          where: { disabled: false },
          include: {
            group: {
              where: { disabled: false },
              include: {
                class: {
                  where: { disabled: false },
                  include: {
                    subclass: {
                      where: { disabled: false },
                      include: {
                        translation: true,
                      },
                    },
                    translation: true,
                  },
                },
                translation: true,
              },
            },
            translation: true,
          },
        }),
      ]);
      /** Try to download previous quotations for out of bound reference */
      if (questionnaire && questionnaire.questionnaireItems.length > 0) {
        const quotationFilter: Prisma.QuotationWhereInput = {};
        if (req.user?.marketplaceCode)
          quotationFilter.marketplaceCode = req.user.marketplaceCode;
        else if (req.user?.branchCode)
          quotationFilter.marketplace = {
            branchCode: req.user.branchCode,
          };
        else {
          console.log(
            "User with no marketplace and branch tried to download questionnaire"
          );
          return res
            .status(httpStatusCodes.UNAUTHORIZED)
            .json(
              new ResponseJSON(
                "User either has to be assigned to a marketplace or branch to collect download questionnaire",
                true,
                httpStatusCodes.UNAUTHORIZED
              )
            );
        }
        const previousQuestionnaire = await prisma.questionnaire.findFirst({
          orderBy: [{ startDate: "desc" }],
          where: {
            ...filter,
            approved: true,
            disabled: false,
            endDate: {
              lte: new Date(questionnaire.startDate),
            },
            startDate: {
              gte: addDays(new Date(questionnaire.startDate), -35),
            },
            isDraft: false,
            // quotationsStatus: QuestionnaireQuotationsStatus.CLEANED,
          },
          select: {
            id: true,
            questionnaireItems: {
              select: {
                itemCode: true,
                quotations: {
                  where: quotationFilter,
                  select: {
                    marketplaceCode: true,
                    cleanedQuotes: {
                      where: { isDeleted: false },
                      select: {
                        price: true,
                      },
                    },
                  },
                },
              },
            },
          },
        });
        questionnaire.questionnaireItems.forEach((questionnaireItem: any) => {
          questionnaireItem.item.previousPrices = [];
          if (previousQuestionnaire)
            previousQuestionnaire.questionnaireItems.every(
              (prevQuestionItem) => {
                if (questionnaireItem.itemCode === prevQuestionItem.itemCode) {
                  prevQuestionItem.quotations.forEach((quotation) => {
                    let sum = 0;
                    quotation.cleanedQuotes.forEach((cleanQuote) => {
                      sum += cleanQuote.price.toNumber();
                    });
                    const avg =
                      sum > 0 ? sum / quotation.cleanedQuotes.length : 0;
                    if (avg) {
                      questionnaireItem.item.previousPrices.push({
                        marketplaceCode: quotation.marketplaceCode,
                        price: avg,
                      });
                    }
                  });
                  return false;
                }
                return true;
              }
            );
        });
      }
      return res.status(httpStatusCodes.OK).json(
        new ResponseJSON("Success", false, httpStatusCodes.OK, {
          questionnaire,
          categories,
        })
      );
    } catch (error) {
      console.log("Error --- ", error);
      next(
        apiErrorHandler(
          error,
          req,
          errorMessages.INTERNAL_SERVER,
          httpStatusCodes.INTERNAL_SERVER
        )
      );
    }
  } not return data with the status data: {
            status: QuestionnaireQuotationsStatus.INTERPOLATED,
          },