Skip to content

Commit

Permalink
Adjust mark song played event validation
Browse files Browse the repository at this point in the history
previously we disabled recording songs played in same day

but in truth we can allow it as long as it's more than 10 minutes ago
  • Loading branch information
dvnrsn committed Dec 2, 2023
1 parent 344c668 commit e642d2a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions app/models/song.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,20 @@ export async function markSongPlaybackEvent({
songId: Song["id"];
userId?: User["id"];
}) {
const todayStart = new Date();
todayStart.setHours(0, 0, 0, 0);
const todayEnd = new Date();
todayEnd.setHours(23, 59, 59, 999);
const tenMinutesAgo = new Date();
tenMinutesAgo.setMinutes(tenMinutesAgo.getMinutes() - 10);

const playbackToday = await prisma.playbackEvent.findFirst({
const songPlayedInLastTenMinutes = await prisma.playbackEvent.findFirst({
where: {
songId,
createdAt: {
gte: todayStart,
lte: todayEnd,
gte: tenMinutesAgo,
lte: new Date(),
},
},
});

if (playbackToday) {
if (songPlayedInLastTenMinutes) {
return { alreadyMarked: true };
}

Expand Down

0 comments on commit e642d2a

Please sign in to comment.