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