add: create, update and login dates in database
This commit is contained in:
@@ -78,6 +78,9 @@ export const user = pgTable("user", {
|
|||||||
username: text(),
|
username: text(),
|
||||||
dashboardTheme: text("dashboard_theme").default('none'),
|
dashboardTheme: text("dashboard_theme").default('none'),
|
||||||
dashboardColor: text("dashboard_color"),
|
dashboardColor: text("dashboard_color"),
|
||||||
|
lastLogin: timestamp("last_login", { mode: 'string' }),
|
||||||
|
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
||||||
|
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
|
||||||
}, (table) => [
|
}, (table) => [
|
||||||
unique("user_email_unique").on(table.email),
|
unique("user_email_unique").on(table.email),
|
||||||
unique("user_username_unique").on(table.username),
|
unique("user_username_unique").on(table.username),
|
||||||
|
|||||||
@@ -103,6 +103,14 @@ const authConfig: SvelteKitAuthConfig = {
|
|||||||
signIn: '/signin'
|
signIn: '/signin'
|
||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
|
async signIn({ user }) {
|
||||||
|
if (user?.id) {
|
||||||
|
await db.update(users)
|
||||||
|
.set({ lastLogin: new Date() })
|
||||||
|
.where(eq(users.id, user.id));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
async jwt({ token, user }) {
|
async jwt({ token, user }) {
|
||||||
if (user) {
|
if (user) {
|
||||||
token.id = user.id;
|
token.id = user.id;
|
||||||
|
|||||||
@@ -8,12 +8,18 @@
|
|||||||
import ColorPicker from '$lib/components/ui/ColorPicker.svelte';
|
import ColorPicker from '$lib/components/ui/ColorPicker.svelte';
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import { languageStore } from '$lib/stores/language.svelte';
|
import { languageStore } from '$lib/stores/language.svelte';
|
||||||
|
import ThemeCard from '$lib/components/themes/ThemeCard.svelte';
|
||||||
|
import { getCardStyle } from '$lib/utils/colors';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
|
wishlistColor?: string | null;
|
||||||
|
wishlistTheme?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { onSuccess }: Props = $props();
|
let { onSuccess, wishlistColor = null, wishlistTheme = null }: Props = $props();
|
||||||
|
|
||||||
|
const cardStyle = $derived(getCardStyle(wishlistColor, null));
|
||||||
|
|
||||||
const t = $derived(languageStore.t);
|
const t = $derived(languageStore.t);
|
||||||
|
|
||||||
@@ -53,11 +59,12 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card>
|
<Card style={cardStyle} class="relative overflow-hidden">
|
||||||
<CardHeader>
|
<ThemeCard themeName={wishlistTheme} color={wishlistColor} showPattern={false} />
|
||||||
|
<CardHeader class="relative z-10">
|
||||||
<CardTitle>{t.form.addNewWish}</CardTitle>
|
<CardTitle>{t.form.addNewWish}</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent class="relative z-10">
|
||||||
<form
|
<form
|
||||||
method="POST"
|
method="POST"
|
||||||
action="?/addItem"
|
action="?/addItem"
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import type { Item } from '$lib/server/schema';
|
import type { Item } from '$lib/server/schema';
|
||||||
import { languageStore } from '$lib/stores/language.svelte';
|
import { languageStore } from '$lib/stores/language.svelte';
|
||||||
|
import ThemeCard from '$lib/components/themes/ThemeCard.svelte';
|
||||||
|
import { getCardStyle } from '$lib/utils/colors';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
item: Item;
|
item: Item;
|
||||||
@@ -18,9 +20,13 @@
|
|||||||
currentPosition?: number;
|
currentPosition?: number;
|
||||||
totalItems?: number;
|
totalItems?: number;
|
||||||
onPositionChange?: (newPosition: number) => void;
|
onPositionChange?: (newPosition: number) => void;
|
||||||
|
wishlistColor?: string | null;
|
||||||
|
wishlistTheme?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { item, onSuccess, onCancel, onColorChange, currentPosition = 1, totalItems = 1, onPositionChange }: Props = $props();
|
let { item, onSuccess, onCancel, onColorChange, currentPosition = 1, totalItems = 1, onPositionChange, wishlistColor = null, wishlistTheme = null }: Props = $props();
|
||||||
|
|
||||||
|
const cardStyle = $derived(getCardStyle(wishlistColor, null));
|
||||||
|
|
||||||
const t = $derived(languageStore.t);
|
const t = $derived(languageStore.t);
|
||||||
|
|
||||||
@@ -60,11 +66,12 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card>
|
<Card style={cardStyle} class="relative overflow-hidden">
|
||||||
<CardHeader>
|
<ThemeCard themeName={wishlistTheme} color={wishlistColor} showPattern={false} />
|
||||||
|
<CardHeader class="relative z-10">
|
||||||
<CardTitle>{t.wishlist.editWish}</CardTitle>
|
<CardTitle>{t.wishlist.editWish}</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent class="relative z-10">
|
||||||
<form
|
<form
|
||||||
method="POST"
|
method="POST"
|
||||||
action="?/updateItem"
|
action="?/updateItem"
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ export const users = pgTable('user', {
|
|||||||
password: text('password'),
|
password: text('password'),
|
||||||
username: text('username').unique(),
|
username: text('username').unique(),
|
||||||
dashboardTheme: text('dashboard_theme').default('none'),
|
dashboardTheme: text('dashboard_theme').default('none'),
|
||||||
dashboardColor: text('dashboard_color')
|
dashboardColor: text('dashboard_color'),
|
||||||
|
lastLogin: timestamp('last_login', { mode: 'date' }),
|
||||||
|
createdAt: timestamp('created_at').defaultNow().notNull(),
|
||||||
|
updatedAt: timestamp('updated_at').defaultNow().notNull()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const accounts = pgTable(
|
export const accounts = pgTable(
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export const actions: Actions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await db.update(wishlists)
|
await db.update(wishlists)
|
||||||
.set({ isFavorite: !isFavorite })
|
.set({ isFavorite: !isFavorite, updatedAt: new Date() })
|
||||||
.where(eq(wishlists.id, wishlistId));
|
.where(eq(wishlists.id, wishlistId));
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -171,7 +171,7 @@ export const actions: Actions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await db.update(users)
|
await db.update(users)
|
||||||
.set({ dashboardTheme: theme })
|
.set({ dashboardTheme: theme, updatedAt: new Date() })
|
||||||
.where(eq(users.id, session.user.id));
|
.where(eq(users.id, session.user.id));
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -187,7 +187,7 @@ export const actions: Actions = {
|
|||||||
const color = formData.get('color') as string | null;
|
const color = formData.get('color') as string | null;
|
||||||
|
|
||||||
await db.update(users)
|
await db.update(users)
|
||||||
.set({ dashboardColor: color })
|
.set({ dashboardColor: color, updatedAt: new Date() })
|
||||||
.where(eq(users.id, session.user.id));
|
.where(eq(users.id, session.user.id));
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
|
|
||||||
{#if showAddForm}
|
{#if showAddForm}
|
||||||
<div bind:this={addFormElement}>
|
<div bind:this={addFormElement}>
|
||||||
<AddItemForm onSuccess={handleItemAdded} />
|
<AddItemForm onSuccess={handleItemAdded} wishlistColor={currentColor} wishlistTheme={currentTheme} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -169,6 +169,8 @@
|
|||||||
currentPosition={items.findIndex(item => item.id === editingItem.id) + 1}
|
currentPosition={items.findIndex(item => item.id === editingItem.id) + 1}
|
||||||
totalItems={items.length}
|
totalItems={items.length}
|
||||||
onPositionChange={handlePositionChange}
|
onPositionChange={handlePositionChange}
|
||||||
|
wishlistColor={currentColor}
|
||||||
|
wishlistTheme={currentTheme}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user