From 7155754d60125a85b53e27367f0ce317cb5a3c51 Mon Sep 17 00:00:00 2001 From: hywax Date: Wed, 19 Jun 2024 16:23:03 +0300 Subject: [PATCH] fix: minor changes --- src/lib/date.ts | 6 +++--- src/lib/locale.ts | 2 +- src/routes/(website)/auth/sign-in/+server.ts | 16 ++++++---------- src/routes/(website)/character/+page.server.ts | 3 ++- .../(website)/character/[slug]/+page.server.ts | 1 + 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/lib/date.ts b/src/lib/date.ts index 1170c50e..5a8b036c 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -1,14 +1,14 @@ -export function getDatePlusMinutes(minutes: number) { +export function getDatePlusMinutes(minutes: number): Date { const milliseconds = minutes * 60 * 1000 return new Date(new Date().getTime() + milliseconds) } -export function getDateMinusMinutes(minutes: number) { +export function getDateMinusMinutes(minutes: number): Date { const milliseconds = minutes * 60 * 1000 return new Date(new Date().getTime() - milliseconds) } -export function getDatePlusSeconds(seconds: number) { +export function getDatePlusSeconds(seconds: number): Date { const milliseconds = seconds * 1000 return new Date(new Date().getTime() + milliseconds) } diff --git a/src/lib/locale.ts b/src/lib/locale.ts index 982e7280..980125d4 100644 --- a/src/lib/locale.ts +++ b/src/lib/locale.ts @@ -1,7 +1,7 @@ export function ruWordWithEndings( int: number, array: [string, string, string], -) { +): string { return array[ int % 100 > 4 && int % 100 < 20 ? 2 diff --git a/src/routes/(website)/auth/sign-in/+server.ts b/src/routes/(website)/auth/sign-in/+server.ts index 8e9b9bfe..0c4e7acb 100644 --- a/src/routes/(website)/auth/sign-in/+server.ts +++ b/src/routes/(website)/auth/sign-in/+server.ts @@ -3,23 +3,19 @@ import { error, json } from '@sveltejs/kit' import { ApiClient } from '@twurple/api' import { StaticAuthProvider, getTokenInfo } from '@twurple/auth' import jwt from 'jsonwebtoken' +import type { Profile } from '@prisma/client' import type { RequestHandler } from './$types' import type { IProfile } from '$lib/types' import { db } from '$lib/server/db/db.client' import { env as publicEnv } from '$env/dynamic/public' import { env as privateEnv } from '$env/dynamic/private' -async function findOrCreateProfile({ - twitchId, - userName, -}: { - twitchId: string - userName: string -}) { - const profileInDB = await db.profile.findFirst({ +async function findOrCreateProfile({ twitchId, userName }: Pick): Promise { + const profile = await db.profile.findFirst({ where: { twitchId }, }) - if (!profileInDB) { + + if (!profile) { return db.profile.create({ data: { id: createId(), @@ -29,7 +25,7 @@ async function findOrCreateProfile({ }) } - return profileInDB + return profile } async function prepareJwtToken(accessToken: string) { diff --git a/src/routes/(website)/character/+page.server.ts b/src/routes/(website)/character/+page.server.ts index e26579b1..bb6fd9b3 100644 --- a/src/routes/(website)/character/+page.server.ts +++ b/src/routes/(website)/character/+page.server.ts @@ -4,7 +4,8 @@ import { db } from '$lib/server/db/db.client' export const load: PageServerLoad = async () => { const characters = await db.character.findMany() - if (!characters) { + + if (!characters.length) { error(404, 'Not found') } diff --git a/src/routes/(website)/character/[slug]/+page.server.ts b/src/routes/(website)/character/[slug]/+page.server.ts index 2d3100bd..22bb73f5 100644 --- a/src/routes/(website)/character/[slug]/+page.server.ts +++ b/src/routes/(website)/character/[slug]/+page.server.ts @@ -8,6 +8,7 @@ export const load: PageServerLoad = async ({ params }) => { const character = await db.character.findFirst({ where: { id }, }) + if (!character) { error(404, 'Not found') }