Skip to content

Commit

Permalink
fix: 🐛 resolve schema issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed May 28, 2024
1 parent f2694e4 commit 30226ac
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
let currentPage = 0;
console.log(currentPage, lastPage);
let currentPageAvailability: (ZotDate | null)[];
let selectionState: SelectionStateType | null = null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/availabilityStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ export const isEditingAvailability = writable<boolean>(false);
export const isStateUnsaved = writable<boolean>(false);

export const guestSession = writable<GuestSession>({
guestName: "yippee",
guestName: "",
meetingId: "",
});
12 changes: 9 additions & 3 deletions src/routes/api/availability/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { and, eq } from "drizzle-orm";
import type { RequestHandler } from "./$types";

import { db } from "$lib/db/drizzle";
import { availabilities, guests } from "$lib/db/schema";
import { availabilities, guests, meetingDates } from "$lib/db/schema";

export const POST: RequestHandler = async ({ request }) => {
const data = await request.json();
Expand All @@ -25,11 +25,17 @@ export const POST: RequestHandler = async ({ request }) => {
const availability = await db
.select()
.from(availabilities)
.where(eq(availabilities.member_id, guest.id));
.innerJoin(meetingDates, eq(availabilities.meeting_day, meetingDates.id))
.where(
and(
eq(availabilities.member_id, guest.id),
eq(meetingDates.meeting_id, data.meetingId ?? ""),
),
);

if (availability.length == 0) {
return json([]);
}

return json(availability.sort((a, b) => (a.day < b.day ? -1 : 1)));
return json(availability.sort((a, b) => (a.meeting_dates.date > b.meeting_dates.date ? 1 : -1)));
};
3 changes: 0 additions & 3 deletions src/routes/api/availability/saveGuest/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import type { ZotDate } from "$lib/utils/ZotDate";
export async function POST({ request }: { request: Request }) {
const formData = await request.formData();

console.log(formData.get("availabilityDates"));
const availabilityDates: ZotDate[] = JSON.parse(
(formData.get("availabilityDates") as string) ?? "[]",
);
const meetingId = (formData.get("meetingId") as string) ?? "";

console.log(availabilityDates, meetingId);

let dbMeetingDates: MeetingDateSelectSchema[] = [];

try {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/availability/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getAvailability = async (user: User, meetingId: string | undefined) => {
and(eq(availabilities.member_id, user.id), eq(meetingDates.meeting_id, meetingId ?? "")),
);

return availability.map((item) => item.availabilities).sort((a, b) => (a.day < b.day ? -1 : 1));
return availability.map((item) => item.meeting_dates).sort((a, b) => (a.date < b.date ? -1 : 1));
};

export const actions: Actions = {
Expand Down
2 changes: 0 additions & 2 deletions src/routes/summary/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ 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.startDate?.toLocaleDateString();
Expand Down

0 comments on commit 30226ac

Please sign in to comment.