From 7f29cfccb672d5af1357dfd099ec0159617154a9 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Tue, 23 Apr 2024 12:04:43 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20ne=20montre=20que=20les=20=C3=A9v=C3=A8?= =?UTF-8?q?nements=20=C3=A0=20venir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/contentful.ts | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/lib/contentful.ts b/src/lib/contentful.ts index 0792ce2..93c92de 100644 --- a/src/lib/contentful.ts +++ b/src/lib/contentful.ts @@ -1,4 +1,5 @@ import contentful, {type Entry, type EntryFieldTypes} from "contentful"; +import type { Document } from '@contentful/rich-text-types'; export const contentfulClient = contentful.createClient({ space: import.meta.env.CONTENTFUL_SPACE_ID, @@ -21,8 +22,26 @@ export interface ContentFulEvenement { } -export const evenementFromContentfull = ({ fields: { nom, slug, description, date, affiche, lieu, lieuUrl, position } }: Entry) => ({ - nom, slug, description, date, affiche, lieu, lieuUrl, position +export const evenementFromContentfull = ({ + fields: { + nom, + slug, + description, + date, + affiche, + lieu, + lieuUrl, + position + } + }: Entry): Évènement => ({ + nom: nom as string, + slug: slug as string, + description: description as Document, + date: date as ContentfulDate, + affiche, + lieu: lieu as string | undefined, + lieuUrl: lieuUrl as string | undefined, + position }) export const sortByDate = (evenements: Entry[]): Entry[] => { @@ -33,10 +52,28 @@ export const sortByDate = (evenements: Entry[]): Entry= 0); +} + export const fetchEvenements = async () => { const entries = await contentfulClient.getEntries({ content_type: "evenement", }); - return sortByDate(entries.items).map(evenementFromContentfull) + return sortByDate(entries.items) + .map(evenementFromContentfull) + .filter(estÀVenir) }