const [questionnaire, categories] = await prisma.$transaction([…
- User
const [questionnaire, categories] = await prisma.$transaction([ prisma.questionnaire.findFirst({ orderBy: [{ startDate: "desc" }], where: { ...filter, approved: true, disabled: false, endDate: { // gte: addDays(new Date(), -5), //previous code gte: subDays(new Date(), -5), // return questionnaires with in the last 5 days of the current date lte: new Date(), }, 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, }, }), ]); why is the above code not returning questionnaires that are equal to the current date or below the current date
- Assistant
The code is actually returning questionnaires that have an end date falling between 5 days before the current date and the current date (
gte: subDays(new Date(), -5)means "greater than or equal to 5 days ago from the current date" andlte: new Date()means "less than or equal to the current date"). So, the end date of the questionnaire can be equal to the current date or earlier, but the start date must be earlier than or equal to the current date.If the code is not returning the desired results, the issue may be with the
filterobject that is being spread into thewhereclause. Thefilterobject may be excluding certain questionnaires from the results, or it may be including questionnaires that do not meet the criteria. Analyzing thefilterobject and adjusting it accordingly may help in getting the desired results.