-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meeting Creation Functionality (#102)
* style: 🎨 rename groupMembers to groupAvailabilities * feat: ✨ create meeting * refactor(chrono): ♻️ use HourMinuteString instead of string * fix(creation): 🐛 start and end times formats * fix(schema): 🐛 regress to HH:MM format for start and end times * refactor(get meeting): use existing util * feat(create): ✨ add host_id to created meeting * feat(availability): ✨ add member to members_in_meeting * fix: 🐛 remove vestigial function import
- Loading branch information
1 parent
a2cb804
commit 47051c6
Showing
12 changed files
with
166 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { error, json } from "@sveltejs/kit"; | ||
|
||
import { getUserIdFromSession, insertMeeting } from "$lib/db/databaseUtils.server"; | ||
import type { MeetingInsertSchema } from "$lib/db/schema"; | ||
import type { CreateMeetingPostParams } from "$lib/types/meetings"; | ||
|
||
export async function POST({ request }) { | ||
const { title, description, fromTime, toTime, meetingDates, sessionId }: CreateMeetingPostParams = | ||
await request.json(); | ||
|
||
console.log("Creating meeting:", title, description, fromTime, toTime, meetingDates); | ||
|
||
if (fromTime >= toTime) { | ||
error(400, "From time must be before to time"); | ||
} | ||
|
||
if (meetingDates.length === 0) { | ||
error(400, "At least one date must be provided"); | ||
} | ||
|
||
// Just so we don't get flooded too easily | ||
if (meetingDates.length > 100) { | ||
error(400, "Too many dates provided"); | ||
} | ||
|
||
const sortedDates = meetingDates | ||
.map((dateString) => new Date(dateString)) | ||
.sort((a, b) => a.getUTCMilliseconds() - b.getUTCMilliseconds()); | ||
|
||
const host_id = sessionId ? await getUserIdFromSession(sessionId) : undefined; | ||
|
||
const meeting: MeetingInsertSchema = { | ||
title, | ||
description: description || "", | ||
from_time: fromTime, | ||
to_time: toTime, | ||
host_id, | ||
}; | ||
|
||
try { | ||
const meetingId = await insertMeeting(meeting, sortedDates); | ||
return json({ meetingId }); | ||
} catch (err) { | ||
console.log("Error creating meeting:", err); | ||
error(500, "Error creating meeting"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.