mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Fixing collection by CUID2 and fixing the controllers for these.
This commit is contained in:
parent
ab4c019406
commit
ead20829e4
12 changed files with 165 additions and 135 deletions
|
|
@ -67,8 +67,8 @@
|
||||||
"sveltekit-superforms": "^2.17.0",
|
"sveltekit-superforms": "^2.17.0",
|
||||||
"tailwindcss": "^3.4.10",
|
"tailwindcss": "^3.4.10",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tslib": "^2.6.3",
|
"tslib": "^2.7.0",
|
||||||
"tsx": "^4.17.0",
|
"tsx": "^4.18.0",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^5.5.4",
|
||||||
"vite": "^5.4.2",
|
"vite": "^5.4.2",
|
||||||
"vitest": "^1.6.0",
|
"vitest": "^1.6.0",
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/fira-mono": "^5.0.14",
|
"@fontsource/fira-mono": "^5.0.14",
|
||||||
"@hono/swagger-ui": "^0.4.0",
|
"@hono/swagger-ui": "^0.4.1",
|
||||||
"@hono/zod-openapi": "^0.15.3",
|
"@hono/zod-openapi": "^0.15.3",
|
||||||
"@hono/zod-validator": "^0.2.2",
|
"@hono/zod-validator": "^0.2.2",
|
||||||
"@iconify-icons/line-md": "^1.2.30",
|
"@iconify-icons/line-md": "^1.2.30",
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ importers:
|
||||||
specifier: ^5.0.14
|
specifier: ^5.0.14
|
||||||
version: 5.0.14
|
version: 5.0.14
|
||||||
'@hono/swagger-ui':
|
'@hono/swagger-ui':
|
||||||
specifier: ^0.4.0
|
specifier: ^0.4.1
|
||||||
version: 0.4.0(hono@4.5.8)
|
version: 0.4.1(hono@4.5.8)
|
||||||
'@hono/zod-openapi':
|
'@hono/zod-openapi':
|
||||||
specifier: ^0.15.3
|
specifier: ^0.15.3
|
||||||
version: 0.15.3(hono@4.5.8)(zod@3.23.8)
|
version: 0.15.3(hono@4.5.8)(zod@3.23.8)
|
||||||
|
|
@ -248,7 +248,7 @@ importers:
|
||||||
version: 16.1.0(postcss@8.4.41)
|
version: 16.1.0(postcss@8.4.41)
|
||||||
postcss-load-config:
|
postcss-load-config:
|
||||||
specifier: ^5.1.0
|
specifier: ^5.1.0
|
||||||
version: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0)
|
version: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0)
|
||||||
postcss-preset-env:
|
postcss-preset-env:
|
||||||
specifier: ^9.6.0
|
specifier: ^9.6.0
|
||||||
version: 9.6.0(postcss@8.4.41)
|
version: 9.6.0(postcss@8.4.41)
|
||||||
|
|
@ -272,7 +272,7 @@ importers:
|
||||||
version: 5.0.0-next.175
|
version: 5.0.0-next.175
|
||||||
svelte-check:
|
svelte-check:
|
||||||
specifier: ^3.8.6
|
specifier: ^3.8.6
|
||||||
version: 3.8.6(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)
|
version: 3.8.6(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)
|
||||||
svelte-headless-table:
|
svelte-headless-table:
|
||||||
specifier: ^0.18.2
|
specifier: ^0.18.2
|
||||||
version: 0.18.2(svelte@5.0.0-next.175)
|
version: 0.18.2(svelte@5.0.0-next.175)
|
||||||
|
|
@ -281,7 +281,7 @@ importers:
|
||||||
version: 3.1.3(svelte@5.0.0-next.175)(typescript@5.5.4)
|
version: 3.1.3(svelte@5.0.0-next.175)(typescript@5.5.4)
|
||||||
svelte-preprocess:
|
svelte-preprocess:
|
||||||
specifier: ^6.0.2
|
specifier: ^6.0.2
|
||||||
version: 6.0.2(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4)
|
version: 6.0.2(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4)
|
||||||
svelte-sequential-preprocessor:
|
svelte-sequential-preprocessor:
|
||||||
specifier: ^2.0.1
|
specifier: ^2.0.1
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
|
|
@ -301,11 +301,11 @@ importers:
|
||||||
specifier: ^10.9.2
|
specifier: ^10.9.2
|
||||||
version: 10.9.2(@types/node@20.16.1)(typescript@5.5.4)
|
version: 10.9.2(@types/node@20.16.1)(typescript@5.5.4)
|
||||||
tslib:
|
tslib:
|
||||||
specifier: ^2.6.3
|
specifier: ^2.7.0
|
||||||
version: 2.6.3
|
version: 2.7.0
|
||||||
tsx:
|
tsx:
|
||||||
specifier: ^4.17.0
|
specifier: ^4.18.0
|
||||||
version: 4.17.0
|
version: 4.18.0
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ^5.5.4
|
specifier: ^5.5.4
|
||||||
version: 5.5.4
|
version: 5.5.4
|
||||||
|
|
@ -1270,8 +1270,8 @@ packages:
|
||||||
'@hapi/topo@5.1.0':
|
'@hapi/topo@5.1.0':
|
||||||
resolution: {integrity: sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==}
|
resolution: {integrity: sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==}
|
||||||
|
|
||||||
'@hono/swagger-ui@0.4.0':
|
'@hono/swagger-ui@0.4.1':
|
||||||
resolution: {integrity: sha512-8lF+dexzgV2HRM1R/gf49E5djroq4jVMYMSwLkSF9pT0I6sYhuqirFDCRFrBtbbLCBsKzw6f2MF5rS+WY3d7Nw==}
|
resolution: {integrity: sha512-kPaJatHffeYQ3yVkHo878hCqwfapqx54FczJVJ+eRWt8J4biyVVMIdCAJb6MyA8bcnHUoTmUpPc7OJAV1VTg2g==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
hono: '*'
|
hono: '*'
|
||||||
|
|
||||||
|
|
@ -4734,8 +4734,11 @@ packages:
|
||||||
tslib@2.6.3:
|
tslib@2.6.3:
|
||||||
resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==}
|
resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==}
|
||||||
|
|
||||||
tsx@4.17.0:
|
tslib@2.7.0:
|
||||||
resolution: {integrity: sha512-eN4mnDA5UMKDt4YZixo9tBioibaMBpoxBkD+rIPAjVmYERSG0/dWEY1CEFuV89CgASlKL499q8AhmkMnnjtOJg==}
|
resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==}
|
||||||
|
|
||||||
|
tsx@4.18.0:
|
||||||
|
resolution: {integrity: sha512-a1jaKBSVQkd6yEc1/NI7G6yHFfefIcuf3QJST7ZEyn4oQnxLYrZR5uZAM8UrwUa3Ge8suiZHcNS1gNrEvmobqg==}
|
||||||
engines: {node: '>=18.0.0'}
|
engines: {node: '>=18.0.0'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
|
@ -5320,17 +5323,17 @@ snapshots:
|
||||||
|
|
||||||
'@emnapi/core@0.45.0':
|
'@emnapi/core@0.45.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@emnapi/runtime@0.45.0':
|
'@emnapi/runtime@0.45.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@emnapi/runtime@1.2.0':
|
'@emnapi/runtime@1.2.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@esbuild-kit/core-utils@3.3.2':
|
'@esbuild-kit/core-utils@3.3.2':
|
||||||
|
|
@ -5692,7 +5695,7 @@ snapshots:
|
||||||
'@hapi/hoek': 9.3.0
|
'@hapi/hoek': 9.3.0
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@hono/swagger-ui@0.4.0(hono@4.5.8)':
|
'@hono/swagger-ui@0.4.1(hono@4.5.8)':
|
||||||
dependencies:
|
dependencies:
|
||||||
hono: 4.5.8
|
hono: 4.5.8
|
||||||
|
|
||||||
|
|
@ -6370,7 +6373,7 @@ snapshots:
|
||||||
|
|
||||||
'@swc/helpers@0.5.11':
|
'@swc/helpers@0.5.11':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
|
|
||||||
'@tsconfig/node10@1.0.11': {}
|
'@tsconfig/node10@1.0.11': {}
|
||||||
|
|
||||||
|
|
@ -6382,7 +6385,7 @@ snapshots:
|
||||||
|
|
||||||
'@tybys/wasm-util@0.8.3':
|
'@tybys/wasm-util@0.8.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@types/cookie@0.6.0': {}
|
'@types/cookie@0.6.0': {}
|
||||||
|
|
@ -6754,7 +6757,7 @@ snapshots:
|
||||||
msgpackr: 1.11.0
|
msgpackr: 1.11.0
|
||||||
node-abort-controller: 3.1.1
|
node-abort-controller: 3.1.1
|
||||||
semver: 7.6.3
|
semver: 7.6.3
|
||||||
tslib: 2.6.3
|
tslib: 2.7.0
|
||||||
uuid: 9.0.1
|
uuid: 9.0.1
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
@ -8298,14 +8301,14 @@ snapshots:
|
||||||
postcss: 8.4.41
|
postcss: 8.4.41
|
||||||
ts-node: 10.9.2(@types/node@20.16.1)(typescript@5.5.4)
|
ts-node: 10.9.2(@types/node@20.16.1)(typescript@5.5.4)
|
||||||
|
|
||||||
postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0):
|
postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
lilconfig: 3.1.1
|
lilconfig: 3.1.1
|
||||||
yaml: 2.4.2
|
yaml: 2.4.2
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
jiti: 1.21.6
|
jiti: 1.21.6
|
||||||
postcss: 8.4.41
|
postcss: 8.4.41
|
||||||
tsx: 4.17.0
|
tsx: 4.18.0
|
||||||
|
|
||||||
postcss-logical@7.0.1(postcss@8.4.41):
|
postcss-logical@7.0.1(postcss@8.4.41):
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
@ -8875,14 +8878,14 @@ snapshots:
|
||||||
|
|
||||||
supports-preserve-symlinks-flag@1.0.0: {}
|
supports-preserve-symlinks-flag@1.0.0: {}
|
||||||
|
|
||||||
svelte-check@3.8.6(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175):
|
svelte-check@3.8.6(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/trace-mapping': 0.3.25
|
'@jridgewell/trace-mapping': 0.3.25
|
||||||
chokidar: 3.6.0
|
chokidar: 3.6.0
|
||||||
picocolors: 1.0.0
|
picocolors: 1.0.0
|
||||||
sade: 1.8.1
|
sade: 1.8.1
|
||||||
svelte: 5.0.0-next.175
|
svelte: 5.0.0-next.175
|
||||||
svelte-preprocess: 5.1.4(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4)
|
svelte-preprocess: 5.1.4(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4)
|
||||||
typescript: 5.5.4
|
typescript: 5.5.4
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@babel/core'
|
- '@babel/core'
|
||||||
|
|
@ -8938,7 +8941,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
svelte: 5.0.0-next.175
|
svelte: 5.0.0-next.175
|
||||||
|
|
||||||
svelte-preprocess@5.1.4(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4):
|
svelte-preprocess@5.1.4(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/pug': 2.0.10
|
'@types/pug': 2.0.10
|
||||||
detect-indent: 6.1.0
|
detect-indent: 6.1.0
|
||||||
|
|
@ -8948,16 +8951,16 @@ snapshots:
|
||||||
svelte: 5.0.0-next.175
|
svelte: 5.0.0-next.175
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
postcss: 8.4.41
|
postcss: 8.4.41
|
||||||
postcss-load-config: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0)
|
postcss-load-config: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0)
|
||||||
sass: 1.77.8
|
sass: 1.77.8
|
||||||
typescript: 5.5.4
|
typescript: 5.5.4
|
||||||
|
|
||||||
svelte-preprocess@6.0.2(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4):
|
svelte-preprocess@6.0.2(postcss-load-config@5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0))(postcss@8.4.41)(sass@1.77.8)(svelte@5.0.0-next.175)(typescript@5.5.4):
|
||||||
dependencies:
|
dependencies:
|
||||||
svelte: 5.0.0-next.175
|
svelte: 5.0.0-next.175
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
postcss: 8.4.41
|
postcss: 8.4.41
|
||||||
postcss-load-config: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.17.0)
|
postcss-load-config: 5.1.0(jiti@1.21.6)(postcss@8.4.41)(tsx@4.18.0)
|
||||||
sass: 1.77.8
|
sass: 1.77.8
|
||||||
typescript: 5.5.4
|
typescript: 5.5.4
|
||||||
|
|
||||||
|
|
@ -9169,7 +9172,9 @@ snapshots:
|
||||||
|
|
||||||
tslib@2.6.3: {}
|
tslib@2.6.3: {}
|
||||||
|
|
||||||
tsx@4.17.0:
|
tslib@2.7.0: {}
|
||||||
|
|
||||||
|
tsx@4.18.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
esbuild: 0.23.0
|
esbuild: 0.23.0
|
||||||
get-tsconfig: 4.7.5
|
get-tsconfig: 4.7.5
|
||||||
|
|
|
||||||
17
src/env.ts
17
src/env.ts
|
|
@ -10,21 +10,22 @@ const stringBoolean = z.coerce
|
||||||
.default('false');
|
.default('false');
|
||||||
|
|
||||||
const EnvSchema = z.object({
|
const EnvSchema = z.object({
|
||||||
NODE_ENV: z.string().default('development'),
|
ADMIN_USERNAME: z.string(),
|
||||||
|
ADMIN_PASSWORD: z.string(),
|
||||||
DATABASE_USER: z.string(),
|
DATABASE_USER: z.string(),
|
||||||
DATABASE_PASSWORD: z.string(),
|
DATABASE_PASSWORD: z.string(),
|
||||||
DATABASE_HOST: z.string(),
|
DATABASE_HOST: z.string(),
|
||||||
DATABASE_PORT: z.coerce.number(),
|
DATABASE_PORT: z.coerce.number(),
|
||||||
DATABASE_DB: z.string(),
|
DATABASE_DB: z.string(),
|
||||||
|
DB_MIGRATING: stringBoolean,
|
||||||
|
DB_SEEDING: stringBoolean,
|
||||||
|
NODE_ENV: z.string().default('development'),
|
||||||
PUBLIC_SITE_NAME: z.string(),
|
PUBLIC_SITE_NAME: z.string(),
|
||||||
PUBLIC_SITE_URL: z.string(),
|
PUBLIC_SITE_URL: z.string(),
|
||||||
PUBLIC_UMAMI_DO_NOT_TRACK: z.string(),
|
PUBLIC_UMAMI_DO_NOT_TRACK: z.string(),
|
||||||
PUBLIC_UMAMI_ID: z.string(),
|
PUBLIC_UMAMI_ID: z.string(),
|
||||||
PUBLIC_UMAMI_URL: z.string(),
|
PUBLIC_UMAMI_URL: z.string(),
|
||||||
DB_MIGRATING: stringBoolean,
|
REDIS_URL: z.string(),
|
||||||
DB_SEEDING: stringBoolean,
|
|
||||||
ADMIN_USERNAME: z.string(),
|
|
||||||
ADMIN_PASSWORD: z.string(),
|
|
||||||
TWO_FACTOR_TIMEOUT: z.coerce.number().default(300000),
|
TWO_FACTOR_TIMEOUT: z.coerce.number().default(300000),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -37,9 +38,9 @@ try {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof ZodError) {
|
if (error instanceof ZodError) {
|
||||||
let message = 'Missing required values in .env:\n';
|
let message = 'Missing required values in .env:\n';
|
||||||
error.issues.forEach((issue) => {
|
for (const issue of error.issues) {
|
||||||
message += issue.path[0] + '\n';
|
message += `${issue.path[0]}\n`;
|
||||||
});
|
}
|
||||||
const e = new Error(message);
|
const e = new Error(message);
|
||||||
e.stack = '';
|
e.stack = '';
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ import env from '../../../../env';
|
||||||
|
|
||||||
const isPreview = process.env.VERCEL_ENV === 'preview' || process.env.VERCEL_ENV === 'development';
|
const isPreview = process.env.VERCEL_ENV === 'preview' || process.env.VERCEL_ENV === 'development';
|
||||||
|
|
||||||
let domain;
|
let domain: string;
|
||||||
if (process.env.NODE_ENV === 'production' || process.env.VERCEL_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production' || process.env.VERCEL_ENV === 'production') {
|
||||||
domain = 'boredgame.vercel.app';
|
domain = 'boredgame.vercel.app';
|
||||||
} else if (isPreview) {
|
} else if (isPreview && process.env.VERCEL_BRANCH_URL !== undefined) {
|
||||||
domain = process.env.VERCEL_BRANCH_URL;
|
domain = process.env.VERCEL_BRANCH_URL;
|
||||||
} else {
|
} else {
|
||||||
domain = 'localhost';
|
domain = 'localhost';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = { ...env, isProduction: process.env.NODE_ENV === 'production' || process.env.VERCEL_ENV === 'production', domain };
|
export const config = { ...env, isProduction: process.env.NODE_ENV === 'production'
|
||||||
|
|| process.env.VERCEL_ENV === 'production', domain };
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ export class CollectionController implements Controller {
|
||||||
})
|
})
|
||||||
.get('/:cuid', requireAuth, async (c) => {
|
.get('/:cuid', requireAuth, async (c) => {
|
||||||
const cuid = c.req.param('cuid');
|
const cuid = c.req.param('cuid');
|
||||||
const user = await this.collectionsService.findOneByCuid(cuid);
|
const collection = await this.collectionsService.findOneByCuid(cuid);
|
||||||
return c.json({ user });
|
return c.json({ collection });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ export class WishlistController implements Controller {
|
||||||
})
|
})
|
||||||
.get('/:cuid', requireAuth, async (c) => {
|
.get('/:cuid', requireAuth, async (c) => {
|
||||||
const cuid = c.req.param('cuid')
|
const cuid = c.req.param('cuid')
|
||||||
console.log(cuid)
|
|
||||||
const wishlist = await this.wishlistsService.findOneByCuid(cuid)
|
const wishlist = await this.wishlistsService.findOneByCuid(cuid)
|
||||||
return c.json({ wishlist });
|
return c.json({ wishlist });
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import { superValidate } from 'sveltekit-superforms/server';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
import { redirect } from 'sveltekit-flash-message/server';
|
import { redirect } from 'sveltekit-flash-message/server';
|
||||||
import { modifyListGameSchema } from '$lib/validations/zod-schemas';
|
import { modifyListGameSchema } from '$lib/validations/zod-schemas';
|
||||||
import db from '../../../../db';
|
import { db } from '$lib/server/api/infrastructure/database';
|
||||||
import { collection_items, collections, games } from '$db/schema';
|
import { collection_items, collections, games } from '$lib/server/api/infrastructure/database/tables';
|
||||||
import { notSignedInMessage } from '$lib/flashMessages';
|
import { notSignedInMessage } from '$lib/flashMessages';
|
||||||
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,100 +3,126 @@ import { and, eq } from 'drizzle-orm';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
import { superValidate } from 'sveltekit-superforms/server';
|
import { superValidate } from 'sveltekit-superforms/server';
|
||||||
import { redirect } from 'sveltekit-flash-message/server';
|
import { redirect } from 'sveltekit-flash-message/server';
|
||||||
import { type ListGame, modifyListGameSchema } from '$lib/validations/zod-schemas';
|
import { modifyListGameSchema } from '$lib/validations/zod-schemas';
|
||||||
import db from '../../../../../db';
|
import { db } from '$lib/server/api/infrastructure/database';
|
||||||
import { notSignedInMessage } from '$lib/flashMessages.js';
|
import { notSignedInMessage } from '$lib/flashMessages.js';
|
||||||
import { collections, games, collection_items } from '$db/schema';
|
import { collections, games, collection_items } from '$lib/server/api/infrastructure/database/tables';
|
||||||
import { search_schema } from '$lib/zodValidation';
|
|
||||||
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
||||||
|
|
||||||
export async function load(event) {
|
export async function load(event) {
|
||||||
const { locals, params, url } = event;
|
const { params, locals } = event;
|
||||||
const { user, session } = locals;
|
const { cuid } = params;
|
||||||
const { id } = params;
|
|
||||||
|
|
||||||
if (userNotAuthenticated(user, session)) {
|
const authedUser = await locals.getAuthedUser();
|
||||||
redirect(302, '/login', notSignedInMessage, event);
|
if (!authedUser) {
|
||||||
}
|
throw redirect(302, '/login', notSignedInMessage, event);
|
||||||
const searchParams = Object.fromEntries(url?.searchParams);
|
|
||||||
console.log('searchParams', searchParams);
|
|
||||||
const q = searchParams?.q;
|
|
||||||
const limit = parseInt(searchParams?.limit) || 10;
|
|
||||||
const skip = parseInt(searchParams?.skip) || 0;
|
|
||||||
|
|
||||||
const searchData = {
|
|
||||||
q,
|
|
||||||
limit,
|
|
||||||
skip,
|
|
||||||
};
|
|
||||||
|
|
||||||
const searchForm = await superValidate(searchData, zod(search_schema));
|
|
||||||
const listManageForm = await superValidate(zod(modifyListGameSchema));
|
|
||||||
|
|
||||||
const collection = await db.query.collections.findFirst({
|
|
||||||
columns: {
|
|
||||||
id: true,
|
|
||||||
cuid: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
where: and(eq(collections.user_id, user!.id!), eq(collections.cuid, id)),
|
|
||||||
});
|
|
||||||
console.log('collection', collection);
|
|
||||||
|
|
||||||
if (!collection) {
|
|
||||||
console.log('Collection was not found');
|
|
||||||
error(404, 'Collection was not found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const collectionItems = await db.query.collection_items.findMany({
|
try {
|
||||||
columns: {
|
const { data, errors } = await locals.api.collections[':cuid'].$get({
|
||||||
collection_id: true,
|
param: { cuid }
|
||||||
times_played: true,
|
}).then(locals.parseApiResponse);
|
||||||
},
|
|
||||||
where: eq(collection_items.collection_id, collection.id),
|
|
||||||
with: {
|
|
||||||
game: {
|
|
||||||
columns: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
thumb_url: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
offset: skip,
|
|
||||||
limit,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('collection_items', collectionItems);
|
if (errors) {
|
||||||
|
return error(500, 'Failed to fetch collection');
|
||||||
const items: ListGame[] = [];
|
|
||||||
for (const item of collectionItems) {
|
|
||||||
console.log('item', item);
|
|
||||||
const game = item.game;
|
|
||||||
if (game) {
|
|
||||||
items.push({
|
|
||||||
game_id: '',
|
|
||||||
in_wishlist: false,
|
|
||||||
wishlist_id: '',
|
|
||||||
id: game.id,
|
|
||||||
collection_id: item.collection_id,
|
|
||||||
game_name: game.name ?? "Game doesn't have a name",
|
|
||||||
thumb_url: game.thumb_url,
|
|
||||||
times_played: item.times_played ?? 0,
|
|
||||||
in_collection: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { collection } = data;
|
||||||
|
|
||||||
|
if (!collection) {
|
||||||
|
redirect(302, '/404');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('collection', collection);
|
||||||
|
|
||||||
|
return {
|
||||||
|
collection,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
redirect(302, '/404');
|
||||||
searchForm,
|
|
||||||
listManageForm,
|
// const searchParams = Object.fromEntries(url?.searchParams);
|
||||||
collection: {
|
// console.log('searchParams', searchParams);
|
||||||
name: collection.name,
|
// const q = searchParams?.q;
|
||||||
cuid: collection.cuid ?? '',
|
// const limit = parseInt(searchParams?.limit) || 10;
|
||||||
},
|
// const skip = parseInt(searchParams?.skip) || 0;
|
||||||
items,
|
//
|
||||||
};
|
// const searchData = {
|
||||||
|
// q,
|
||||||
|
// limit,
|
||||||
|
// skip,
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// const searchForm = await superValidate(searchData, zod(search_schema));
|
||||||
|
// const listManageForm = await superValidate(zod(modifyListGameSchema));
|
||||||
|
//
|
||||||
|
// const collection = await db.query.collections.findFirst({
|
||||||
|
// columns: {
|
||||||
|
// id: true,
|
||||||
|
// cuid: true,
|
||||||
|
// name: true,
|
||||||
|
// },
|
||||||
|
// where: and(eq(collections.user_id, user!.id!), eq(collections.cuid, id)),
|
||||||
|
// });
|
||||||
|
// console.log('collection', collection);
|
||||||
|
|
||||||
|
// if (!collection) {
|
||||||
|
// console.log('Collection was not found');
|
||||||
|
// error(404, 'Collection was not found');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const collectionItems = await db.query.collection_items.findMany({
|
||||||
|
// columns: {
|
||||||
|
// collection_id: true,
|
||||||
|
// times_played: true,
|
||||||
|
// },
|
||||||
|
// where: eq(collection_items.collection_id, collection.id),
|
||||||
|
// with: {
|
||||||
|
// game: {
|
||||||
|
// columns: {
|
||||||
|
// id: true,
|
||||||
|
// name: true,
|
||||||
|
// thumb_url: true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// offset: skip,
|
||||||
|
// limit,
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// console.log('collection_items', collectionItems);
|
||||||
|
//
|
||||||
|
// const items: ListGame[] = [];
|
||||||
|
// for (const item of collectionItems) {
|
||||||
|
// console.log('item', item);
|
||||||
|
// const game = item.game;
|
||||||
|
// if (game) {
|
||||||
|
// items.push({
|
||||||
|
// game_id: '',
|
||||||
|
// in_wishlist: false,
|
||||||
|
// wishlist_id: '',
|
||||||
|
// id: game.id,
|
||||||
|
// collection_id: item.collection_id,
|
||||||
|
// game_name: game.name ?? "Game doesn't have a name",
|
||||||
|
// thumb_url: game.thumb_url,
|
||||||
|
// times_played: item.times_played ?? 0,
|
||||||
|
// in_collection: true,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return {
|
||||||
|
// searchForm,
|
||||||
|
// listManageForm,
|
||||||
|
// collection: {
|
||||||
|
// name: collection.name,
|
||||||
|
// cuid: collection.cuid ?? '',
|
||||||
|
// },
|
||||||
|
// items,
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
|
|
@ -12,8 +12,8 @@ import { redirect, setFlash } from 'sveltekit-flash-message/server';
|
||||||
import type { PageServerLoad } from '../../$types';
|
import type { PageServerLoad } from '../../$types';
|
||||||
import { addTwoFactorSchema, removeTwoFactorSchema } from '$lib/validations/account';
|
import { addTwoFactorSchema, removeTwoFactorSchema } from '$lib/validations/account';
|
||||||
import { notSignedInMessage } from '$lib/flashMessages';
|
import { notSignedInMessage } from '$lib/flashMessages';
|
||||||
import db from '../../../../../../db';
|
import db from '$lib/server/api/infrastructure/database';
|
||||||
import { recoveryCodes, twoFactor, usersTable } from '$db/schema';
|
import { recoveryCodes, twoFactor, usersTable } from '$lib/server/api/infrastructure/database/tables';
|
||||||
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
import { userNotAuthenticated } from '$lib/server/auth-utils';
|
||||||
import env from '../../../../../../env';
|
import env from '../../../../../../env';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ export async function load(event) {
|
||||||
if (errors) {
|
if (errors) {
|
||||||
return error(500, 'Failed to fetch wishlist');
|
return error(500, 'Failed to fetch wishlist');
|
||||||
}
|
}
|
||||||
console.log('data', data);
|
|
||||||
const { wishlist } = data;
|
const { wishlist } = data;
|
||||||
console.log('wishlist', wishlist);
|
|
||||||
|
|
||||||
if (!wishlist) {
|
if (!wishlist) {
|
||||||
redirect(302, '/404');
|
redirect(302, '/404');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue