From 29baa39a94b05fc739d5e73b0e46ae0ac50ce61f Mon Sep 17 00:00:00 2001 From: Ardeman Date: Fri, 14 Mar 2025 12:54:15 +0800 Subject: [PATCH] fix: update start_date and end_date fields to be non-nullable and filter ads based on date range --- app/apis/common/get-ads.ts | 4 ++-- app/routes/_news.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/apis/common/get-ads.ts b/app/apis/common/get-ads.ts index f3583ee..743594a 100644 --- a/app/apis/common/get-ads.ts +++ b/app/apis/common/get-ads.ts @@ -6,8 +6,8 @@ const adResponseSchema = z.object({ id: z.string(), image_url: z.string(), url: z.string(), - start_date: z.string().nullable(), - end_date: z.string().nullable(), + start_date: z.string(), + end_date: z.string(), }) const adsResponseSchema = z.object({ data: z.array(adResponseSchema), diff --git a/app/routes/_news.tsx b/app/routes/_news.tsx index 6666bec..1b8f307 100644 --- a/app/routes/_news.tsx +++ b/app/routes/_news.tsx @@ -27,7 +27,12 @@ export const loader = async ({ request }: Route.LoaderArgs) => { } const { data: subscribePlanData } = await getSubscribePlan() const { data: categoriesData } = await getCategories() - const { data: adsData } = await getAds() + let { data: adsData } = await getAds() + adsData = adsData.filter( + (ad) => + new Date(ad.start_date) <= new Date() && + new Date(ad.end_date) >= new Date(), + ) return { userData,