Swapnull
06/03/2021, 9:39 AMconst lastLesson = await db.lesson.findFirst({ where: { date: { gt: new Date() } }});
but I have a field called lesson.duration. So I would ideally want to do only get it if the duration has passed, maybe something like this
const lastLesson = await db.lesson.findFirst({ where: { date: { gt: addMinutes(new Date(),
this.duration) } }});
basically can I get the where to know context about the current row somehow so it can know what the duration is while checking, rather than having to loop?
Is this possible?Manish
06/03/2021, 9:41 AMRyan
06/03/2021, 9:42 AMaddMinutes returns a valid Date object.Manish
06/03/2021, 9:42 AMSwapnull
06/03/2021, 9:53 AMaddMinutes(new Date(), 60). When I try to use this.duration I get Cannot read property 'duration' of undefined , even though it exists on the row.Manish
06/03/2021, 9:56 AMManish
06/03/2021, 9:57 AMSwapnull
06/03/2021, 10:02 AMthis.duration was just my placeholder.
I have a model which looks like
model lesson {
id String @id @default(uuid())
date DateTime
duration Int? @default(60)
}
And then a function (in an api route) that only contains
const getNextLesson = async (req, res) => {
return db.lesson.findFirst({
where: {
date: { gt: addMinutes(new Date(), 60) },
},
});
}
And I want to replace that 60 so it gets it from the database instead. I am not defining this.duration anywhere manually.Manish
06/03/2021, 10:05 AMSwapnull
06/03/2021, 10:05 AMManish
06/03/2021, 10:07 AMRyan
06/03/2021, 10:10 AMSwapnull
06/03/2021, 10:17 AM