Update the following code const [questionnaire, categories] = await…
- User
Update the following code 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, }, }), ]); so that questionnaires with current date greater than endDate are not returned . Show the steps with explanation
- Assistant
Step 1: Import the
subDaysfunction from thedate-fnslibraryimport { subDays } from 'date-fns';Step 2: Replace the
endDateproperty in the clause with a custom condition that checks if the current date is less than or equal to the minus 5 days.