Remove userVisitedAdventuresTable
This commit is contained in:
@@ -32,3 +32,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<svelte:head>
|
||||
<title>Home | AdventureLog</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="AdventureLog is a platform to log your adventures."
|
||||
/>
|
||||
</svelte:head>
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { userVisitedAdventures } from "$lib/db/schema";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
|
||||
export async function DELETE(event: RequestEvent): Promise<Response> {
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "No user found" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let res = await db
|
||||
.delete(userVisitedAdventures)
|
||||
.where(
|
||||
eq(userVisitedAdventures.userId, event.locals.user.id),
|
||||
)
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "No user found" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
let res = await db
|
||||
.delete(adventureTable)
|
||||
.where(eq(adventureTable.userId, event.locals.user.id))
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { userVisitedAdventures, userVisitedWorldTravel } from "$lib/db/schema";
|
||||
import { userVisitedWorldTravel } from "$lib/db/schema";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
|
||||
export async function POST(event: RequestEvent): Promise<Response> {
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let body = await event.request.json();
|
||||
let res = await db
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let body = await event.request.json();
|
||||
let res = await db
|
||||
.insert(userVisitedWorldTravel)
|
||||
.values({
|
||||
userId: event.locals.user.id,
|
||||
region_id: body.region_id,
|
||||
country_code: body.country_code,
|
||||
userId: event.locals.user.id,
|
||||
region_id: body.region_id,
|
||||
country_code: body.country_code,
|
||||
})
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function GET(event: RequestEvent): Promise<Response> {
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let res = await db
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let res = await db
|
||||
.select()
|
||||
.from(userVisitedWorldTravel)
|
||||
.where(eq(userVisitedWorldTravel.userId,event.locals.user.id));
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
.where(eq(userVisitedWorldTravel.userId, event.locals.user.id));
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent): Promise<Response> {
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let body = await event.request.json();
|
||||
let res = await db
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
let body = await event.request.json();
|
||||
let res = await db
|
||||
.delete(userVisitedWorldTravel)
|
||||
.where(
|
||||
and(
|
||||
eq(userVisitedWorldTravel.userId, event.locals.user.id),
|
||||
eq(userVisitedWorldTravel.region_id, body.region_id),
|
||||
)
|
||||
and(
|
||||
eq(userVisitedWorldTravel.userId, event.locals.user.id),
|
||||
eq(userVisitedWorldTravel.region_id, body.region_id)
|
||||
)
|
||||
)
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ res: res }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
import { count } from 'drizzle-orm';
|
||||
import { count } from "drizzle-orm";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { userVisitedAdventures } from "$lib/db/schema";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
import { db } from "$lib/db/db.server";
|
||||
|
||||
export async function GET(event: RequestEvent): Promise<Response> {
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "No user found" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
// get the count of the number of adventures the user has visited
|
||||
let result = await db
|
||||
.select({ count: count() })
|
||||
.from(userVisitedAdventures)
|
||||
.where(eq(userVisitedAdventures.userId,event.locals.user.id))
|
||||
.execute();
|
||||
if (!event.locals.user) {
|
||||
return new Response(JSON.stringify({ error: "No user found" }), {
|
||||
status: 401,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
// get the count of the number of adventures the user has visited
|
||||
let result = await db
|
||||
.select({ count: count() })
|
||||
.from(adventureTable)
|
||||
.where(eq(adventureTable.userId, event.locals.user.id))
|
||||
.execute();
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
visitCount: result[0].count,
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
visitCount: result[0].count,
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { lucia } from "$lib/server/auth";
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
import { adventureTable, userVisitedAdventures } from "$lib/db/schema";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
|
||||
@@ -11,15 +11,21 @@
|
||||
});
|
||||
|
||||
async function add(event: CustomEvent<{ name: string; location: string }>) {
|
||||
let newAdventure: Adventure = {
|
||||
name: event.detail.name,
|
||||
location: event.detail.location,
|
||||
date: "",
|
||||
type: "mylog",
|
||||
id: -1,
|
||||
};
|
||||
|
||||
const response = await fetch("/api/visits", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: event.detail.name,
|
||||
location: event.detail.location,
|
||||
date: "",
|
||||
newAdventure,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import { error, redirect, type Actions, type Handle } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import {
|
||||
adventureTable,
|
||||
sessionTable,
|
||||
userTable,
|
||||
userVisitedAdventures,
|
||||
userVisitedWorldTravel,
|
||||
} from "$lib/db/schema";
|
||||
import type { DatabaseUser } from "$lib/server/auth";
|
||||
@@ -25,7 +25,7 @@ export const load: PageServerLoad = async (event) => {
|
||||
users = (await db.select().from(userTable).execute()) as DatabaseUser[];
|
||||
visitCount = (await db
|
||||
.select({ count: count() })
|
||||
.from(userVisitedAdventures)
|
||||
.from(adventureTable)
|
||||
.execute()) as unknown as number;
|
||||
userCount = (await db
|
||||
.select({ count: count() })
|
||||
|
||||
Reference in New Issue
Block a user