From 1c420d9db89b60503787fa8a73e20bdd59583692 Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Wed, 28 Aug 2024 10:22:07 +0200 Subject: [PATCH] feat: :sparkles: use zero-time day for queries --- src/api/announcements.ts | 7 +++++-- src/api/holidays.ts | 7 +++++-- src/api/vacations.ts | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/api/announcements.ts b/src/api/announcements.ts index 50f3f2a..185f73b 100644 --- a/src/api/announcements.ts +++ b/src/api/announcements.ts @@ -7,14 +7,17 @@ export const getCurrentAnnouncements = async ( const payload = await getPayload(); const today = new Date(); + const todayDay = new Date(today.getFullYear(), today.getMonth(), today.getDay()); return await payload.find({ collection: "announcement", sort: "from", where: { or: [ - { from: { equals: today } }, - { and: [{ from: { less_than_equal: today } }, { to: { greater_than_equal: today } }] }, + { from: { equals: todayDay } }, + { + and: [{ from: { less_than_equal: todayDay } }, { to: { greater_than_equal: todayDay } }], + }, ], }, pagination: false, diff --git a/src/api/holidays.ts b/src/api/holidays.ts index 570a928..791eba9 100644 --- a/src/api/holidays.ts +++ b/src/api/holidays.ts @@ -7,14 +7,17 @@ export const getCurrentHolidays = async ( const payload = await getPayload(); const today = new Date(); + const todayDay = new Date(today.getFullYear(), today.getMonth(), today.getDay()); return await payload.find({ collection: "holiday", sort: "from", where: { or: [ - { from: { equals: today } }, - { and: [{ from: { less_than_equal: today } }, { to: { greater_than_equal: today } }] }, + { from: { equals: todayDay } }, + { + and: [{ from: { less_than_equal: todayDay } }, { to: { greater_than_equal: todayDay } }], + }, ], }, pagination: false, diff --git a/src/api/vacations.ts b/src/api/vacations.ts index 1fc7153..303590c 100644 --- a/src/api/vacations.ts +++ b/src/api/vacations.ts @@ -7,14 +7,17 @@ export const getCurrentVacations = async ( const payload = await getPayload(); const today = new Date(); + const todayDay = new Date(today.getFullYear(), today.getMonth(), today.getDay()); return await payload.find({ collection: "vacation", sort: "from", where: { or: [ - { from: { equals: today } }, - { and: [{ from: { less_than_equal: today } }, { to: { greater_than_equal: today } }] }, + { from: { equals: todayDay } }, + { + and: [{ from: { less_than_equal: todayDay } }, { to: { greater_than_equal: todayDay } }], + }, ], }, pagination: false,