I have no idea how to phrase this question and to be honest, when I think about it, this should have a really simple answer but for some reason, I couldn't find the best way to do it.
I'm building a React Native app with a Prisma backend. I don't want to involve the front end at all to solve this. I have a session model that has a date of the event and isCompleted param. I would like to be able to update isCompleted when the date of the event is in the past automatically. Backend is running on Heroku server, without setting up a cron job or something else, is this possible to do?
here is the model and update code I have, but not sure where to tie this to make sure it always updates all the sessions based on the time.
export const SessionUpdate = {
updateSessionCompletion: async (parent, args, context): Promise<any> => {
try {
const session = await prisma.session.findUnique({
where: {
id: args.id,
},
});
if (session && session.date < new Date()) {
console.log(session.date, new Date());
return await prisma.session.update({
where: {
id: args.id,
},
data: {
isCompleted: true,
},
});
}
} catch (error) {
console.log(error);
}
},
}
model Session {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
// updatedAt DateTime @updatedAt
isCompleted Boolean @default(false)
title String
date DateTime
isCanceled Boolean @default(false)
}