fix: various lints
This commit is contained in:
parent
054e3635f3
commit
db8cd9e38f
12 changed files with 19 additions and 23 deletions
2
plice/src/app.d.ts
vendored
2
plice/src/app.d.ts
vendored
|
@ -22,7 +22,7 @@ declare global {
|
|||
type DatabaseUserAttributes = {
|
||||
username: string;
|
||||
};
|
||||
type DatabaseSessionAttributes = {};
|
||||
type DatabaseSessionAttributes = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ exports[`homepage fetch 1`] = `
|
|||
exports[`track page fetch 1`] = `
|
||||
{
|
||||
"createdAt": 2024-01-12T13:10:10.419Z,
|
||||
"id": 1,
|
||||
"producer": {
|
||||
"username": "fake",
|
||||
},
|
||||
|
|
|
@ -24,6 +24,7 @@ export interface Database {
|
|||
>;
|
||||
|
||||
fetchTrackPageData: (trackId: number) => Promise<{
|
||||
id: number;
|
||||
title: string;
|
||||
createdAt: Date;
|
||||
producer: {
|
||||
|
@ -42,5 +43,5 @@ export interface Database {
|
|||
} | null>;
|
||||
createTrack: (producerId: string, title: string) => Promise<Track>;
|
||||
createTrackVersion: (trackId: number) => Promise<TrackVersion>;
|
||||
createComment: (versionId: number, producerId: string, content: string) => Promise<{}>;
|
||||
createComment: (versionId: string, userId: string, content: string) => Promise<null>;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { Database } from '$lib/server/db';
|
||||
|
||||
export class MockHomepageFetch implements Database {
|
||||
// TODO Flesh this out
|
||||
export class MockGenericDatabase implements Database {
|
||||
fetchHomepageData = async (_producerId: string) => {
|
||||
const data = [
|
||||
{
|
||||
|
|
|
@ -54,6 +54,7 @@ export class DatabasePrisma implements Database {
|
|||
fetchTrackPageData = async (trackId: number) => {
|
||||
return await this.client.track.findUnique({
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
createdAt: true,
|
||||
producer: {
|
||||
|
@ -104,8 +105,8 @@ export class DatabasePrisma implements Database {
|
|||
});
|
||||
};
|
||||
|
||||
createComment = async (versionId: number, producerId: string, content: string) => {
|
||||
createComment = async (_versionId: string, _userId: string, _content: string) => {
|
||||
// TODO
|
||||
return {};
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ import type { LayoutServerLoad } from './$types';
|
|||
|
||||
export const load: LayoutServerLoad = async ({ locals: { authReq } }) => {
|
||||
return {
|
||||
isLoggedIn: authReq.validate()
|
||||
isLoggedIn: (await authReq.validate()) !== null
|
||||
};
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ export const actions: Actions = {
|
|||
|
||||
const session = await auth.createSession({
|
||||
userId: key.userId,
|
||||
attributes: {}
|
||||
attributes: null
|
||||
});
|
||||
|
||||
authReq.setSession(session);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
type="text"
|
||||
name="username"
|
||||
placeholder="username"
|
||||
value={form?.username ?? ''}
|
||||
aria-label="Username"
|
||||
autocomplete="username"
|
||||
required
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { expect, test } from 'vitest';
|
||||
import { load } from './+page.server';
|
||||
|
||||
import { MockHomepageFetch } from '$lib/server/db/mock';
|
||||
import { MockGenericDatabase } from '$lib/server/db/mock';
|
||||
|
||||
test('anonymous homepage load', async () => {
|
||||
const db = new MockHomepageFetch();
|
||||
const db = new MockGenericDatabase();
|
||||
const locals = {
|
||||
// TODO: Replace with authentication adapter
|
||||
authReq: {
|
||||
|
@ -20,7 +20,7 @@ test('anonymous homepage load', async () => {
|
|||
});
|
||||
|
||||
test('user homepage load', async () => {
|
||||
const db = new MockHomepageFetch();
|
||||
const db = new MockGenericDatabase();
|
||||
const locals = {
|
||||
// TODO: Replace with authentication adapter
|
||||
authReq: {
|
||||
|
|
|
@ -38,7 +38,7 @@ export const actions: Actions = {
|
|||
|
||||
const session = await auth.createSession({
|
||||
userId: user.userId,
|
||||
attributes: {}
|
||||
attributes: null
|
||||
});
|
||||
|
||||
authReq.setSession(session);
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
export let form;
|
||||
|
||||
let username = form?.username ?? '';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let passwordIsInvalid: boolean | null = null;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ export const load: PageServerLoad = async ({ params: { slug }, locals: { databas
|
|||
error(404, 'Track not found');
|
||||
}
|
||||
|
||||
let track = await database.fetchTrackPageData(trackId);
|
||||
const track = await database.fetchTrackPageData(trackId);
|
||||
if (!track) {
|
||||
error(440, 'Track not found');
|
||||
}
|
||||
|
@ -22,17 +22,11 @@ export const actions: Actions = {
|
|||
const session = await authReq.validate();
|
||||
if (!session) redirect(302, '/login');
|
||||
|
||||
const trackId = parseInt(slug);
|
||||
const versionId = slug;
|
||||
|
||||
const formData = await request.formData();
|
||||
const comment = formData.get('comment') as string;
|
||||
const version = formData.get('version') as string;
|
||||
|
||||
const versionId = parseInt(version);
|
||||
if (isNaN(versionId)) {
|
||||
error(404, 'Invalid version');
|
||||
}
|
||||
|
||||
database.createComment(trackId, versionId, comment);
|
||||
database.createComment(versionId, session.user.userId, comment);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue