Skip to content

Commit

Permalink
fix: 🐛 correct data fetching types
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed May 28, 2024
1 parent 30226ac commit df0dd59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,8 @@ export type MeetingInsertSchema = typeof meetings.$inferInsert;
export type MeetingSelectSchema = typeof meetings.$inferSelect;
export type MeetingDateInsertSchema = typeof meetingDates.$inferInsert;
export type MeetingDateSelectSchema = typeof meetingDates.$inferSelect;

export type AvailabilityMeetingDateJoinSchema = {
availabilities: typeof availabilities.$inferSelect;
meeting_dates: typeof meetingDates.$inferSelect;
};
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: "",
guestName: "awaw",
meetingId: "",
});
12 changes: 6 additions & 6 deletions src/lib/utils/availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PageData } from "../../routes/availability/[slug]/$types";

import { ZotDate } from "./ZotDate";

import type { AvailabilityInsertSchema } from "$lib/db/schema";
import type { AvailabilityMeetingDateJoinSchema } from "$lib/db/schema";
import type { GuestSession } from "$lib/types/availability";

export async function getGuestAvailability(guestSession: GuestSession) {
Expand All @@ -14,14 +14,14 @@ export async function getGuestAvailability(guestSession: GuestSession) {
},
});

const guestData: AvailabilityInsertSchema[] = await response.json();
const guestData: AvailabilityMeetingDateJoinSchema[] = await response.json();

return guestData?.map(
(availability) =>
new ZotDate(
new Date(availability.day),
new Date(availability.meeting_dates.date),
false,
Array.from(availability.availability_string).map((char) => char === "1"),
Array.from(availability.availabilities.availability_string).map((char) => char === "1"),
),
);
}
Expand All @@ -31,9 +31,9 @@ export const getUserAvailability = (data: PageData) => {
return data.availability?.map(
(availability) =>
new ZotDate(
new Date(availability.day),
new Date(availability.meeting_dates.date),
false,
Array.from(availability.availability_string).map((char) => char === "1"),
Array.from(availability.availabilities.availability_string).map((char) => char === "1"),
),
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/routes/availability/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
meetingDates,
membersInMeeting,
type AvailabilityInsertSchema,
type AvailabilityMeetingDateJoinSchema,
type MeetingDateSelectSchema,
} from "$lib/db/schema";
import type { ZotDate } from "$lib/utils/ZotDate";
Expand All @@ -31,7 +32,10 @@ export const load: PageServerLoad = (async ({ locals, params }) => {
};
}) satisfies PageServerLoad;

const getAvailability = async (user: User, meetingId: string | undefined) => {
const getAvailability = async (
user: User,
meetingId: string | undefined,
): Promise<AvailabilityMeetingDateJoinSchema[]> => {
const availability = await db
.select()
.from(availabilities)
Expand All @@ -40,7 +44,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.meeting_dates).sort((a, b) => (a.date < b.date ? -1 : 1));
return availability.sort((a, b) => (a.meeting_dates.date > b.meeting_dates.date ? 1 : -1));
};

export const actions: Actions = {
Expand Down

0 comments on commit df0dd59

Please sign in to comment.