Skip to content

Commit

Permalink
Update Evnt db with create new ev + fix form issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 17, 2024
1 parent c55f7cb commit 2010c68
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/(auth)/login/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function LoginForm(props: Props) {
async function handleLogin(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

const response = await fetch('api/login', {
const response = await fetch('/api/login', {
method: 'POST',
body: JSON.stringify({
email,
Expand Down
2 changes: 1 addition & 1 deletion app/(auth)/register/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function RegisterForm() {
async function handleRegister(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

const response = await fetch('api/register', {
const response = await fetch('/api/register', {
method: 'POST',
body: JSON.stringify({
username,
Expand Down
9 changes: 9 additions & 0 deletions app/api/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NextResponse } from 'next/server';

type RootResponseBodyGet = {
events: string;
};

export function GET(): NextResponse<RootResponseBodyGet> {
return NextResponse.json({ events: '/api/events' });
}
47 changes: 47 additions & 0 deletions database/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,50 @@ export const getEventInsecure = cache(async (id: number) => {

return event;
});

export const createEvent = cache(
async (sessionToken: string, newEvent: Omit<Event, 'id'>) => {
const [event] = await sql<Event[]>`

Check failure on line 47 in database/events.ts

View workflow job for this annotation

GitHub Actions / Jest Unit Tests, Type Checking, Linting, Playwright End to End Tests

Invalid Query: Error: syntax error at or near "FROM"
INSERT INTO
events (
user_id,
name,
type,
date,
location,
duration,
entry_fee,
category,
description,
image,
organizer_url,
age_restriction,
archived
)
VALUES
(
${newEvent.userId},
${newEvent.name},
${newEvent.type},
${newEvent.date},
${newEvent.location},
${newEvent.duration},
${newEvent.entryFee},
${newEvent.category},
${newEvent.description},
${newEvent.image},
${newEvent.organizerUrl},
${newEvent.ageRestriction},
${newEvent.archived}
FROM
sessions
WHERE
token = ${sessionToken}
AND sessions.expiry_timestamp > now()
)
RETURNING
events.*
`;
return event;
},
);

0 comments on commit 2010c68

Please sign in to comment.