From 73f27a8450030c2b928c12e51775cd07f86dbc71 Mon Sep 17 00:00:00 2001 From: Adithya Anandsaikrishnan Date: Mon, 29 Apr 2024 14:07:40 -0700 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E2=9C=A8=20created=20function=20to?= =?UTF-8?q?=20get=20user=20from=20sessionID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adithya Anandsaikrishnan --- src/lib/db/databaseUtils.server.ts | 15 ++++++++++++- src/lib/db/schema.ts | 12 +++++++---- src/routes/summary/+page.server.ts | 34 ++++++++++++++++++++++++++++++ src/routes/summary/+page.svelte | 3 +++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/routes/summary/+page.server.ts diff --git a/src/lib/db/databaseUtils.server.ts b/src/lib/db/databaseUtils.server.ts index a850d8c6..72694371 100644 --- a/src/lib/db/databaseUtils.server.ts +++ b/src/lib/db/databaseUtils.server.ts @@ -3,7 +3,7 @@ import type { SuperValidated } from "sveltekit-superforms"; import type { ZodObject, ZodString } from "zod"; import { db } from "./drizzle"; -import { users, type UserInsertSchema } from "./schema"; +import { users, type UserInsertSchema, sessions } from "./schema"; import type { AlertMessageType } from "$lib/types/auth"; @@ -60,3 +60,16 @@ export const getExistingUser = async ( return existingUser; }; + +export const getUserFromSession = async (sessionID: string | undefined) => { + if (sessionID === undefined) { + return ""; + } + const { userId } = ( + await db + .selectDistinct({ userId: sessions.userId }) + .from(sessions) + .where(eq(sessions.id, sessionID)) + )[0]; + return userId; +}; diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 23d919ff..0ba02167 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -5,7 +5,6 @@ import { timestamp, index, smallint, - date, primaryKey, pgEnum, boolean, @@ -82,7 +81,6 @@ export const groups = pgTable("groups", { export const availabilities = pgTable( "availabilities", { - day: date("day").notNull(), member_id: text("member_id") .notNull() .references(() => members.id, { onDelete: "cascade" }), @@ -96,6 +94,7 @@ export const availabilities = pgTable( pk: primaryKey({ columns: [table.member_id, table.meeting_day] }), }), ); + // meeting_day export const oauthAccountsTable = pgTable( "oauth_accounts", @@ -210,16 +209,16 @@ export const meetingsRelations = relations(meetings, ({ one, many }) => ({ fields: [meetings.host_id], references: [members.id], }), - availabilities: many(availabilities), membersInMeeting: many(membersInMeeting), meetingDates: many(meetingDates), })); -export const meetingDateRelations = relations(meetingDates, ({ one }) => ({ +export const meetingDatesRelations = relations(meetingDates, ({ one, many }) => ({ meetings: one(meetings, { fields: [meetingDates.meeting_id], references: [meetings.id], }), + availabilities: many(availabilities), })); export const sessionsRelations = relations(sessions, ({ one }) => ({ @@ -247,4 +246,9 @@ export const availabilitiesRelations = relations(availabilities, ({ one }) => ({ }), })); +export type MemberInsertSchema = typeof members.$inferInsert; export type UserInsertSchema = typeof users.$inferInsert; +export type GuestInsertSchema = typeof guests.$inferInsert; +export type AvailabilityInsertSchema = typeof availabilities.$inferInsert; +export type MeetingSelectSchema = typeof meetings.$inferSelect; +export type MeetingDateSelectSchema = typeof meetingDates.$inferSelect; diff --git a/src/routes/summary/+page.server.ts b/src/routes/summary/+page.server.ts new file mode 100644 index 00000000..89c4828b --- /dev/null +++ b/src/routes/summary/+page.server.ts @@ -0,0 +1,34 @@ +import { eq } from "drizzle-orm"; + +import type { PageServerLoad } from "./$types"; + +import { getUserFromSession } from "$lib/db/databaseUtils.server"; +import { db } from "$lib/db/drizzle"; +import { availabilities, meetingDates, meetings } from "$lib/db/schema"; + +export const load: PageServerLoad = async ({ cookies }) => { + const sessionID = cookies.get("session"); + + console.log(sessionID, "sessionID"); + const user_id = await getUserFromSession(sessionID); + console.log(user_id); + + const meetingList = await db + .select({ + name: meetings.title, + id: meetings.id, + startTime: meetings.from_time, + endTime: meetings.to_time, + location: meetings.location, + scheduled: meetings.scheduled, + }) + .from(availabilities) + .leftJoin(meetingDates, eq(availabilities.meeting_day, meetingDates.id)) + .leftJoin(meetings, eq(meetings.id, meetingDates.meeting_id)) + .groupBy(meetings.id) + .where(eq(availabilities.member_id, user_id)); + console.log(meetingList); + return { + meetings: meetingList, + }; +}; diff --git a/src/routes/summary/+page.svelte b/src/routes/summary/+page.svelte index f9e269b7..01219cb4 100644 --- a/src/routes/summary/+page.svelte +++ b/src/routes/summary/+page.svelte @@ -1,8 +1,11 @@ From 5a7fd9256c8b7a752d1e5c510d91ad85f9cbfa51 Mon Sep 17 00:00:00 2001 From: Adithya Anandsaikrishnan Date: Mon, 29 Apr 2024 18:16:28 -0700 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E2=9C=A8=20implemented=20summary?= =?UTF-8?q?=20retrieval=20from=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adithya Anandsaikrishnan --- src/lib/stores/summaryStores.ts | 8 +++--- src/lib/types/meetings.ts | 2 +- src/routes/summary/+page.server.ts | 46 +++++++++++++++++++++++++++--- src/routes/summary/+page.svelte | 7 +++-- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/lib/stores/summaryStores.ts b/src/lib/stores/summaryStores.ts index c617198d..e1f2db4e 100644 --- a/src/lib/stores/summaryStores.ts +++ b/src/lib/stores/summaryStores.ts @@ -94,7 +94,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [ startTime: "11:00", endTime: "13:30", location: "CSL 8", - hasIndicated: false, + // hasIndicated: false, }, { name: "Meeting Dos", @@ -105,7 +105,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [ startTime: "8:00", endTime: "15:00", location: "CSL 8", - hasIndicated: true, + // hasIndicated: true, }, { name: "Meeting Tres", @@ -116,7 +116,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [ startTime: "8:00", endTime: "15:00", location: "CSL 8", - hasIndicated: true, + // hasIndicated: true, }, { name: "Meeting Quatro", @@ -127,7 +127,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [ startTime: "8:00", endTime: "15:00", location: "CSL 8", - hasIndicated: false, + // hasIndicated: false, }, ]; diff --git a/src/lib/types/meetings.ts b/src/lib/types/meetings.ts index b0a9dfa8..b6f68792 100644 --- a/src/lib/types/meetings.ts +++ b/src/lib/types/meetings.ts @@ -24,7 +24,7 @@ export type UnscheduledMeeting = { startTime: string; endTime: string; location: string; - hasIndicated: boolean; + // hasIndicated: boolean; }; export type MeetingTime = { diff --git a/src/routes/summary/+page.server.ts b/src/routes/summary/+page.server.ts index 89c4828b..c17789ab 100644 --- a/src/routes/summary/+page.server.ts +++ b/src/routes/summary/+page.server.ts @@ -5,13 +5,13 @@ import type { PageServerLoad } from "./$types"; import { getUserFromSession } from "$lib/db/databaseUtils.server"; import { db } from "$lib/db/drizzle"; import { availabilities, meetingDates, meetings } from "$lib/db/schema"; +import type { ScheduledMeeting, UnscheduledMeeting } from "$lib/types/meetings"; export const load: PageServerLoad = async ({ cookies }) => { + // get user id from session const sessionID = cookies.get("session"); - console.log(sessionID, "sessionID"); const user_id = await getUserFromSession(sessionID); - console.log(user_id); const meetingList = await db .select({ @@ -27,8 +27,46 @@ export const load: PageServerLoad = async ({ cookies }) => { .leftJoin(meetings, eq(meetings.id, meetingDates.meeting_id)) .groupBy(meetings.id) .where(eq(availabilities.member_id, user_id)); - console.log(meetingList); + + const scheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === true); + const scheduled: ScheduledMeeting[] = scheduledMeetings.map((meeting) => { + const meetingDate = meeting.startTime?.toLocaleDateString(); + const start = meeting.startTime?.toLocaleTimeString(); + const end = meeting.endTime?.toLocaleTimeString(); + return { + name: meeting.name, + id: meeting.id, + link: "www.google.com", + date: meetingDate, + startTime: start, + endTime: end, + attendance: "maybe", + location: meeting.location, + } as unknown as ScheduledMeeting; + }); + + const unscheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === false); + + const unscheduled: UnscheduledMeeting[] = unscheduledMeetings.map((meeting) => { + const startDate = meeting.startTime?.toLocaleDateString(); + const endDate = meeting.endTime?.toLocaleDateString(); + const startTime = meeting.startTime?.toLocaleTimeString(); + const endTime = meeting.endTime?.toLocaleTimeString(); + return { + name: meeting.name, + id: meeting.id, + link: "www.google.com", + startDate, + endDate, + startTime, + endTime, + attendance: "maybe", + location: meeting.location, + } as unknown as UnscheduledMeeting; + }); + return { - meetings: meetingList, + scheduled, + unscheduled, }; }; diff --git a/src/routes/summary/+page.svelte b/src/routes/summary/+page.svelte index 01219cb4..66c07d05 100644 --- a/src/routes/summary/+page.svelte +++ b/src/routes/summary/+page.svelte @@ -1,11 +1,14 @@ From 87fb1f6c4b5dee1156952c9facc70db011670296 Mon Sep 17 00:00:00 2001 From: Adithya Anandsaikrishnan Date: Mon, 20 May 2024 16:09:58 -0700 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E2=9C=A8=20modified?= =?UTF-8?q?=20attendance=20to=20align=20with=20schema.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adithya Anandsaikrishnan --- src/lib/db/schema.ts | 6 ++---- src/routes/summary/+page.server.ts | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 8abe7a9f..0d82ac40 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -16,13 +16,11 @@ import { export const attendanceValues = ["accepted", "maybe", "declined"] as const; export type AttendanceValue = (typeof attendanceValues)[number]; -export const attendanceEnum = pgEnum("attendance", attendanceValues); -export const memberEnum = pgEnum("member_type", ["guest", "user"]); +export const attendanceEnum = pgEnum("attendance", ["accepted", "maybe", "declined"]); // Members encompasses anyone who uses ZotMeet, regardless of guest or user status. export const members = pgTable("members", { id: text("id").primaryKey(), - type: memberEnum("type").notNull().default("guest"), }); // Users encompasses Members who have created an account. @@ -160,7 +158,7 @@ export const membersInMeeting = pgTable( meetingId: uuid("meeting_id") .notNull() .references(() => meetings.id, { onDelete: "cascade" }), - attending: attendanceEnum("attendance"), + attending: attendanceEnum("maybe"), }, (table) => ({ pk: primaryKey({ columns: [table.memberId, table.meetingId] }), diff --git a/src/routes/summary/+page.server.ts b/src/routes/summary/+page.server.ts index c17789ab..f6607436 100644 --- a/src/routes/summary/+page.server.ts +++ b/src/routes/summary/+page.server.ts @@ -1,17 +1,16 @@ -import { eq } from "drizzle-orm"; +import { eq, min, max } from "drizzle-orm"; import type { PageServerLoad } from "./$types"; -import { getUserFromSession } from "$lib/db/databaseUtils.server"; +import { getUserIdFromSession } from "$lib/db/databaseUtils.server"; import { db } from "$lib/db/drizzle"; import { availabilities, meetingDates, meetings } from "$lib/db/schema"; import type { ScheduledMeeting, UnscheduledMeeting } from "$lib/types/meetings"; export const load: PageServerLoad = async ({ cookies }) => { // get user id from session - const sessionID = cookies.get("session"); - - const user_id = await getUserFromSession(sessionID); + const sessionID = cookies.get("session")!; + const user_id = await getUserIdFromSession(sessionID); const meetingList = await db .select({ @@ -21,6 +20,8 @@ export const load: PageServerLoad = async ({ cookies }) => { endTime: meetings.to_time, location: meetings.location, scheduled: meetings.scheduled, + startDate: min(meetingDates.date), + endDate: max(meetingDates.date), }) .from(availabilities) .leftJoin(meetingDates, eq(availabilities.meeting_day, meetingDates.id)) @@ -28,11 +29,13 @@ export const load: PageServerLoad = async ({ cookies }) => { .groupBy(meetings.id) .where(eq(availabilities.member_id, user_id)); + console.log(meetingList); + const scheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === true); const scheduled: ScheduledMeeting[] = scheduledMeetings.map((meeting) => { - const meetingDate = meeting.startTime?.toLocaleDateString(); - const start = meeting.startTime?.toLocaleTimeString(); - const end = meeting.endTime?.toLocaleTimeString(); + const meetingDate = meeting.startDate?.toLocaleDateString(); + const start = meeting.startTime; + const end = meeting.endTime; return { name: meeting.name, id: meeting.id, @@ -48,10 +51,10 @@ export const load: PageServerLoad = async ({ cookies }) => { const unscheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === false); const unscheduled: UnscheduledMeeting[] = unscheduledMeetings.map((meeting) => { - const startDate = meeting.startTime?.toLocaleDateString(); - const endDate = meeting.endTime?.toLocaleDateString(); - const startTime = meeting.startTime?.toLocaleTimeString(); - const endTime = meeting.endTime?.toLocaleTimeString(); + const startDate = meeting.startDate?.toLocaleDateString(); + const endDate = meeting.endDate?.toLocaleDateString(); + const startTime = meeting.startTime; + const endTime = meeting.endTime; return { name: meeting.name, id: meeting.id, From 8381a8a5444156ed3b010ffb70d60c9e2cb2f724 Mon Sep 17 00:00:00 2001 From: Adithya Anandsaikrishnan Date: Mon, 20 May 2024 16:33:39 -0700 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E2=9C=A8=20swapped?= =?UTF-8?q?=20scheduled=20and=20unscheduled=20meetings=20in=20summary=20pa?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adithya Anandsaikrishnan --- src/routes/summary/+page.server.ts | 2 +- src/routes/summary/+page.svelte | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/routes/summary/+page.server.ts b/src/routes/summary/+page.server.ts index f6607436..b538d24d 100644 --- a/src/routes/summary/+page.server.ts +++ b/src/routes/summary/+page.server.ts @@ -48,7 +48,7 @@ export const load: PageServerLoad = async ({ cookies }) => { } as unknown as ScheduledMeeting; }); - const unscheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === false); + const unscheduledMeetings = meetingList.filter((meeting) => !meeting.scheduled); const unscheduled: UnscheduledMeeting[] = unscheduledMeetings.map((meeting) => { const startDate = meeting.startDate?.toLocaleDateString(); diff --git a/src/routes/summary/+page.svelte b/src/routes/summary/+page.svelte index 66c07d05..43a766a0 100644 --- a/src/routes/summary/+page.svelte +++ b/src/routes/summary/+page.svelte @@ -31,7 +31,7 @@ style:border-color={currentTab === 0 ? "oklch(var(--a))" : undefined} on:click={() => { currentTab = 0; - }}>ScheduledUnscheduled Scheduled From 2be71ec75a3402a19659825c9f0e9bd7204e880e Mon Sep 17 00:00:00 2001 From: Adithya Anandsaikrishnan Date: Mon, 20 May 2024 16:52:48 -0700 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20changed=20attendance?= =?UTF-8?q?=20field=20name=20from=20maybe=20to=20attendance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adithya Anandsaikrishnan --- src/lib/db/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 0d82ac40..64d963f0 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -158,7 +158,7 @@ export const membersInMeeting = pgTable( meetingId: uuid("meeting_id") .notNull() .references(() => meetings.id, { onDelete: "cascade" }), - attending: attendanceEnum("maybe"), + attending: attendanceEnum("availability"), }, (table) => ({ pk: primaryKey({ columns: [table.memberId, table.meetingId] }),