diff --git a/src/api/EndPoint.ts b/src/api/EndPoint.ts index 0964b21..84c3fd6 100644 --- a/src/api/EndPoint.ts +++ b/src/api/EndPoint.ts @@ -19,12 +19,13 @@ export const getEvents = async ({ }) => { try { const user = await GetUser({ event }); - - console.log("you cant be null ", user); + if (user === null || user === undefined) { + return { success: false, data: null, error: "Failed to get events" }; + } const data = await QueryEvents({ event, - options: { ...options, byUser: user?.ID }, + options: { ...options, byUser: user.ID }, }); if (data === null) { diff --git a/src/api/Query.ts b/src/api/Query.ts index 0d07ff2..be8c0c6 100644 --- a/src/api/Query.ts +++ b/src/api/Query.ts @@ -1,6 +1,6 @@ import { Users, Events, Requests, Places } from "../../drizzle/schema"; import type { Session } from "./drizzled"; -import { eq, and, ne, or, not, exists } from "drizzle-orm"; +import { eq, and, ne, or, not, exists, gte } from "drizzle-orm"; import type { Requested } from "./drizzled"; import { drizzler } from "./drizzled"; import type { UpdateUserForm, CreateEventForm } from "~/api/Forms"; @@ -249,6 +249,7 @@ export type QueryEventOptions = { to?: Date; byUser?: number; active?: boolean; + fromDateTime?: Date; }; export const QueryEvent = async (params: { @@ -275,13 +276,13 @@ export const QueryEvent = async (params: { image: Events.ImageURL, }) .from(Events) - .where(eq(Events.EventID, params.id)) + .where(and(eq(Events.EventID, params.id))) + .execute() .catch((e) => { console.log(e); return null; }); - if (event && event.length > 0) { const user = await Client.select() .from(Users) @@ -338,6 +339,7 @@ export const QueryEvents = async (params: { ), ), ne(Events.UserID, params.options.byUser as number), + gte(Events.Date, new Date().toISOString()), ), ) .limit(params.options.limit ?? 3)