-
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.
- Loading branch information
1 parent
0b7b2e7
commit 6e9af6b
Showing
8 changed files
with
157 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { fail } from "@sveltejs/kit"; | ||
import { generateId } from "lucia"; | ||
import { setError, superValidate } from "sveltekit-superforms/client"; | ||
|
||
import { _getMeeting } from "../../availability/+page.server"; | ||
|
||
import { guestSchema } from "$lib/config/zod-schemas"; | ||
import { | ||
checkIfGuestUsernameExists, | ||
insertNewGuest, | ||
insertNewMember, | ||
} from "$lib/db/databaseUtils.server"; | ||
import type { AlertMessageType } from "$lib/types/auth"; | ||
|
||
export const _guestSchema = guestSchema.pick({ | ||
username: true, | ||
}); | ||
|
||
export const actions = { | ||
default: createGuest, | ||
}; | ||
|
||
async function createGuest({ request }: { request: Request }) { | ||
const form = await superValidate<typeof _guestSchema, AlertMessageType>(request, _guestSchema); | ||
|
||
if (!form.valid) { | ||
return fail(400, { form }); | ||
} | ||
|
||
try { | ||
const isGuestUsernameAlreadyRegistered = await checkIfGuestUsernameExists( | ||
form.data.username, | ||
await _getMeeting(), | ||
); | ||
|
||
if (isGuestUsernameAlreadyRegistered === true) { | ||
return setError(form, "username", "Guest username already exists"); | ||
} | ||
|
||
const id = generateId(15); | ||
await insertNewMember({ id: id }); | ||
await insertNewGuest({ | ||
username: form.data.username, | ||
id: id, | ||
meeting_id: "e3cf0163-e172-40c5-955a-ae9fa1090dc2", // TODO replace with actual meeting id | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
return setError( | ||
form, | ||
"username", | ||
`An error occurred while processing your request. Please try again. Error: ${error}`, | ||
); | ||
} | ||
|
||
return { form }; | ||
} |
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