From 421a283d6c33ae8d1f309a65faa8b06d44686011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Mon, 25 Sep 2023 19:53:01 -0400 Subject: [PATCH] refactor(server/middleware): inject ficmas data into request context via middleware to make sure people can't see ficmas stories in listings --- server/middleware/10.ficmasData.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server/middleware/10.ficmasData.ts diff --git a/server/middleware/10.ficmasData.ts b/server/middleware/10.ficmasData.ts new file mode 100644 index 0000000..55ec07c --- /dev/null +++ b/server/middleware/10.ficmasData.ts @@ -0,0 +1,22 @@ +import { Ficmas } from "~/models/challenges/ficmas"; + +export default eventHandler(async (event) => { + let y = new Date().getFullYear() + let fmfilt: any = {}; + + if (!!process.env.JulyFicmas && new Date() < new Date(Date.parse('Aug 1 ' + y))) { + fmfilt.isAnniversary = true; + fmfilt.year = y; + } else if (new Date() < new Date(Date.parse('Dec 25 ' + y))) { + fmfilt.year = process.env.YEAR; + fmfilt.isAnniversary = false; + } else { + fmfilt.keythatdoesntexist = { + $exists: true + } + } + let ficmasarray_raw = await Ficmas.find(fmfilt) + // console.log(ficsHidden()); + // console.log(query); + event.context.ficmasarray_raw = ficmasarray_raw +}) \ No newline at end of file