updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { User, UserPayload } from '$lib/types/user';
|
||||
import { DefaultUserSettings, type User, type UserPayload } from '$lib/types/user';
|
||||
import bcrypt from 'bcrypt';
|
||||
import sql from '$lib/db/db.server';
|
||||
import { type Cookies, error } from '@sveltejs/kit';
|
||||
@@ -9,7 +9,10 @@ export function setJWTCookie(cookies: Cookies, user: User) {
|
||||
const payload = {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.name
|
||||
name: user.name,
|
||||
settings: user.settings || DefaultUserSettings,
|
||||
createdAt: user.createdAt,
|
||||
lastSignIn: user.lastSignIn
|
||||
};
|
||||
|
||||
if (process.env.JWT_SECRET === undefined) {
|
||||
@@ -65,8 +68,7 @@ export async function login(email: string, password: string): Promise<User> {
|
||||
if (await bcrypt.compare(password, user.passwordHash!)) {
|
||||
delete user.passwordHash;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
sql`
|
||||
await sql`
|
||||
UPDATE users
|
||||
SET last_sign_in = NOW()
|
||||
WHERE id = ${user.id};
|
||||
|
||||
@@ -16,19 +16,21 @@
|
||||
import { approveDenyItem, restoreClaimedItem } from '$lib/db/items.remote';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import NoImagePlaceholder from './no-image-placeholder.svelte';
|
||||
import type { User } from '$lib/types/user';
|
||||
|
||||
export let item: Item = <Item>{};
|
||||
export let admin = false;
|
||||
export let user: User | null = null;
|
||||
// export let admin = false;
|
||||
export let editCallback: (item: Item) => void;
|
||||
export let inquireCallback: (item: Item) => void;
|
||||
export let claimCallback: (item: Item) => void;
|
||||
|
||||
let timeSincePosted: number | string = (new Date().getTime() - item.foundDate.getTime()) / 1000 / 60 / 60 / 24; // days
|
||||
if (timeSincePosted < 1) {
|
||||
timeSincePosted = '<1';
|
||||
} else {
|
||||
timeSincePosted = Math.round(timeSincePosted);
|
||||
}
|
||||
// if (timeSincePosted < 1) {
|
||||
// timeSincePosted = '<1';
|
||||
// } else {
|
||||
// timeSincePosted = Math.round(timeSincePosted);
|
||||
// }
|
||||
|
||||
</script>
|
||||
|
||||
@@ -39,20 +41,14 @@
|
||||
alt="Lost item">
|
||||
{:else}
|
||||
<div class="min-h-48 w-full bg-accent flex flex-col justify-center">
|
||||
|
||||
<div class="justify-center flex ">
|
||||
|
||||
<NoImagePlaceholder className="" />
|
||||
</div>
|
||||
<p class="text-center mt-4">No image available</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex-col flex h-full px-2 pb-2">
|
||||
|
||||
<!-- <div class="font-bold inline-block">{item.title}</div>-->
|
||||
<!-- <div class="inline-block">-->
|
||||
<div>
|
||||
|
||||
{#if item.transferred}
|
||||
<Badge variant="secondary" class="inline-block">In Lost & Found</Badge>
|
||||
{:else}
|
||||
@@ -62,8 +58,9 @@
|
||||
<Tooltip.Root>
|
||||
<Tooltip.Trigger
|
||||
>
|
||||
<Badge variant="outline" class="inline-block">{timeSincePosted}
|
||||
day{(timeSincePosted === 1 || timeSincePosted === '<1') ? '' : 's'} ago
|
||||
<Badge variant="outline"
|
||||
class="inline-block {user?.settings !== null && user?.settings !== undefined && timeSincePosted >= user.settings.staleItemDays ? 'text-warning' : ''}">{timeSincePosted < 1 ? "<1" : Math.round(timeSincePosted)}
|
||||
day{(timeSincePosted <= 1) ? '' : 's'} ago
|
||||
</Badge>
|
||||
</Tooltip.Trigger
|
||||
>
|
||||
@@ -72,9 +69,7 @@
|
||||
</Tooltip.Content>
|
||||
</Tooltip.Root>
|
||||
</Tooltip.Provider>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="flex-1">{item.description}</div>
|
||||
{#if item.foundLocation}
|
||||
<div class="mt-2">
|
||||
@@ -82,8 +77,7 @@
|
||||
<div>{item.foundLocation}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if admin}
|
||||
{#if user !== null}
|
||||
<div class="mt-2 justify-between flex">
|
||||
{#if item.approvedDate === null}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user