Skip to content

Commit

Permalink
Summary page Backend Functionality (#94)
Browse files Browse the repository at this point in the history
* feat: ✨ created function to get user from sessionID

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>

* feat: ✨ implemented summary retrieval from backend

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>

* fix: 🐛 ✨ modified attendance to align with schema.ts

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>

* fix: 🐛 ✨ swapped scheduled and unscheduled meetings in summary page

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>

* fix: 🐛 changed attendance field name from maybe to attendance

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>

---------

Signed-off-by: Adithya Anandsaikrishnan <[email protected]>
  • Loading branch information
adi-lux authored May 20, 2024
1 parent 47051c6 commit 8eecf2b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
timestamp,
index,
smallint,
date,
primaryKey,
pgEnum,
boolean,
Expand All @@ -17,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.
Expand Down Expand Up @@ -87,7 +84,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" }),
Expand Down Expand Up @@ -162,7 +158,7 @@ export const membersInMeeting = pgTable(
meetingId: uuid("meeting_id")
.notNull()
.references(() => meetings.id, { onDelete: "cascade" }),
attending: attendanceEnum("attendance"),
attending: attendanceEnum("availability"),
},
(table) => ({
pk: primaryKey({ columns: [table.memberId, table.meetingId] }),
Expand Down
8 changes: 4 additions & 4 deletions src/lib/stores/summaryStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [
startTime: "11:00",
endTime: "13:30",
location: "CSL 8",
hasIndicated: false,
// hasIndicated: false,
},
{
name: "Meeting Dos",
Expand All @@ -105,7 +105,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [
startTime: "8:00",
endTime: "15:00",
location: "CSL 8",
hasIndicated: true,
// hasIndicated: true,
},
{
name: "Meeting Tres",
Expand All @@ -116,7 +116,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [
startTime: "8:00",
endTime: "15:00",
location: "CSL 8",
hasIndicated: true,
// hasIndicated: true,
},
{
name: "Meeting Quatro",
Expand All @@ -127,7 +127,7 @@ const dummyUnscheduledMeetings: UnscheduledMeeting[] = [
startTime: "8:00",
endTime: "15:00",
location: "CSL 8",
hasIndicated: false,
// hasIndicated: false,
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/meetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type UnscheduledMeeting = {
startTime: string;
endTime: string;
location: string;
hasIndicated: boolean;
// hasIndicated: boolean;
};

export type MeetingTime = {
Expand Down
75 changes: 75 additions & 0 deletions src/routes/summary/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { eq, min, max } from "drizzle-orm";

import type { PageServerLoad } from "./$types";

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 getUserIdFromSession(sessionID);

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,
startDate: min(meetingDates.date),
endDate: max(meetingDates.date),
})
.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);

const scheduledMeetings = meetingList.filter((meeting) => meeting.scheduled === true);
const scheduled: ScheduledMeeting[] = scheduledMeetings.map((meeting) => {
const meetingDate = meeting.startDate?.toLocaleDateString();
const start = meeting.startTime;
const end = meeting.endTime;
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);

const unscheduled: UnscheduledMeeting[] = unscheduledMeetings.map((meeting) => {
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,
link: "www.google.com",
startDate,
endDate,
startTime,
endTime,
attendance: "maybe",
location: meeting.location,
} as unknown as UnscheduledMeeting;
});

return {
scheduled,
unscheduled,
};
};
14 changes: 10 additions & 4 deletions src/routes/summary/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<script lang="ts">
// import GroupCarousel from "$lib/components/summary/GroupsCarousel.svelte";
import type { PageData } from "./$types";
import ScheduledMeetingsList from "$lib/components/summary/ScheduledMeetings/ScheduledMeetingsList.svelte";
import UnscheduledMeetingsList from "$lib/components/summary/UnscheduledMeetings/UnscheduledMeetingsList.svelte";
import { scheduledMeetings, unscheduledMeetings } from "$lib/stores/summaryStores";
export let data: PageData;
scheduledMeetings.set(data.scheduled);
unscheduledMeetings.set(data.unscheduled);
let currentTab: number = 0;
</script>

Expand All @@ -25,7 +31,7 @@
style:border-color={currentTab === 0 ? "oklch(var(--a))" : undefined}
on:click={() => {
currentTab = 0;
}}>Scheduled</button
}}>Unscheduled</button
>
<button
role="tab"
Expand All @@ -35,7 +41,7 @@
style:border-color={currentTab === 1 ? "oklch(var(--a))" : undefined}
on:click={() => {
currentTab = 1;
}}>Unscheduled</button
}}>Scheduled</button
>
</div>
<div class="hidden w-full border-b-2 border-gray-300 lg:block" />
Expand All @@ -44,9 +50,9 @@

<div>
{#if currentTab === 0}
<ScheduledMeetingsList />
{:else if currentTab === 1}
<UnscheduledMeetingsList />
{:else if currentTab === 1}
<ScheduledMeetingsList />
{/if}
</div>
</div>

0 comments on commit 8eecf2b

Please sign in to comment.