diff --git a/src/routes/settings/+page.server.ts b/src/routes/settings/+page.server.ts
index c2cbb5b6..57dfaa5b 100644
--- a/src/routes/settings/+page.server.ts
+++ b/src/routes/settings/+page.server.ts
@@ -11,11 +11,11 @@ export const load: PageServerLoad = async (event) => {
return {
user: event.locals.user,
};
- return redirect(302, "/login");
+ return redirect(302, "/login");
};
export const actions: Actions = {
- default: async (event: { request: { formData: () => any; }; }) => {
+ default: async (event: { request: { formData: () => any } }) => {
const formData = await event.request.formData();
let userId = formData.get("user_id");
let username = formData.get("username");
@@ -26,22 +26,22 @@ export const actions: Actions = {
let password = formData.get("password");
if (!userId) {
- return {
- status: 400,
- body: {
- message: "User ID is required"
- }
- };
+ return {
+ status: 400,
+ body: {
+ message: "User ID is required",
+ },
+ };
}
- if (icon.length > 1) {
- return {
- status: 400,
- body: {
- message: "Icon must be a single character"
- }
- };
- }
+ // if (icon.length > 1) {
+ // return {
+ // status: 400,
+ // body: {
+ // message: "Icon must be a single character",
+ // },
+ // };
+ // }
const usernameTaken = await db
.select()
@@ -50,40 +50,42 @@ export const actions: Actions = {
.limit(1)
.then((results) => results[0] as unknown as DatabaseUser | undefined);
- if (usernameTaken) {
- return {
- status: 400,
- body: {
- message: "Username taken!"
- }
- };
+ if (usernameTaken && usernameTaken.id !== userId) {
+ return {
+ status: 400,
+ body: {
+ message: "Username taken!",
+ },
+ };
}
if (password) {
- let hashedPassword = await new Argon2id().hash(password);
- console.log(hashedPassword)
- await db.update(userTable)
- .set({
- hashed_password: hashedPassword
- })
- .where(eq(userTable.id, userId));
- }
-
- await db.update(userTable)
+ let hashedPassword = await new Argon2id().hash(password);
+ console.log(hashedPassword);
+ await db
+ .update(userTable)
.set({
- username: username,
- first_name: firstName,
- last_name: lastName,
- icon: icon
+ hashed_password: hashedPassword,
})
.where(eq(userTable.id, userId));
-
- return {
- status: 200,
- body: {
- message: "User updated"
-
- }
- };
}
-};
\ No newline at end of file
+
+ await db
+ .update(userTable)
+ .set({
+ username: username,
+ first_name: firstName,
+ last_name: lastName,
+ icon: icon,
+ })
+ .where(eq(userTable.id, userId));
+
+ // return a page refresh
+ return {
+ status: 303,
+ headers: {
+ location: "/settings",
+ },
+ };
+ },
+};
diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte
index 634faedb..81a94e44 100644
--- a/src/routes/settings/+page.svelte
+++ b/src/routes/settings/+page.svelte
@@ -10,6 +10,8 @@
let icon = data.user?.icon;
let signup_date = data.user?.signup_date;
let role = data.user?.role;
+
+ // the submit function shoud just reload the page
diff --git a/src/routes/settings/admin/+page.server.ts b/src/routes/settings/admin/+page.server.ts
index 08f3037f..78a53769 100644
--- a/src/routes/settings/admin/+page.server.ts
+++ b/src/routes/settings/admin/+page.server.ts
@@ -4,6 +4,7 @@ import { db } from "$lib/db/db.server";
import {
adventureTable,
sessionTable,
+ userPlannedTrips,
userTable,
userVisitedWorldTravel,
} from "$lib/db/schema";
@@ -14,6 +15,9 @@ export const load: PageServerLoad = async (event) => {
let users: DatabaseUser[] = [];
let visitCount: number = NaN;
let userCount: number = NaN;
+ let planCount: number = NaN;
+ let tripCount: number = NaN;
+ let featuredCount: number = NaN;
let regionCount: number = NaN;
if (!event.locals.user) {
return redirect(302, "/login");
@@ -36,12 +40,29 @@ export const load: PageServerLoad = async (event) => {
.select({ count: count() })
.from(userVisitedWorldTravel)
.execute()) as unknown as number;
+ planCount = (await db
+ .select({ count: count() })
+ .from(adventureTable)
+ .where(eq(adventureTable.type, "planner"))
+ .execute()) as unknown as number;
+ tripCount = (await db
+ .select({ count: count() })
+ .from(userPlannedTrips)
+ .execute()) as unknown as number;
+ featuredCount = (await db
+ .select({ count: count() })
+ .from(adventureTable)
+ .where(eq(adventureTable.type, "featured"))
+ .execute()) as unknown as number;
}
return {
users,
visitCount,
userCount,
regionCount,
+ planCount,
+ tripCount,
+ featuredCount,
};
};
diff --git a/src/routes/settings/admin/+page.svelte b/src/routes/settings/admin/+page.svelte
index dfc9c8c7..db97cb6a 100644
--- a/src/routes/settings/admin/+page.svelte
+++ b/src/routes/settings/admin/+page.svelte
@@ -62,6 +62,9 @@
let visitCount = $page.data.visitCount[0].count;
let userCount = $page.data.userCount[0].count;
let regionCount = $page.data.regionCount[0].count;
+ let tripCount = $page.data.tripCount[0].count;
+ let planCount = $page.data.planCount[0].count;
+ let featuredCount = $page.data.featuredCount[0].count;
@@ -153,17 +156,29 @@
Total Visits
-
{visitCount}
+
{visitCount}
Total Users
-
{userCount}
+
{userCount}
Visited Regions
-
{regionCount}
+
{regionCount}
+
+
+
Total Trips
+
{tripCount}
+
+
+
Total Plans
+
{planCount}
+
+
+
Featured Adventures
+
{featuredCount}
diff --git a/src/routes/trip/[id]/+page.svelte b/src/routes/trip/[id]/+page.svelte
index 9568f089..223dd150 100644
--- a/src/routes/trip/[id]/+page.svelte
+++ b/src/routes/trip/[id]/+page.svelte
@@ -6,6 +6,7 @@
import CreateNewAdventure from "$lib/components/CreateNewAdventure.svelte";
import {
addAdventure,
+ removeAdventure,
saveAdventure,
} from "../../../services/adventureService";
import AdventureCard from "$lib/components/AdventureCard.svelte";
@@ -43,9 +44,9 @@
let newArray = await addAdventure(detailAdventure, adventuresPlans);
if (newArray.length > 0) {
adventuresPlans = newArray;
- // showToast("Adventure added successfully!");
+ showToast("Adventure added successfully!");
} else {
- // showToast("Failed to add adventure");
+ showToast("Failed to add adventure");
}
};
@@ -62,6 +63,22 @@
}, 3000);
}
+ async function remove(event: { detail: number }) {
+ let initialLength: number = adventuresPlans.length;
+ let theAdventure = adventuresPlans.find(
+ (adventure) => adventure.id === event.detail
+ );
+ if (theAdventure) {
+ let newArray = await removeAdventure(theAdventure, adventuresPlans);
+ if (newArray.length === initialLength - 1) {
+ adventuresPlans = newArray;
+ showToast("Adventure removed successfully!");
+ } else {
+ showToast("Failed to remove adventure");
+ }
+ }
+ }
+
async function savePlan(event: { detail: Adventure }) {
let newArray = await saveAdventure(event.detail, adventuresPlans);
if (newArray.length > 0) {
@@ -108,7 +125,7 @@
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
>
{#each adventuresPlans as adventure (adventure.id)}
-
+
{/each}