mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-12 18:43:45 +00:00
Merge pull request #68 from jcreek/chore/migrate-from-mongodb
feat(*): Migrate from MongoDB to unified Supabase PostgreSQL architecture
This commit is contained in:
+2
-3
@@ -1,3 +1,2 @@
|
|||||||
MONGO_URL=""
|
PUBLIC_SUPABASE_URL="your-supabase-project-url"
|
||||||
PUBLIC_SUPABASE_URL=""
|
PUBLIC_SUPABASE_ANON_KEY="your-supabase-anon-key"
|
||||||
PUBLIC_SUPABASE_ANON_KEY=""
|
|
||||||
@@ -31,7 +31,7 @@ You can preview the production build with `npm run preview`.
|
|||||||
|
|
||||||
The app is hosted on [Netlify](https://www.netlify.com/) at [pokedex.jcreek.co.uk](https://pokedex.jcreek.co.uk/).
|
The app is hosted on [Netlify](https://www.netlify.com/) at [pokedex.jcreek.co.uk](https://pokedex.jcreek.co.uk/).
|
||||||
|
|
||||||
The Pokédex data is stored in a [MongoDB](https://www.mongodb.com/) database hosted on [MongoDB Cloud](https://cloud.mongodb.com/).
|
The Pokédex data is stored in a [Supabase](https://supabase.com/) database.
|
||||||
|
|
||||||
User authentication is handled by [Supabase Auth](https://supabase.com/auth).
|
User authentication is handled by [Supabase Auth](https://supabase.com/auth).
|
||||||
|
|
||||||
|
|||||||
Generated
+6
-189
@@ -1,16 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "LivingDexTracker",
|
"name": "livingdextracker",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "LivingDexTracker",
|
"name": "livingdextracker",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@supabase/ssr": "^0.1.0",
|
"@supabase/ssr": "^0.1.0",
|
||||||
"@supabase/supabase-js": "^2.42.0",
|
"@supabase/supabase-js": "^2.42.0",
|
||||||
"mongoose": "^8.0.3",
|
|
||||||
"nanoid": "^5.0.4"
|
"nanoid": "^5.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -2661,14 +2660,6 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mongodb-js/saslprep": {
|
|
||||||
"version": "1.1.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.5.tgz",
|
|
||||||
"integrity": "sha512-XLNOMH66KhJzUJNwT/qlMnS4WsNDWD5ASdyaSH3EtK+F4r/CFGa3jT4GNi4mfOitGvWXtdLgQJkQjxSVrio+jA==",
|
|
||||||
"dependencies": {
|
|
||||||
"sparse-bitfield": "^3.0.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@nodelib/fs.scandir": {
|
"node_modules/@nodelib/fs.scandir": {
|
||||||
"version": "2.1.5",
|
"version": "2.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||||
@@ -3406,19 +3397,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/webidl-conversions": {
|
|
||||||
"version": "7.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
|
||||||
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA=="
|
|
||||||
},
|
|
||||||
"node_modules/@types/whatwg-url": {
|
|
||||||
"version": "11.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.4.tgz",
|
|
||||||
"integrity": "sha512-lXCmTWSHJvf0TRSO58nm978b8HJ/EdsSsEKLd3ODHFjo+3VGAyyTp4v50nWvwtzBxSMQrVOK7tcuN0zGPLICMw==",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/webidl-conversions": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/ws": {
|
"node_modules/@types/ws": {
|
||||||
"version": "8.5.10",
|
"version": "8.5.10",
|
||||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
|
||||||
@@ -4207,14 +4185,6 @@
|
|||||||
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/bson": {
|
|
||||||
"version": "6.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/bson/-/bson-6.6.0.tgz",
|
|
||||||
"integrity": "sha512-BVINv2SgcMjL4oYbBuCQTpE3/VKOSxrOA8Cj/wQP7izSzlBGVomdm+TcUd0Pzy0ytLSSDweCKQ6X3f5veM5LQA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/buffer": {
|
"node_modules/buffer": {
|
||||||
"version": "5.7.1",
|
"version": "5.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
@@ -4697,6 +4667,7 @@
|
|||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "2.1.2"
|
"ms": "2.1.2"
|
||||||
},
|
},
|
||||||
@@ -6698,14 +6669,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/kareem": {
|
|
||||||
"version": "2.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.0.tgz",
|
|
||||||
"integrity": "sha512-B9wwgyKKKZkxYZXQzefvb/Ykh9eHixxR+ttTP2c/Pq8NvHi1iYIAImf3nj/DXkPcnenjGEffhPWXnCFRIbNAhw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/keyv": {
|
"node_modules/keyv": {
|
||||||
"version": "4.5.4",
|
"version": "4.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
||||||
@@ -6877,11 +6840,6 @@
|
|||||||
"integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==",
|
"integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/memory-pager": {
|
|
||||||
"version": "1.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
|
||||||
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg=="
|
|
||||||
},
|
|
||||||
"node_modules/merge-stream": {
|
"node_modules/merge-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||||
@@ -7006,105 +6964,6 @@
|
|||||||
"ufo": "^1.3.2"
|
"ufo": "^1.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongodb": {
|
|
||||||
"version": "6.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.5.0.tgz",
|
|
||||||
"integrity": "sha512-Fozq68InT+JKABGLqctgtb8P56pRrJFkbhW0ux+x1mdHeyinor8oNzJqwLjV/t5X5nJGfTlluxfyMnOXNggIUA==",
|
|
||||||
"dependencies": {
|
|
||||||
"@mongodb-js/saslprep": "^1.1.5",
|
|
||||||
"bson": "^6.4.0",
|
|
||||||
"mongodb-connection-string-url": "^3.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@aws-sdk/credential-providers": "^3.188.0",
|
|
||||||
"@mongodb-js/zstd": "^1.1.0",
|
|
||||||
"gcp-metadata": "^5.2.0",
|
|
||||||
"kerberos": "^2.0.1",
|
|
||||||
"mongodb-client-encryption": ">=6.0.0 <7",
|
|
||||||
"snappy": "^7.2.2",
|
|
||||||
"socks": "^2.7.1"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@aws-sdk/credential-providers": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"@mongodb-js/zstd": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"gcp-metadata": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"kerberos": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"mongodb-client-encryption": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"snappy": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"socks": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongodb-connection-string-url": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-t1Vf+m1I5hC2M5RJx/7AtxgABy1cZmIPQRMXw+gEIPn/cZNF3Oiy+l0UIypUwVB5trcWHq3crg2g3uAR9aAwsQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/whatwg-url": "^11.0.2",
|
|
||||||
"whatwg-url": "^13.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose": {
|
|
||||||
"version": "8.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.3.0.tgz",
|
|
||||||
"integrity": "sha512-Y5QNnuA38CEin8hnA+q//nUVztIi4Xklu9xlmbkd1KdWHnIlemSwf5IL/evcI+e2zplL4g5Y6PMkO+nPSAnIdA==",
|
|
||||||
"dependencies": {
|
|
||||||
"bson": "^6.5.0",
|
|
||||||
"kareem": "2.6.0",
|
|
||||||
"mongodb": "6.5.0",
|
|
||||||
"mpath": "0.9.0",
|
|
||||||
"mquery": "5.0.0",
|
|
||||||
"ms": "2.1.3",
|
|
||||||
"sift": "16.0.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/mongoose"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose/node_modules/ms": {
|
|
||||||
"version": "2.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
|
||||||
},
|
|
||||||
"node_modules/mpath": {
|
|
||||||
"version": "0.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
|
|
||||||
"integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mquery": {
|
|
||||||
"version": "5.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz",
|
|
||||||
"integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==",
|
|
||||||
"dependencies": {
|
|
||||||
"debug": "4.x"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mri": {
|
"node_modules/mri": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||||
@@ -7126,7 +6985,8 @@
|
|||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/mz": {
|
"node_modules/mz": {
|
||||||
"version": "2.7.0",
|
"version": "2.7.0",
|
||||||
@@ -7903,6 +7763,7 @@
|
|||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||||
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
||||||
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
@@ -8464,11 +8325,6 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/sift": {
|
|
||||||
"version": "16.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz",
|
|
||||||
"integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ=="
|
|
||||||
},
|
|
||||||
"node_modules/siginfo": {
|
"node_modules/siginfo": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
|
||||||
@@ -8659,14 +8515,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/sparse-bitfield": {
|
|
||||||
"version": "3.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
|
||||||
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"memory-pager": "^1.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/stackback": {
|
"node_modules/stackback": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
|
||||||
@@ -9453,17 +9301,6 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/tr46": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==",
|
|
||||||
"dependencies": {
|
|
||||||
"punycode": "^2.3.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/ts-api-utils": {
|
"node_modules/ts-api-utils": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz",
|
||||||
@@ -10365,26 +10202,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/webidl-conversions": {
|
|
||||||
"version": "7.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
|
||||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/whatwg-url": {
|
|
||||||
"version": "13.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-13.0.0.tgz",
|
|
||||||
"integrity": "sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==",
|
|
||||||
"dependencies": {
|
|
||||||
"tr46": "^4.1.1",
|
|
||||||
"webidl-conversions": "^7.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/which": {
|
"node_modules/which": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
|
|||||||
+9
-3
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "LivingDexTracker",
|
"name": "livingdextracker",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -23,7 +23,14 @@
|
|||||||
"test-generate-sw-node": "npm run build-generate-sw-node && NODE_ADAPTER=true GENERATE_SW=true vitest run && NODE_ADAPTER=true GENERATE_SW=true playwright test",
|
"test-generate-sw-node": "npm run build-generate-sw-node && NODE_ADAPTER=true GENERATE_SW=true vitest run && NODE_ADAPTER=true GENERATE_SW=true playwright test",
|
||||||
"test-inject-manifest": "npm run build-inject-manifest && vitest run && playwright test",
|
"test-inject-manifest": "npm run build-inject-manifest && vitest run && playwright test",
|
||||||
"test-inject-manifest-node": "npm run build-inject-manifest-node && NODE_ADAPTER=true vitest run && NODE_ADAPTER=true playwright test",
|
"test-inject-manifest-node": "npm run build-inject-manifest-node && NODE_ADAPTER=true vitest run && NODE_ADAPTER=true playwright test",
|
||||||
"test": "npm run test-generate-sw && npm run test-generate-sw-node && npm run test-inject-manifest && npm run test-inject-manifest-node"
|
"test": "npm run test-generate-sw && npm run test-generate-sw-node && npm run test-inject-manifest && npm run test-inject-manifest-node",
|
||||||
|
"supabase:start": "supabase start",
|
||||||
|
"supabase:stop": "supabase stop",
|
||||||
|
"supabase:reset": "supabase db reset",
|
||||||
|
"supabase:studio": "supabase studio",
|
||||||
|
"migrate:convert-tsv": "node scripts/convert-tsv-to-sql.js",
|
||||||
|
"dev:local": "./scripts/dev-local.sh && npm run dev",
|
||||||
|
"dev:supabase": "supabase start && npm run dev"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.37.1",
|
"@playwright/test": "^1.37.1",
|
||||||
@@ -58,7 +65,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@supabase/ssr": "^0.1.0",
|
"@supabase/ssr": "^0.1.0",
|
||||||
"@supabase/supabase-js": "^2.42.0",
|
"@supabase/supabase-js": "^2.42.0",
|
||||||
"mongoose": "^8.0.3",
|
|
||||||
"nanoid": "^5.0.4"
|
"nanoid": "^5.0.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -59,10 +59,6 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (strippedPokedexNumber == '869') {
|
|
||||||
// console.log(sanitisedPokemonName, sanitisedForm);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// If the form is contained in the identifier, use that
|
// If the form is contained in the identifier, use that
|
||||||
if (
|
if (
|
||||||
pokeApiPokemon.find(
|
pokeApiPokemon.find(
|
||||||
|
|||||||
@@ -13,15 +13,25 @@
|
|||||||
export let supabase: any;
|
export let supabase: any;
|
||||||
|
|
||||||
async function signInWithEmail() {
|
async function signInWithEmail() {
|
||||||
// TODO use the data and error from the response
|
try {
|
||||||
const { data, error } = await supabase.auth
|
const { data, error } = await supabase.auth.signInWithPassword({
|
||||||
.signInWithPassword({
|
|
||||||
email: email,
|
email: email,
|
||||||
password: password
|
password: password
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
emitSignedInEvent();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Sign in error:', error);
|
||||||
|
alert(`Sign in failed: ${error.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
emitSignedInEvent();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Sign in error:', err);
|
||||||
|
alert('Sign in failed');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,25 @@
|
|||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
export let pokedexEntry: PokedexEntry;
|
export let pokedexEntry: PokedexEntry;
|
||||||
export let catchRecord: CatchRecord;
|
export let catchRecord: CatchRecord | null;
|
||||||
export let showOrigins: boolean;
|
export let showOrigins: boolean;
|
||||||
export let showForms: boolean;
|
export let showForms: boolean;
|
||||||
export let showShiny: boolean;
|
export let showShiny: boolean;
|
||||||
|
export let userId: string | null = null;
|
||||||
|
|
||||||
|
// Create a default catch record if none exists
|
||||||
|
$: if (!catchRecord) {
|
||||||
|
catchRecord = {
|
||||||
|
_id: '', // Empty string, not temp ID - will be created by server
|
||||||
|
userId: userId || '',
|
||||||
|
pokedexEntryId: pokedexEntry._id,
|
||||||
|
haveToEvolve: false,
|
||||||
|
caught: false,
|
||||||
|
inHome: false,
|
||||||
|
hasGigantamaxed: false,
|
||||||
|
personalNotes: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
@@ -124,12 +139,13 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<p>
|
<p>
|
||||||
<label class="block font-bold mb-1" for={`personalNotesInput-${catchRecord._id}`}
|
<label
|
||||||
>Notes:</label
|
class="block font-bold mb-1"
|
||||||
|
for={`personalNotesInput-${catchRecord?._id || pokedexEntry._id}`}>Notes:</label
|
||||||
>
|
>
|
||||||
<textarea
|
<textarea
|
||||||
bind:value={catchRecord.personalNotes}
|
bind:value={catchRecord.personalNotes}
|
||||||
id={`personalNotesInput-${catchRecord._id}`}
|
id={`personalNotesInput-${catchRecord?._id || pokedexEntry._id}`}
|
||||||
class="form-textarea w-full p-2 border rounded"
|
class="form-textarea w-full p-2 border rounded"
|
||||||
on:change={updateCatchRecord}
|
on:change={updateCatchRecord}
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|||||||
@@ -19,18 +19,18 @@
|
|||||||
export let markBoxAsNotInHome = (boxNumber: number) => {};
|
export let markBoxAsNotInHome = (boxNumber: number) => {};
|
||||||
export let createCatchRecords = () => {};
|
export let createCatchRecords = () => {};
|
||||||
|
|
||||||
function cellBackgroundColourClass(catchRecord: CatchRecord) {
|
function cellBackgroundColourClass(catchRecord: CatchRecord | null) {
|
||||||
if (catchRecord.caught) {
|
if (catchRecord?.caught) {
|
||||||
return 'bg-green-100/50';
|
return 'bg-green-100/50';
|
||||||
} else if (catchRecord.haveToEvolve) {
|
} else if (catchRecord?.haveToEvolve) {
|
||||||
return 'bg-yellow-100/50';
|
return 'bg-yellow-100/50';
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cellBackgroundColourStyle(pokedexEntry: PokedexEntry, catchRecord: CatchRecord) {
|
function cellBackgroundColourStyle(pokedexEntry: PokedexEntry, catchRecord: CatchRecord | null) {
|
||||||
if (catchRecord.caught || catchRecord.haveToEvolve) {
|
if (catchRecord?.caught || catchRecord?.haveToEvolve) {
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
if (pokedexEntry[currentPlacement].column % 2 === 0) {
|
if (pokedexEntry[currentPlacement].column % 2 === 0) {
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
>
|
>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<div slot="hover-target">
|
<div slot="hover-target">
|
||||||
{#if catchRecord.inHome}
|
{#if catchRecord?.inHome}
|
||||||
<span
|
<span
|
||||||
class="absolute -top-5 -right-4 z-2 p-1 text-secondary text-lg font-extrabold"
|
class="absolute -top-5 -right-4 z-2 p-1 text-secondary text-lg font-extrabold"
|
||||||
>✓</span
|
>✓</span
|
||||||
@@ -97,9 +97,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>{pokedexEntry.pokedexNumber.toString().padStart(3, '0')}</div>
|
<div>{pokedexEntry.pokedexNumber.toString().padStart(3, '0')}</div>
|
||||||
<div>
|
<div>
|
||||||
Caught: {catchRecord.caught ? 'Yes' : 'No'} <br />
|
Caught: {catchRecord?.caught ? 'Yes' : 'No'} <br />
|
||||||
Needs to Evolve: {catchRecord.haveToEvolve ? 'Yes' : 'No'} <br />
|
Needs to Evolve: {catchRecord?.haveToEvolve ? 'Yes' : 'No'} <br />
|
||||||
In Home: {catchRecord.inHome ? 'Yes' : 'No'}
|
In Home: {catchRecord?.inHome ? 'Yes' : 'No'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
export let failedToLoad = false;
|
export let failedToLoad = false;
|
||||||
export let updateACatch = (event: any) => {};
|
export let updateACatch = (event: any) => {};
|
||||||
export let createCatchRecords = () => {};
|
export let createCatchRecords = () => {};
|
||||||
|
export let userId: string | null = null;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main class="flex-1 p-4 w-full">
|
<main class="flex-1 p-4 w-full">
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
{showOrigins}
|
{showOrigins}
|
||||||
{showForms}
|
{showForms}
|
||||||
{showShiny}
|
{showShiny}
|
||||||
|
{userId}
|
||||||
bind:catchRecord
|
bind:catchRecord
|
||||||
on:updateCatch={updateACatch}
|
on:updateCatch={updateACatch}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import mongoose, { Schema, Document, Types } from 'mongoose';
|
// Supabase-based CatchRecord interface
|
||||||
|
export interface CatchRecord {
|
||||||
export interface CatchRecord extends Document {
|
_id: string; // Maps to Supabase 'id' field for frontend compatibility
|
||||||
userId: string;
|
userId: string;
|
||||||
pokedexEntryId: Types.ObjectId;
|
pokedexEntryId: string; // String representation of the foreign key
|
||||||
haveToEvolve: boolean;
|
haveToEvolve: boolean;
|
||||||
caught: boolean;
|
caught: boolean;
|
||||||
inHome: boolean;
|
inHome: boolean;
|
||||||
@@ -10,15 +10,16 @@ export interface CatchRecord extends Document {
|
|||||||
personalNotes: string;
|
personalNotes: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const catchRecordSchema = new Schema<CatchRecord>({
|
// Database record type for Supabase
|
||||||
userId: String,
|
export interface CatchRecordDB {
|
||||||
pokedexEntryId: { type: Schema.Types.ObjectId, ref: 'PokedexEntry', required: true },
|
id: string;
|
||||||
haveToEvolve: { type: Boolean, default: false },
|
userId: string;
|
||||||
caught: { type: Boolean, default: false },
|
pokedexEntryId: number; // Numeric foreign key in database
|
||||||
inHome: { type: Boolean, default: false },
|
haveToEvolve: boolean;
|
||||||
hasGigantamaxed: { type: Boolean, default: false },
|
caught: boolean;
|
||||||
personalNotes: String
|
inHome: boolean;
|
||||||
});
|
hasGigantamaxed: boolean;
|
||||||
|
personalNotes: string;
|
||||||
const CatchRecordModel = mongoose.model<CatchRecord>('CatchRecord', catchRecordSchema);
|
createdAt: string;
|
||||||
export default CatchRecordModel;
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ import { type CatchRecord } from './CatchRecord';
|
|||||||
|
|
||||||
export interface CombinedData {
|
export interface CombinedData {
|
||||||
pokedexEntry: PokedexEntry;
|
pokedexEntry: PokedexEntry;
|
||||||
catchRecord: CatchRecord;
|
catchRecord: CatchRecord | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import mongoose, { Schema, Document } from 'mongoose';
|
// Supabase-based PokedexEntry interface
|
||||||
|
export interface PokedexEntry {
|
||||||
export interface PokedexEntry extends Document {
|
_id: string; // Maps to Supabase 'id' field for frontend compatibility
|
||||||
pokedexNumber: number;
|
pokedexNumber: number;
|
||||||
boxPlacement: { box: number; row: number; column: number };
|
boxPlacement: { box: number; row: number; column: number };
|
||||||
boxPlacementForms: { box: number; row: number; column: number };
|
boxPlacementForms: { box: number; row: number; column: number };
|
||||||
@@ -11,41 +11,27 @@ export interface PokedexEntry extends Document {
|
|||||||
gamesToCatchIn: string[];
|
gamesToCatchIn: string[];
|
||||||
regionToEvolveIn: string;
|
regionToEvolveIn: string;
|
||||||
evolutionInformation: string;
|
evolutionInformation: string;
|
||||||
catchInformation: [
|
catchInformation: string[];
|
||||||
{
|
|
||||||
game: string;
|
|
||||||
location: string;
|
|
||||||
notes: string;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pokedexEntrySchema = new Schema<PokedexEntry>({
|
// Database record type for Supabase
|
||||||
pokedexNumber: Number,
|
export interface PokedexEntryDB {
|
||||||
boxPlacement: {
|
id: number;
|
||||||
box: Number,
|
pokedexNumber: number;
|
||||||
row: Number,
|
pokemon: string;
|
||||||
column: Number
|
form: string | null;
|
||||||
},
|
canGigantamax: boolean;
|
||||||
boxPlacementForms: {
|
regionToCatchIn: string | null;
|
||||||
box: Number,
|
gamesToCatchIn: string[] | null;
|
||||||
row: Number,
|
regionToEvolveIn: string | null;
|
||||||
column: Number
|
evolutionInformation: string | null;
|
||||||
},
|
catchInformation: string[] | null;
|
||||||
pokemon: String,
|
boxPlacementFormsBox: number | null;
|
||||||
form: String,
|
boxPlacementFormsRow: number | null;
|
||||||
canGigantamax: Boolean,
|
boxPlacementFormsColumn: number | null;
|
||||||
regionToCatchIn: String,
|
boxPlacementBox: number | null;
|
||||||
gamesToCatchIn: Array<string>,
|
boxPlacementRow: number | null;
|
||||||
regionToEvolveIn: String,
|
boxPlacementColumn: number | null;
|
||||||
evolutionInformation: String,
|
createdAt: string;
|
||||||
catchInformation: [
|
updatedAt: string;
|
||||||
{
|
}
|
||||||
game: String,
|
|
||||||
location: String,
|
|
||||||
notes: String
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
export default mongoose.model<PokedexEntry>('PokedexEntry', pokedexEntrySchema);
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import mongoose, { Schema, Document } from 'mongoose';
|
|
||||||
|
|
||||||
export interface PokedexMetadata extends Document {
|
|
||||||
lastModified: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pokedexMetadataSchema = new Schema<PokedexMetadata>({
|
|
||||||
lastModified: {
|
|
||||||
type: Date,
|
|
||||||
default: Date.now
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default mongoose.model<PokedexMetadata>('PokedexMetadata', pokedexMetadataSchema);
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
import mongoose, { Schema, Document } from 'mongoose';
|
// Supabase-based RegionGameMapping interface
|
||||||
|
export interface RegionGameMapping {
|
||||||
export interface RegionGameMapping extends Document {
|
id?: number;
|
||||||
region: string;
|
region: string;
|
||||||
games: string[];
|
game: string; // Note: Different from MongoDB version which had 'games' array
|
||||||
}
|
}
|
||||||
|
|
||||||
const regionGameMappingSchema = new Schema<RegionGameMapping>({
|
// Database record type for Supabase
|
||||||
region: String,
|
export interface RegionGameMappingDB {
|
||||||
games: Array<string>
|
id: number;
|
||||||
});
|
region: string;
|
||||||
|
game: string;
|
||||||
export default mongoose.model<RegionGameMapping>('RegionGameMapping', regionGameMappingSchema);
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import mongoose, { Schema, Document } from 'mongoose';
|
|
||||||
|
|
||||||
export interface User extends Document {
|
|
||||||
username: string;
|
|
||||||
// Add other user-related fields as needed
|
|
||||||
}
|
|
||||||
|
|
||||||
const userSchema = new Schema<User>({
|
|
||||||
username: String
|
|
||||||
// Add other user-related fields as needed
|
|
||||||
});
|
|
||||||
|
|
||||||
export default mongoose.model<User>('User', userSchema);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import mongoose, { Schema, Document } from 'mongoose';
|
|
||||||
|
|
||||||
export interface UserCatchEntry extends Document {
|
|
||||||
userId: mongoose.Types.ObjectId; // Reference to the user
|
|
||||||
pokedexEntryId: mongoose.Types.ObjectId; // Reference to the pokedex entry
|
|
||||||
haveToEvolve: boolean;
|
|
||||||
caught: boolean;
|
|
||||||
inHome: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const userCatchEntrySchema = new Schema<UserCatchEntry>({
|
|
||||||
userId: { type: mongoose.Types.ObjectId, ref: 'User' },
|
|
||||||
pokedexEntryId: { type: mongoose.Types.ObjectId, ref: 'PokedexEntry' },
|
|
||||||
haveToEvolve: Boolean,
|
|
||||||
caught: Boolean,
|
|
||||||
inHome: Boolean
|
|
||||||
});
|
|
||||||
|
|
||||||
export default mongoose.model<UserCatchEntry>('UserCatchEntry', userCatchEntrySchema);
|
|
||||||
@@ -1,38 +1,158 @@
|
|||||||
import CatchRecordModel, { type CatchRecord } from '$lib/models/CatchRecord';
|
import type { CatchRecord, CatchRecordDB } from '$lib/models/CatchRecord';
|
||||||
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
class CatchRecordRepository {
|
class CatchRecordRepository {
|
||||||
|
constructor(
|
||||||
|
private supabase: SupabaseClient,
|
||||||
|
private userId: string
|
||||||
|
) {}
|
||||||
|
|
||||||
|
// Transform Supabase data to frontend format (minimal transformation)
|
||||||
|
private transformCatchRecord(record: CatchRecordDB): CatchRecord {
|
||||||
|
return {
|
||||||
|
_id: record.id,
|
||||||
|
userId: record.userId,
|
||||||
|
pokedexEntryId: record.pokedexEntryId.toString(),
|
||||||
|
haveToEvolve: record.haveToEvolve,
|
||||||
|
caught: record.caught,
|
||||||
|
inHome: record.inHome,
|
||||||
|
hasGigantamaxed: record.hasGigantamaxed,
|
||||||
|
personalNotes: record.personalNotes
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform frontend data to database format (minimal transformation)
|
||||||
|
private transformToDatabase(data: Partial<CatchRecord>): Partial<CatchRecordDB> {
|
||||||
|
const dbData: Partial<CatchRecordDB> = {};
|
||||||
|
if (data.pokedexEntryId !== undefined && data.pokedexEntryId !== null) {
|
||||||
|
const numericId = Number(data.pokedexEntryId);
|
||||||
|
if (isNaN(numericId)) {
|
||||||
|
throw new Error(`Invalid pokedexEntryId: ${data.pokedexEntryId}`);
|
||||||
|
}
|
||||||
|
dbData.pokedexEntryId = numericId;
|
||||||
|
}
|
||||||
|
if (data.haveToEvolve !== undefined) dbData.haveToEvolve = data.haveToEvolve;
|
||||||
|
if (data.caught !== undefined) dbData.caught = data.caught;
|
||||||
|
if (data.inHome !== undefined) dbData.inHome = data.inHome;
|
||||||
|
if (data.hasGigantamaxed !== undefined) dbData.hasGigantamaxed = data.hasGigantamaxed;
|
||||||
|
if (data.personalNotes !== undefined) dbData.personalNotes = data.personalNotes;
|
||||||
|
|
||||||
|
return dbData;
|
||||||
|
}
|
||||||
|
|
||||||
async findById(id: string): Promise<CatchRecord | null> {
|
async findById(id: string): Promise<CatchRecord | null> {
|
||||||
return CatchRecordModel.findById(id).exec();
|
const { data, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', id)
|
||||||
|
.eq('userId', this.userId)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !data) return null;
|
||||||
|
return this.transformCatchRecord(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<CatchRecord[]> {
|
async findAll(): Promise<CatchRecord[]> {
|
||||||
return CatchRecordModel.find().exec();
|
const { data, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('userId', this.userId);
|
||||||
|
|
||||||
|
if (error || !data) return [];
|
||||||
|
return data.map((record) => this.transformCatchRecord(record));
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByUserId(userId: string): Promise<CatchRecord[]> {
|
async findByUserId(userId: string): Promise<CatchRecord[]> {
|
||||||
return CatchRecordModel.find({ userId }).exec();
|
const { data, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('userId', userId);
|
||||||
|
|
||||||
|
if (error || !data) return [];
|
||||||
|
return data.map((record) => this.transformCatchRecord(record));
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: Partial<CatchRecord>): Promise<CatchRecord> {
|
async create(data: Partial<CatchRecord>): Promise<CatchRecord> {
|
||||||
return CatchRecordModel.create(data);
|
const dbData = {
|
||||||
|
userId: this.userId,
|
||||||
|
...this.transformToDatabase(data)
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data: result, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.insert(dbData)
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Supabase error creating catch record:', error);
|
||||||
|
throw new Error(`Failed to create catch record: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new Error('Failed to create catch record: No result returned');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.transformCatchRecord(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: Partial<CatchRecord>): Promise<CatchRecord | null> {
|
async update(id: string, data: Partial<CatchRecord>): Promise<CatchRecord | null> {
|
||||||
return CatchRecordModel.findByIdAndUpdate(id, data, { new: true }).exec();
|
const dbData = this.transformToDatabase(data);
|
||||||
|
|
||||||
|
const { data: result, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.update(dbData)
|
||||||
|
.eq('id', id)
|
||||||
|
.eq('userId', this.userId)
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !result) return null;
|
||||||
|
return this.transformCatchRecord(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id: string): Promise<void> {
|
async delete(id: string): Promise<void> {
|
||||||
await CatchRecordModel.findByIdAndDelete(id).exec();
|
const { error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.delete()
|
||||||
|
.eq('id', id)
|
||||||
|
.eq('userId', this.userId);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error deleting catch record:', error);
|
||||||
|
throw new Error(`Failed to delete catch record: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async upsert(data: Partial<CatchRecord>): Promise<CatchRecord | null> {
|
async upsert(data: Partial<CatchRecord>): Promise<CatchRecord | null> {
|
||||||
if (data._id) {
|
if (data._id) {
|
||||||
// Update existing record
|
return this.update(data._id, data);
|
||||||
return CatchRecordModel.findByIdAndUpdate(data._id, data, { new: true }).exec();
|
} else if (data.pokedexEntryId) {
|
||||||
} else {
|
// Try to find existing record for this user and pokemon
|
||||||
// Create new record
|
const existing = await this.findByUserAndPokemon(this.userId, data.pokedexEntryId);
|
||||||
return CatchRecordModel.create(data);
|
if (existing) {
|
||||||
|
return this.update(existing._id, data);
|
||||||
|
} else {
|
||||||
|
return this.create(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return this.create(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findByUserAndPokemon(userId: string, pokedexEntryId: string): Promise<CatchRecord | null> {
|
||||||
|
const numericId = Number(pokedexEntryId);
|
||||||
|
if (isNaN(numericId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { data, error } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('userId', userId)
|
||||||
|
.eq('pokedexEntryId', numericId)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !data) return null;
|
||||||
|
return this.transformCatchRecord(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,79 +1,128 @@
|
|||||||
import PokedexEntryModel, { type PokedexEntry } from '$lib/models/PokedexEntry';
|
import { type PokedexEntry, type PokedexEntryDB } from '$lib/models/PokedexEntry';
|
||||||
import CatchRecordModel, { type CatchRecord } from '$lib/models/CatchRecord';
|
import { type CatchRecord, type CatchRecordDB } from '$lib/models/CatchRecord';
|
||||||
import { type CombinedData } from '$lib/models/CombinedData';
|
import { type CombinedData } from '$lib/models/CombinedData';
|
||||||
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
class CombinedDataRepository {
|
class CombinedDataRepository {
|
||||||
|
constructor(
|
||||||
|
private supabase: SupabaseClient,
|
||||||
|
private userId: string
|
||||||
|
) {}
|
||||||
|
|
||||||
|
// Transform Supabase data to match frontend expectations (minimal transformation)
|
||||||
|
private transformPokedexEntry(entry: PokedexEntryDB): PokedexEntry {
|
||||||
|
return {
|
||||||
|
_id: entry.id.toString(),
|
||||||
|
pokedexNumber: entry.pokedexNumber,
|
||||||
|
pokemon: entry.pokemon,
|
||||||
|
form: entry.form || '',
|
||||||
|
canGigantamax: entry.canGigantamax,
|
||||||
|
regionToCatchIn: entry.regionToCatchIn || '',
|
||||||
|
gamesToCatchIn: entry.gamesToCatchIn || [],
|
||||||
|
regionToEvolveIn: entry.regionToEvolveIn || '',
|
||||||
|
evolutionInformation: entry.evolutionInformation || '',
|
||||||
|
catchInformation: entry.catchInformation || [],
|
||||||
|
boxPlacementForms: {
|
||||||
|
box: entry.boxPlacementFormsBox || 0,
|
||||||
|
row: entry.boxPlacementFormsRow || 0,
|
||||||
|
column: entry.boxPlacementFormsColumn || 0
|
||||||
|
},
|
||||||
|
boxPlacement: {
|
||||||
|
box: entry.boxPlacementBox || 0,
|
||||||
|
row: entry.boxPlacementRow || 0,
|
||||||
|
column: entry.boxPlacementColumn || 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private transformCatchRecord(record: CatchRecordDB): CatchRecord {
|
||||||
|
return {
|
||||||
|
_id: record.id,
|
||||||
|
userId: record.userId,
|
||||||
|
pokedexEntryId: record.pokedexEntryId.toString(),
|
||||||
|
haveToEvolve: record.haveToEvolve,
|
||||||
|
caught: record.caught,
|
||||||
|
inHome: record.inHome,
|
||||||
|
hasGigantamaxed: record.hasGigantamaxed,
|
||||||
|
personalNotes: record.personalNotes
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async findAllCombinedData(
|
async findAllCombinedData(
|
||||||
userId: string,
|
userId: string,
|
||||||
enableForms: boolean = true,
|
enableForms: boolean = true,
|
||||||
region: string = '',
|
region: string = '',
|
||||||
game: string = ''
|
game: string = ''
|
||||||
): Promise<CombinedData[]> {
|
): Promise<CombinedData[]> {
|
||||||
const pipeline: any[] = [
|
let query = this.supabase.from('pokedex_entries').select('*');
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: 'catchrecords',
|
|
||||||
let: { entryId: '$_id' },
|
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$and: [
|
|
||||||
{ $eq: ['$pokedexEntryId', '$$entryId'] },
|
|
||||||
{ $eq: ['$userId', userId] }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
as: 'catchRecord'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$catchRecord',
|
|
||||||
preserveNullAndEmptyArrays: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$sort: {
|
|
||||||
'boxPlacementForms.box': 1,
|
|
||||||
'boxPlacementForms.row': 1,
|
|
||||||
'boxPlacementForms.column': 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
// Apply filters
|
||||||
if (!enableForms) {
|
if (!enableForms) {
|
||||||
pipeline.unshift({
|
query = query.not('boxPlacementBox', 'is', null);
|
||||||
$match: {
|
|
||||||
'boxPlacement.box': { $ne: null }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region.length > 0) {
|
if (region) {
|
||||||
pipeline.unshift({
|
query = query.eq('regionToCatchIn', region);
|
||||||
$match: {
|
|
||||||
regionToCatchIn: region
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.length > 0) {
|
if (game) {
|
||||||
pipeline.unshift({
|
query = query.contains('gamesToCatchIn', [game]);
|
||||||
$match: {
|
|
||||||
gamesToCatchIn: { $in: [game] }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinedData: CombinedData[] = await PokedexEntryModel.aggregate(pipeline).exec();
|
// Order by box placement
|
||||||
|
if (enableForms) {
|
||||||
|
query = query
|
||||||
|
.order('boxPlacementFormsBox', { ascending: true })
|
||||||
|
.order('boxPlacementFormsRow', { ascending: true })
|
||||||
|
.order('boxPlacementFormsColumn', { ascending: true });
|
||||||
|
} else {
|
||||||
|
query = query
|
||||||
|
.order('boxPlacementBox', { ascending: true })
|
||||||
|
.order('boxPlacementRow', { ascending: true })
|
||||||
|
.order('boxPlacementColumn', { ascending: true });
|
||||||
|
}
|
||||||
|
|
||||||
return combinedData.map((data) => ({
|
const { data: entries, error: entriesError } = await query;
|
||||||
pokedexEntry: data as PokedexEntry,
|
|
||||||
catchRecord: data.catchRecord as CatchRecord
|
if (entriesError) {
|
||||||
}));
|
console.error('Error finding combined data:', entriesError);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entries || entries.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get catch records for all entries
|
||||||
|
let catchRecords: CatchRecordDB[] = [];
|
||||||
|
if (userId) {
|
||||||
|
const entryIds = entries.map((entry) => entry.id);
|
||||||
|
const { data: records, error: recordsError } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('userId', userId)
|
||||||
|
.in('pokedexEntryId', entryIds);
|
||||||
|
|
||||||
|
if (!recordsError && records) {
|
||||||
|
catchRecords = records;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the data exactly like master branch
|
||||||
|
return entries.map((entry) => {
|
||||||
|
const userCatchRecord =
|
||||||
|
catchRecords.find((record) => record.pokedexEntryId === entry.id) || null;
|
||||||
|
|
||||||
|
const transformedEntry = this.transformPokedexEntry(entry);
|
||||||
|
const transformedCatchRecord = userCatchRecord
|
||||||
|
? this.transformCatchRecord(userCatchRecord)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
pokedexEntry: transformedEntry,
|
||||||
|
catchRecord: transformedCatchRecord
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findCombinedData(
|
async findCombinedData(
|
||||||
@@ -84,139 +133,108 @@ class CombinedDataRepository {
|
|||||||
region: string = '',
|
region: string = '',
|
||||||
game: string = ''
|
game: string = ''
|
||||||
): Promise<CombinedData[]> {
|
): Promise<CombinedData[]> {
|
||||||
const skip = (page - 1) * limit;
|
const from = (page - 1) * limit;
|
||||||
const pipeline: any[] = [
|
const to = from + limit - 1;
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: 'catchrecords',
|
|
||||||
let: { entryId: '$_id' },
|
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$and: [
|
|
||||||
{ $eq: ['$pokedexEntryId', '$$entryId'] },
|
|
||||||
{ $eq: ['$userId', userId] }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
as: 'catchRecord'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$catchRecord',
|
|
||||||
preserveNullAndEmptyArrays: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$sort: {
|
|
||||||
'boxPlacementForms.box': 1,
|
|
||||||
'boxPlacementForms.row': 1,
|
|
||||||
'boxPlacementForms.column': 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ $skip: skip },
|
|
||||||
{ $limit: limit }
|
|
||||||
];
|
|
||||||
|
|
||||||
|
let query = this.supabase.from('pokedex_entries').select('*').range(from, to);
|
||||||
|
|
||||||
|
// Apply filters
|
||||||
if (!enableForms) {
|
if (!enableForms) {
|
||||||
pipeline.unshift({
|
query = query.not('boxPlacementBox', 'is', null);
|
||||||
$match: {
|
|
||||||
'boxPlacement.box': { $ne: null }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region.length > 0) {
|
if (region) {
|
||||||
pipeline.unshift({
|
query = query.eq('regionToCatchIn', region);
|
||||||
$match: {
|
|
||||||
regionToCatchIn: region
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.length > 0) {
|
if (game) {
|
||||||
pipeline.unshift({
|
query = query.contains('gamesToCatchIn', [game]);
|
||||||
$match: {
|
|
||||||
gamesToCatchIn: { $in: [game] }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinedData: CombinedData[] = await PokedexEntryModel.aggregate(pipeline).exec();
|
// Order by box placement
|
||||||
|
if (enableForms) {
|
||||||
|
query = query
|
||||||
|
.order('boxPlacementFormsBox', { ascending: true })
|
||||||
|
.order('boxPlacementFormsRow', { ascending: true })
|
||||||
|
.order('boxPlacementFormsColumn', { ascending: true });
|
||||||
|
} else {
|
||||||
|
query = query
|
||||||
|
.order('boxPlacementBox', { ascending: true })
|
||||||
|
.order('boxPlacementRow', { ascending: true })
|
||||||
|
.order('boxPlacementColumn', { ascending: true });
|
||||||
|
}
|
||||||
|
|
||||||
return combinedData.map((data) => ({
|
const { data: entries, error: entriesError } = await query;
|
||||||
pokedexEntry: data as PokedexEntry,
|
|
||||||
catchRecord: data.catchRecord as CatchRecord
|
if (entriesError) {
|
||||||
}));
|
console.error('Error finding paginated combined data:', entriesError);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entries || entries.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get catch records for these entries
|
||||||
|
let catchRecords: CatchRecordDB[] = [];
|
||||||
|
if (userId) {
|
||||||
|
const entryIds = entries.map((entry) => entry.id);
|
||||||
|
const { data: records, error: recordsError } = await this.supabase
|
||||||
|
.from('catch_records')
|
||||||
|
.select('*')
|
||||||
|
.eq('userId', userId)
|
||||||
|
.in('pokedexEntryId', entryIds);
|
||||||
|
|
||||||
|
if (!recordsError && records) {
|
||||||
|
catchRecords = records;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the data exactly like master branch
|
||||||
|
return entries.map((entry) => {
|
||||||
|
const userCatchRecord =
|
||||||
|
catchRecords.find((record) => record.pokedexEntryId === entry.id) || null;
|
||||||
|
|
||||||
|
const transformedEntry = this.transformPokedexEntry(entry);
|
||||||
|
const transformedCatchRecord = userCatchRecord
|
||||||
|
? this.transformCatchRecord(userCatchRecord)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
pokedexEntry: transformedEntry,
|
||||||
|
catchRecord: transformedCatchRecord
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async countCombinedData(userId: string, enableForms: boolean, region: string, game: string): Promise<number> {
|
async countCombinedData(
|
||||||
const pipeline: any[] = [
|
enableForms: boolean,
|
||||||
{
|
region: string,
|
||||||
$lookup: {
|
game: string
|
||||||
from: 'catchrecords',
|
): Promise<number> {
|
||||||
let: { entryId: '$_id' },
|
let query = this.supabase.from('pokedex_entries').select('id', { count: 'exact', head: true });
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$and: [
|
|
||||||
{ $eq: ['$pokedexEntryId', '$$entryId'] },
|
|
||||||
{ $eq: ['$userId', userId] }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
as: 'catchRecord'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$unwind: {
|
|
||||||
path: '$catchRecord',
|
|
||||||
preserveNullAndEmptyArrays: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$count: 'total'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
// Apply same filters as in findCombinedData
|
||||||
if (!enableForms) {
|
if (!enableForms) {
|
||||||
pipeline.unshift({
|
query = query.not('boxPlacementBox', 'is', null);
|
||||||
$match: {
|
|
||||||
'boxPlacement.box': { $ne: null }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region.length > 0) {
|
if (region) {
|
||||||
pipeline.unshift({
|
query = query.eq('regionToCatchIn', region);
|
||||||
$match: {
|
|
||||||
regionToCatchIn: region
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.length > 0) {
|
if (game) {
|
||||||
pipeline.unshift({
|
query = query.contains('gamesToCatchIn', [game]);
|
||||||
$match: {
|
|
||||||
gamesToCatchIn: { $in: [game] }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const { count, error } = await query;
|
||||||
const result = await PokedexEntryModel.aggregate(pipeline).exec();
|
|
||||||
return result.length > 0 ? result[0].total : 0;
|
if (error) {
|
||||||
} catch (error) {
|
console.error('Error counting combined data:', error);
|
||||||
console.error('Error counting documents:', error);
|
return 0;
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return count || 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,127 @@
|
|||||||
import PokedexEntryModel, { type PokedexEntry } from '$lib/models/PokedexEntry';
|
import { type PokedexEntry, type PokedexEntryDB } from '$lib/models/PokedexEntry';
|
||||||
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
class PokedexEntryRepository {
|
class PokedexEntryRepository {
|
||||||
|
constructor(private supabase: SupabaseClient) {}
|
||||||
|
|
||||||
|
// Transform Supabase data to match frontend expectations (minimal transformation)
|
||||||
|
private transformPokedexEntry(entry: PokedexEntryDB): PokedexEntry {
|
||||||
|
return {
|
||||||
|
_id: entry.id.toString(),
|
||||||
|
pokedexNumber: entry.pokedexNumber,
|
||||||
|
pokemon: entry.pokemon,
|
||||||
|
form: entry.form || '',
|
||||||
|
canGigantamax: entry.canGigantamax,
|
||||||
|
regionToCatchIn: entry.regionToCatchIn || '',
|
||||||
|
gamesToCatchIn: entry.gamesToCatchIn || [],
|
||||||
|
regionToEvolveIn: entry.regionToEvolveIn || '',
|
||||||
|
evolutionInformation: entry.evolutionInformation || '',
|
||||||
|
catchInformation: entry.catchInformation || [],
|
||||||
|
boxPlacementForms: {
|
||||||
|
box: entry.boxPlacementFormsBox || 0,
|
||||||
|
row: entry.boxPlacementFormsRow || 0,
|
||||||
|
column: entry.boxPlacementFormsColumn || 0
|
||||||
|
},
|
||||||
|
boxPlacement: {
|
||||||
|
box: entry.boxPlacementBox || 0,
|
||||||
|
row: entry.boxPlacementRow || 0,
|
||||||
|
column: entry.boxPlacementColumn || 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async findById(id: string): Promise<PokedexEntry | null> {
|
async findById(id: string): Promise<PokedexEntry | null> {
|
||||||
return PokedexEntryModel.findById(id).exec();
|
const { data, error } = await this.supabase
|
||||||
|
.from('pokedex_entries')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', id)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !data) return null;
|
||||||
|
return this.transformPokedexEntry(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<PokedexEntry[]> {
|
async findAll(): Promise<PokedexEntry[]> {
|
||||||
return PokedexEntryModel.find().exec();
|
const { data, error } = await this.supabase
|
||||||
|
.from('pokedex_entries')
|
||||||
|
.select('*')
|
||||||
|
.order('pokedexNumber', { ascending: true });
|
||||||
|
|
||||||
|
if (error || !data) return [];
|
||||||
|
return data.map((entry) => this.transformPokedexEntry(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: Partial<PokedexEntry>): Promise<PokedexEntry> {
|
async create(data: Partial<PokedexEntry>): Promise<PokedexEntry> {
|
||||||
return PokedexEntryModel.create(data);
|
// Transform to database format (minimal transformation needed)
|
||||||
|
const dbData: Partial<PokedexEntryDB> = {};
|
||||||
|
if (data.pokedexNumber !== undefined) dbData.pokedexNumber = data.pokedexNumber;
|
||||||
|
if (data.pokemon !== undefined) dbData.pokemon = data.pokemon;
|
||||||
|
if (data.form !== undefined) dbData.form = data.form;
|
||||||
|
if (data.canGigantamax !== undefined) dbData.canGigantamax = data.canGigantamax;
|
||||||
|
if (data.regionToCatchIn !== undefined) dbData.regionToCatchIn = data.regionToCatchIn;
|
||||||
|
if (data.gamesToCatchIn !== undefined) dbData.gamesToCatchIn = data.gamesToCatchIn;
|
||||||
|
if (data.regionToEvolveIn !== undefined) dbData.regionToEvolveIn = data.regionToEvolveIn;
|
||||||
|
if (data.evolutionInformation !== undefined)
|
||||||
|
dbData.evolutionInformation = data.evolutionInformation;
|
||||||
|
if (data.catchInformation !== undefined) dbData.catchInformation = data.catchInformation;
|
||||||
|
if (data.boxPlacementForms?.box !== undefined)
|
||||||
|
dbData.boxPlacementFormsBox = data.boxPlacementForms.box;
|
||||||
|
if (data.boxPlacementForms?.row !== undefined)
|
||||||
|
dbData.boxPlacementFormsRow = data.boxPlacementForms.row;
|
||||||
|
if (data.boxPlacementForms?.column !== undefined)
|
||||||
|
dbData.boxPlacementFormsColumn = data.boxPlacementForms.column;
|
||||||
|
if (data.boxPlacement?.box !== undefined) dbData.boxPlacementBox = data.boxPlacement.box;
|
||||||
|
if (data.boxPlacement?.row !== undefined) dbData.boxPlacementRow = data.boxPlacement.row;
|
||||||
|
if (data.boxPlacement?.column !== undefined)
|
||||||
|
dbData.boxPlacementColumn = data.boxPlacement.column;
|
||||||
|
|
||||||
|
const { data: result, error } = await this.supabase
|
||||||
|
.from('pokedex_entries')
|
||||||
|
.insert(dbData)
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !result) throw new Error('Failed to create pokedex entry');
|
||||||
|
return this.transformPokedexEntry(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: Partial<PokedexEntry>): Promise<PokedexEntry | null> {
|
async update(id: string, data: Partial<PokedexEntry>): Promise<PokedexEntry | null> {
|
||||||
return PokedexEntryModel.findByIdAndUpdate(id, data, { new: true }).exec();
|
// Transform to database format (minimal transformation needed)
|
||||||
|
const dbData: Partial<PokedexEntryDB> = {};
|
||||||
|
if (data.pokedexNumber !== undefined) dbData.pokedexNumber = data.pokedexNumber;
|
||||||
|
if (data.pokemon !== undefined) dbData.pokemon = data.pokemon;
|
||||||
|
if (data.form !== undefined) dbData.form = data.form;
|
||||||
|
if (data.canGigantamax !== undefined) dbData.canGigantamax = data.canGigantamax;
|
||||||
|
if (data.regionToCatchIn !== undefined) dbData.regionToCatchIn = data.regionToCatchIn;
|
||||||
|
if (data.gamesToCatchIn !== undefined) dbData.gamesToCatchIn = data.gamesToCatchIn;
|
||||||
|
if (data.regionToEvolveIn !== undefined) dbData.regionToEvolveIn = data.regionToEvolveIn;
|
||||||
|
if (data.evolutionInformation !== undefined)
|
||||||
|
dbData.evolutionInformation = data.evolutionInformation;
|
||||||
|
if (data.catchInformation !== undefined) dbData.catchInformation = data.catchInformation;
|
||||||
|
if (data.boxPlacementForms?.box !== undefined)
|
||||||
|
dbData.boxPlacementFormsBox = data.boxPlacementForms.box;
|
||||||
|
if (data.boxPlacementForms?.row !== undefined)
|
||||||
|
dbData.boxPlacementFormsRow = data.boxPlacementForms.row;
|
||||||
|
if (data.boxPlacementForms?.column !== undefined)
|
||||||
|
dbData.boxPlacementFormsColumn = data.boxPlacementForms.column;
|
||||||
|
if (data.boxPlacement?.box !== undefined) dbData.boxPlacementBox = data.boxPlacement.box;
|
||||||
|
if (data.boxPlacement?.row !== undefined) dbData.boxPlacementRow = data.boxPlacement.row;
|
||||||
|
if (data.boxPlacement?.column !== undefined)
|
||||||
|
dbData.boxPlacementColumn = data.boxPlacement.column;
|
||||||
|
|
||||||
|
const { data: result, error } = await this.supabase
|
||||||
|
.from('pokedex_entries')
|
||||||
|
.update(dbData)
|
||||||
|
.eq('id', id)
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error || !result) return null;
|
||||||
|
return this.transformPokedexEntry(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id: string): Promise<void> {
|
async delete(id: string): Promise<void> {
|
||||||
await PokedexEntryModel.findByIdAndDelete(id).exec();
|
await this.supabase.from('pokedex_entries').delete().eq('id', id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { getEnv } from '$lib/utils/env';
|
|
||||||
const env = getEnv();
|
|
||||||
|
|
||||||
/*
|
|
||||||
0 - disconnected
|
|
||||||
1 - connected
|
|
||||||
2 - connecting
|
|
||||||
3 - disconnecting
|
|
||||||
4 - uninitialized
|
|
||||||
*/
|
|
||||||
let mongoConnectionState = 0;
|
|
||||||
|
|
||||||
export const dbConnect = async () => {
|
|
||||||
if (mongoConnectionState === 1) {
|
|
||||||
console.log('Connection already established');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mongoose.connections.length > 0) {
|
|
||||||
mongoConnectionState = mongoose.connections[0].readyState;
|
|
||||||
if (mongoConnectionState === 1) {
|
|
||||||
console.log('Using existing connection');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await mongoose.connect(env.MONGO_URL, {
|
|
||||||
serverApi: { version: '1', strict: true, deprecationErrors: true }
|
|
||||||
});
|
|
||||||
await mongoose.connection.db.admin().command({ ping: 1 });
|
|
||||||
console.log('Pinged your deployment. You successfully connected to MongoDB!');
|
|
||||||
mongoConnectionState = 1;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error connecting to MongoDB:', error);
|
|
||||||
mongoConnectionState = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const dbDisconnect = async () => {
|
|
||||||
if (process.env.NODE_ENV === 'development') return;
|
|
||||||
if (mongoConnectionState === 0) return;
|
|
||||||
|
|
||||||
await mongoose.disconnect();
|
|
||||||
mongoConnectionState = 0;
|
|
||||||
console.log('disconnected from mongodb');
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
export function getEnv() {
|
export function getEnv() {
|
||||||
return process.env.hasOwnProperty('MONGO_URL')
|
return process.env;
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
MONGO_URL: import.meta.env.VITE_MONGO_URL
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -20,7 +20,11 @@ self.addEventListener('message', (event) => {
|
|||||||
precache([{ url: '/', revision: null }]);
|
precache([{ url: '/', revision: null }]);
|
||||||
|
|
||||||
// self.__WB_MANIFEST is default injection point
|
// self.__WB_MANIFEST is default injection point
|
||||||
precacheAndRoute(self.__WB_MANIFEST);
|
// Handle the case where __WB_MANIFEST might be undefined in development
|
||||||
|
const manifest = self.__WB_MANIFEST || [];
|
||||||
|
if (Array.isArray(manifest)) {
|
||||||
|
precacheAndRoute(manifest);
|
||||||
|
}
|
||||||
|
|
||||||
// clean old assets
|
// clean old assets
|
||||||
cleanupOutdatedCaches();
|
cleanupOutdatedCaches();
|
||||||
|
|||||||
@@ -1,54 +1,61 @@
|
|||||||
import { json, error } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
|
||||||
import { type CatchRecord } from '$lib/models/CatchRecord';
|
import { type CatchRecord } from '$lib/models/CatchRecord';
|
||||||
import CatchRecordRepository from '$lib/repositories/CatchRecordRepository';
|
import CatchRecordRepository from '$lib/repositories/CatchRecordRepository';
|
||||||
import { requireAuth } from '$lib/utils/auth';
|
import { requireAuth } from '$lib/utils/auth';
|
||||||
import type { RequestEvent } from '@sveltejs/kit';
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const GET = async (event: RequestEvent) => {
|
export const GET = async (event: RequestEvent) => {
|
||||||
let catchData = null as CatchRecord[] | null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = await requireAuth(event);
|
const userId = await requireAuth(event);
|
||||||
await dbConnect();
|
|
||||||
const repo = new CatchRecordRepository();
|
// Get the user's session and set it on the Supabase client
|
||||||
catchData = await repo.findByUserId(userId);
|
const { session } = await event.locals.safeGetSession();
|
||||||
|
if (session) {
|
||||||
|
await event.locals.supabase.auth.setSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = new CatchRecordRepository(event.locals.supabase, userId);
|
||||||
|
const catchData = await repo.findByUserId(userId);
|
||||||
// order by pokedexEntryId property, ascending
|
// order by pokedexEntryId property, ascending
|
||||||
catchData = catchData.sort((a, b) => a.pokedexEntryId - b.pokedexEntryId);
|
const sortedData = catchData.sort(
|
||||||
} catch (error) {
|
(a, b) => Number(a.pokedexEntryId) - Number(b.pokedexEntryId)
|
||||||
console.error(error);
|
);
|
||||||
if (error.status) {
|
return json(sortedData);
|
||||||
// Re-throw SvelteKit errors (like 401)
|
} catch (err) {
|
||||||
throw error;
|
console.error(err);
|
||||||
|
if (err && typeof err === 'object' && 'status' in err) {
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
return json({ error: 'Internal Server Error' }, { status: 500 });
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
} finally {
|
|
||||||
dbDisconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return json(catchData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PUT = async (event: RequestEvent) => {
|
export const PUT = async (event: RequestEvent) => {
|
||||||
try {
|
try {
|
||||||
|
// Check if we can get a session first
|
||||||
|
const { session, user } = await event.locals.safeGetSession();
|
||||||
|
|
||||||
const userId = await requireAuth(event);
|
const userId = await requireAuth(event);
|
||||||
|
|
||||||
const data: Partial<CatchRecord> = await event.request.json();
|
const data: Partial<CatchRecord> = await event.request.json();
|
||||||
|
|
||||||
|
// Get the user's session and set it on the Supabase client
|
||||||
|
if (session) {
|
||||||
|
await event.locals.supabase.auth.setSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the userId is set to the authenticated user
|
// Ensure the userId is set to the authenticated user
|
||||||
data.userId = userId;
|
data.userId = userId;
|
||||||
|
|
||||||
await dbConnect();
|
const repo = new CatchRecordRepository(event.locals.supabase, userId);
|
||||||
const repo = new CatchRecordRepository();
|
|
||||||
const upsertedRecord = await repo.upsert(data);
|
const upsertedRecord = await repo.upsert(data);
|
||||||
return json(upsertedRecord);
|
return json(upsertedRecord);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.status) {
|
if (err && typeof err === 'object' && 'status' in err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return json({ error: 'Internal Server Error' }, { status: 500 });
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
} finally {
|
|
||||||
await dbDisconnect();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,8 +63,14 @@ export const POST = async (event: RequestEvent) => {
|
|||||||
try {
|
try {
|
||||||
const userId = await requireAuth(event);
|
const userId = await requireAuth(event);
|
||||||
const records: Partial<CatchRecord>[] = await event.request.json();
|
const records: Partial<CatchRecord>[] = await event.request.json();
|
||||||
await dbConnect();
|
|
||||||
const repo = new CatchRecordRepository();
|
// Get the user's session and set it on the Supabase client
|
||||||
|
const { session } = await event.locals.safeGetSession();
|
||||||
|
if (session) {
|
||||||
|
await event.locals.supabase.auth.setSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = new CatchRecordRepository(event.locals.supabase, userId);
|
||||||
|
|
||||||
const insertedRecords = [];
|
const insertedRecords = [];
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
@@ -70,11 +83,9 @@ export const POST = async (event: RequestEvent) => {
|
|||||||
return json(insertedRecords);
|
return json(insertedRecords);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.status) {
|
if (err && typeof err === 'object' && 'status' in err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return json({ error: 'Internal Server Error' }, { status: 500 });
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
} finally {
|
|
||||||
await dbDisconnect();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
|
||||||
import CombinedDataRepository from '$lib/repositories/CombinedDataRepository';
|
import CombinedDataRepository from '$lib/repositories/CombinedDataRepository';
|
||||||
import { requireAuth } from '$lib/utils/auth';
|
import { getOptionalUserId } from '$lib/utils/auth';
|
||||||
import type { RequestEvent } from '@sveltejs/kit';
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const GET = async (event: RequestEvent) => {
|
export const GET = async (event: RequestEvent) => {
|
||||||
@@ -9,31 +8,45 @@ export const GET = async (event: RequestEvent) => {
|
|||||||
const page = parseInt(url.searchParams.get('page') || '1', 10);
|
const page = parseInt(url.searchParams.get('page') || '1', 10);
|
||||||
const limit = parseInt(url.searchParams.get('limit') || '20', 10);
|
const limit = parseInt(url.searchParams.get('limit') || '20', 10);
|
||||||
const enableForms = url.searchParams.get('enableForms') === 'true';
|
const enableForms = url.searchParams.get('enableForms') === 'true';
|
||||||
const region = url.searchParams.get('region');
|
const region = url.searchParams.get('region') || '';
|
||||||
const game = url.searchParams.get('game');
|
const game = url.searchParams.get('game') || '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = await requireAuth(event);
|
// Get userId if authenticated, null if not
|
||||||
await dbConnect();
|
const userId = await getOptionalUserId(event);
|
||||||
const repo = new CombinedDataRepository();
|
|
||||||
const combinedData = await repo.findCombinedData(userId, page, limit, enableForms, region, game);
|
// If user is authenticated, set their session on the Supabase client
|
||||||
|
if (userId) {
|
||||||
|
const { session } = await event.locals.safeGetSession();
|
||||||
|
if (session) {
|
||||||
|
await event.locals.supabase.auth.setSession(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = new CombinedDataRepository(event.locals.supabase, userId || '');
|
||||||
|
const combinedData = await repo.findCombinedData(
|
||||||
|
userId || '',
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
enableForms,
|
||||||
|
region,
|
||||||
|
game
|
||||||
|
);
|
||||||
|
|
||||||
// Return empty array instead of 404 for better UX
|
// Return empty array instead of 404 for better UX
|
||||||
if (combinedData.length === 0) {
|
if (combinedData.length === 0) {
|
||||||
return json({ combinedData: [], totalPages: 0 });
|
return json({ combinedData: [], totalPages: 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalCount = await repo.countCombinedData(userId, enableForms, region, game);
|
const totalCount = await repo.countCombinedData(enableForms, region, game);
|
||||||
const totalPages = Math.ceil(totalCount / limit);
|
const totalPages = Math.ceil(totalCount / limit);
|
||||||
|
|
||||||
return json({ combinedData, totalPages });
|
return json({ combinedData, totalPages });
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error(error);
|
console.error(err);
|
||||||
if (error.status) {
|
if (err && typeof err === 'object' && 'status' in err) {
|
||||||
throw error;
|
throw err;
|
||||||
}
|
}
|
||||||
return json({ error: 'Internal Server Error' }, { status: 500 });
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
} finally {
|
|
||||||
dbDisconnect();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +1,36 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
|
||||||
import CombinedDataRepository from '$lib/repositories/CombinedDataRepository';
|
import CombinedDataRepository from '$lib/repositories/CombinedDataRepository';
|
||||||
import { requireAuth } from '$lib/utils/auth';
|
import { getOptionalUserId } from '$lib/utils/auth';
|
||||||
import type { RequestEvent } from '@sveltejs/kit';
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const GET = async (event: RequestEvent) => {
|
export const GET = async (event: RequestEvent) => {
|
||||||
const { url } = event;
|
const { url } = event;
|
||||||
const enableForms = url.searchParams.get('enableForms') === 'true';
|
const enableForms = url.searchParams.get('enableForms') === 'true';
|
||||||
const region = url.searchParams.get('region');
|
const region = url.searchParams.get('region') || '';
|
||||||
const game = url.searchParams.get('game');
|
const game = url.searchParams.get('game') || '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = await requireAuth(event);
|
// Get userId if authenticated, null if not
|
||||||
await dbConnect();
|
const userId = await getOptionalUserId(event);
|
||||||
const repo = new CombinedDataRepository();
|
|
||||||
const combinedData = await repo.findAllCombinedData(userId, enableForms, region, game);
|
// If user is authenticated, set their session on the Supabase client
|
||||||
|
if (userId) {
|
||||||
|
const { session } = await event.locals.safeGetSession();
|
||||||
|
if (session) {
|
||||||
|
await event.locals.supabase.auth.setSession(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = new CombinedDataRepository(event.locals.supabase, userId || '');
|
||||||
|
const combinedData = await repo.findAllCombinedData(userId || '', enableForms, region, game);
|
||||||
|
|
||||||
// Return empty array instead of 404 for better UX
|
// Return empty array instead of 404 for better UX
|
||||||
return json(combinedData);
|
return json(combinedData);
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error(error);
|
console.error(err);
|
||||||
if (error.status) {
|
if (err && typeof err === 'object' && 'status' in err) {
|
||||||
throw error;
|
throw err;
|
||||||
}
|
}
|
||||||
return json({ error: 'Internal Server Error' }, { status: 500 });
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
} finally {
|
|
||||||
dbDisconnect();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
|
||||||
import PokedexMetadataModel from '$lib/models/PokedexMetadata';
|
|
||||||
|
|
||||||
export const GET = async () => {
|
|
||||||
await dbConnect();
|
|
||||||
|
|
||||||
const metadata = await PokedexMetadataModel.findOne();
|
|
||||||
await dbDisconnect();
|
|
||||||
|
|
||||||
if (metadata) {
|
|
||||||
return json({ lastModified: metadata.lastModified });
|
|
||||||
} else {
|
|
||||||
return json({ message: 'Metadata not found' }, { status: 404 });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,26 +1,14 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
|
||||||
import { type PokedexEntry } from '$lib/models/PokedexEntry';
|
|
||||||
import PokedexEntryRepository from '$lib/repositories/PokedexEntryRepository';
|
import PokedexEntryRepository from '$lib/repositories/PokedexEntryRepository';
|
||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
export const GET = async () => {
|
export const GET: RequestHandler = async (event) => {
|
||||||
return json(await fetchPokeDexEntriesFromDatabase());
|
|
||||||
};
|
|
||||||
|
|
||||||
async function fetchPokeDexEntriesFromDatabase() {
|
|
||||||
let pokemonData = null as PokedexEntry[] | null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await dbConnect();
|
const repo = new PokedexEntryRepository(event.locals.supabase);
|
||||||
const repo = new PokedexEntryRepository();
|
const pokemonData = await repo.findAll();
|
||||||
pokemonData = await repo.findAll();
|
return json(pokemonData);
|
||||||
// order by pokedexNumber property, ascending
|
|
||||||
pokemonData = pokemonData.sort((a, b) => a.pokedexNumber - b.pokedexNumber);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error('Error fetching pokedex entries:', error);
|
||||||
} finally {
|
return json({ error: 'Failed to fetch pokedex entries' }, { status: 500 });
|
||||||
dbDisconnect();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return pokemonData;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,49 +1,98 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import PokedexEntryModel from '$lib/models/PokedexEntry';
|
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public';
|
||||||
import PokedexEntryRepository from '$lib/repositories/PokedexEntryRepository';
|
|
||||||
import RegionGameMapping from '$lib/models/RegionGameMapping';
|
|
||||||
import RegionGameMappingRepository from '$lib/repositories/RegionGameMappingRepository';
|
|
||||||
import PokedexMetadataModel from '$lib/models/PokedexMetadata';
|
|
||||||
import dex from '$lib/helpers/pokedex.json';
|
import dex from '$lib/helpers/pokedex.json';
|
||||||
import RegionGameMappingJson from '$lib/helpers/region-game-mapping.json';
|
import RegionGameMappingJson from '$lib/helpers/region-game-mapping.json';
|
||||||
|
|
||||||
// Function to update the lastModified field in the metadata collection
|
export const GET = async () => {
|
||||||
const updateLastModified = async () => {
|
// Only allow seeding in development
|
||||||
const metadata = await PokedexMetadataModel.findOne();
|
if (process.env.NODE_ENV === 'production') {
|
||||||
if (metadata) {
|
return json({ message: 'Seeding not allowed in production' }, { status: 403 });
|
||||||
metadata.lastModified = new Date();
|
}
|
||||||
await metadata.save();
|
|
||||||
} else {
|
const supabase = createClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY);
|
||||||
await PokedexMetadataModel.create({ lastModified: new Date() });
|
|
||||||
|
try {
|
||||||
|
// Seed Pokédex entries
|
||||||
|
const { data: existingEntries, error: countError } = await supabase
|
||||||
|
.from('pokedex_entries')
|
||||||
|
.select('id', { count: 'exact', head: true });
|
||||||
|
|
||||||
|
if (countError) {
|
||||||
|
throw new Error(`Failed to check existing entries: ${countError.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only seed if table is empty
|
||||||
|
if (!existingEntries || existingEntries.length === 0) {
|
||||||
|
console.log('Seeding Pokédex entries...');
|
||||||
|
|
||||||
|
// Transform data to match database schema
|
||||||
|
const pokemonData = dex.map((pokemon: any) => ({
|
||||||
|
pokedexNumber: pokemon.pokedexNumber,
|
||||||
|
pokemon: pokemon.pokemon,
|
||||||
|
form: pokemon.form || null,
|
||||||
|
canGigantamax: pokemon.canGigantamax || false,
|
||||||
|
regionToCatchIn: pokemon.regionToCatchIn || null,
|
||||||
|
gamesToCatchIn: pokemon.gamesToCatchIn || null,
|
||||||
|
regionToEvolveIn: pokemon.regionToEvolveIn || null,
|
||||||
|
evolutionInformation: pokemon.evolutionInformation || null,
|
||||||
|
catchInformation: pokemon.catchInformation || null,
|
||||||
|
boxPlacementFormsBox: pokemon.boxPlacementForms?.box || null,
|
||||||
|
boxPlacementFormsRow: pokemon.boxPlacementForms?.row || null,
|
||||||
|
boxPlacementFormsColumn: pokemon.boxPlacementForms?.column || null,
|
||||||
|
boxPlacementBox: pokemon.boxPlacement?.box || null,
|
||||||
|
boxPlacementRow: pokemon.boxPlacement?.row || null,
|
||||||
|
boxPlacementColumn: pokemon.boxPlacement?.column || null
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { error: insertError } = await supabase.from('pokedex_entries').insert(pokemonData);
|
||||||
|
|
||||||
|
if (insertError) {
|
||||||
|
throw new Error(`Failed to seed Pokédex entries: ${insertError.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Seeded ${pokemonData.length} Pokédex entries`);
|
||||||
|
} else {
|
||||||
|
console.log('Pokédex entries already exist, skipping seeding');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed region-game mappings (check if table exists first)
|
||||||
|
const { data: existingMappings, error: mappingCountError } = await supabase
|
||||||
|
.from('region_game_mappings')
|
||||||
|
.select('id', { count: 'exact', head: true });
|
||||||
|
|
||||||
|
if (!mappingCountError && (!existingMappings || existingMappings.length === 0)) {
|
||||||
|
console.log('Seeding region-game mappings...');
|
||||||
|
|
||||||
|
const { error: mappingInsertError } = await supabase
|
||||||
|
.from('region_game_mappings')
|
||||||
|
.insert(RegionGameMappingJson);
|
||||||
|
|
||||||
|
if (mappingInsertError) {
|
||||||
|
throw new Error(`Failed to seed region-game mappings: ${mappingInsertError.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Seeded ${RegionGameMappingJson.length} region-game mappings`);
|
||||||
|
} else if (!mappingCountError) {
|
||||||
|
console.log('Region-game mappings already exist, skipping seeding');
|
||||||
|
}
|
||||||
|
|
||||||
|
return json({
|
||||||
|
message: 'Seeding completed successfully',
|
||||||
|
seeded: {
|
||||||
|
pokemonEntries: !existingEntries || existingEntries.length === 0,
|
||||||
|
regionGameMappings:
|
||||||
|
!mappingCountError && (!existingMappings || existingMappings.length === 0)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Seeding failed:', error);
|
||||||
|
return json(
|
||||||
|
{
|
||||||
|
message: 'Seeding failed',
|
||||||
|
error: error instanceof Error ? error.message : 'Unknown error'
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Seed Pokedex data
|
|
||||||
export const GET = async () => {
|
|
||||||
// Immediately return if not in development to prevent seeding extra data
|
|
||||||
return;
|
|
||||||
|
|
||||||
await dbConnect()
|
|
||||||
.then(async () => {
|
|
||||||
// Create pokedex entries
|
|
||||||
const repo = new PokedexEntryRepository();
|
|
||||||
|
|
||||||
dex.forEach(async (pokemon: PokedexEntryModel) => {
|
|
||||||
await repo.create(pokemon);
|
|
||||||
console.log(`Seeded ${pokemon.pokedexNumber} ${pokemon.pokemon} ${pokemon.form}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create region-game mappings
|
|
||||||
const regionGameMappingRepository = new RegionGameMappingRepository();
|
|
||||||
await regionGameMappingRepository.create(RegionGameMappingJson as RegionGameMapping[]);
|
|
||||||
|
|
||||||
// Update the lastModified field after seeding
|
|
||||||
await updateLastModified();
|
|
||||||
})
|
|
||||||
.finally(() => dbDisconnect());
|
|
||||||
|
|
||||||
return json({
|
|
||||||
message: 'seeded'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
import PokedexSidebar from '$lib/components/pokedex/PokedexSidebar.svelte';
|
import PokedexSidebar from '$lib/components/pokedex/PokedexSidebar.svelte';
|
||||||
import PokedexViewList from '$lib/components/pokedex/PokedexViewList.svelte';
|
import PokedexViewList from '$lib/components/pokedex/PokedexViewList.svelte';
|
||||||
import PokedexViewBoxes from '$lib/components/pokedex/PokedexViewBoxes.svelte';
|
import PokedexViewBoxes from '$lib/components/pokedex/PokedexViewBoxes.svelte';
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
|
||||||
|
export let data: PageData;
|
||||||
|
|
||||||
|
$: ({ supabase, session } = data);
|
||||||
|
|
||||||
let combinedData = null as CombinedData[] | null;
|
let combinedData = null as CombinedData[] | null;
|
||||||
let currentPage = 1 as number;
|
let currentPage = 1 as number;
|
||||||
@@ -25,7 +30,7 @@
|
|||||||
let drawerOpen = false;
|
let drawerOpen = false;
|
||||||
let viewAsBoxes = false;
|
let viewAsBoxes = false;
|
||||||
let currentPlacement = 'boxPlacementForms';
|
let currentPlacement = 'boxPlacementForms';
|
||||||
let boxNumbers = Array<any>;
|
let boxNumbers: number[] = [];
|
||||||
|
|
||||||
const unsubscribe = user.subscribe((value) => {
|
const unsubscribe = user.subscribe((value) => {
|
||||||
localUser = value;
|
localUser = value;
|
||||||
@@ -86,16 +91,24 @@
|
|||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {
|
||||||
body: JSON.stringify(catchRecord)
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(catchRecord),
|
||||||
|
credentials: 'include' as RequestCredentials
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/catch-records', requestOptions);
|
const response = await fetch('/api/catch-records', requestOptions);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
console.error('Server response:', response.status, errorText);
|
||||||
alert('Failed to update catch record');
|
alert('Failed to update catch record');
|
||||||
throw new Error('Failed to update catch record');
|
throw new Error('Failed to update catch record');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh the data to reflect changes from server
|
||||||
|
await getData(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating catch record:', error);
|
console.error('Error updating catch record:', error);
|
||||||
}
|
}
|
||||||
@@ -109,8 +122,20 @@
|
|||||||
) {
|
) {
|
||||||
let catchRecordsToUpdate = combinedData
|
let catchRecordsToUpdate = combinedData
|
||||||
.filter(({ pokedexEntry }) => pokedexEntry[currentPlacement].box === boxNumber)
|
.filter(({ pokedexEntry }) => pokedexEntry[currentPlacement].box === boxNumber)
|
||||||
.map(({ catchRecord }) => {
|
.map(({ pokedexEntry, catchRecord }) => {
|
||||||
let updatedRecord = { ...catchRecord };
|
// Create default record if null
|
||||||
|
const baseRecord = catchRecord || {
|
||||||
|
_id: '',
|
||||||
|
userId: localUser?.id || '',
|
||||||
|
pokedexEntryId: pokedexEntry._id,
|
||||||
|
haveToEvolve: false,
|
||||||
|
caught: false,
|
||||||
|
inHome: false,
|
||||||
|
hasGigantamaxed: false,
|
||||||
|
personalNotes: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
let updatedRecord = { ...baseRecord };
|
||||||
if (inHome !== null) {
|
if (inHome !== null) {
|
||||||
updatedRecord = {
|
updatedRecord = {
|
||||||
...updatedRecord,
|
...updatedRecord,
|
||||||
@@ -203,13 +228,11 @@
|
|||||||
|
|
||||||
const createdRecords = await response.json();
|
const createdRecords = await response.json();
|
||||||
totalRecordsCreated += createdRecords.length;
|
totalRecordsCreated += createdRecords.length;
|
||||||
console.log(`Created ${createdRecords.length} catch records`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating catch records:', error);
|
console.error('Error creating catch records:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Created catch records for each pokedex entry');
|
|
||||||
creatingRecords = false;
|
creatingRecords = false;
|
||||||
failedToLoad = false;
|
failedToLoad = false;
|
||||||
await getData();
|
await getData();
|
||||||
@@ -269,6 +292,7 @@
|
|||||||
bind:creatingRecords
|
bind:creatingRecords
|
||||||
bind:totalRecordsCreated
|
bind:totalRecordsCreated
|
||||||
bind:failedToLoad
|
bind:failedToLoad
|
||||||
|
userId={localUser?.id}
|
||||||
{updateACatch}
|
{updateACatch}
|
||||||
{createCatchRecords}
|
{createCatchRecords}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export const load = async ({ parent }) => {
|
||||||
|
const { supabase, session } = await parent();
|
||||||
|
return {
|
||||||
|
supabase,
|
||||||
|
session
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -16,18 +16,22 @@
|
|||||||
onDestroy(unsubscribe);
|
onDestroy(unsubscribe);
|
||||||
|
|
||||||
async function getUser() {
|
async function getUser() {
|
||||||
const {
|
try {
|
||||||
data: { session }
|
const {
|
||||||
} = await supabase.auth.getSession();
|
data: { session }
|
||||||
|
} = await supabase.auth.getSession();
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
localUser = session.user;
|
localUser = session.user;
|
||||||
} else {
|
user.set(localUser);
|
||||||
localUser = null;
|
await goto('/mydex', { replace: true });
|
||||||
|
} else {
|
||||||
|
localUser = null;
|
||||||
|
user.set(localUser);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting user session:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.set(localUser);
|
|
||||||
goto('/mydex', { replace: true });
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Supabase
|
||||||
|
.branches
|
||||||
|
.temp
|
||||||
|
|
||||||
|
# dotenvx
|
||||||
|
.env.keys
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
@@ -0,0 +1,332 @@
|
|||||||
|
# For detailed configuration reference documentation, visit:
|
||||||
|
# https://supabase.com/docs/guides/local-development/cli/config
|
||||||
|
# A string used to distinguish different Supabase projects on the same host. Defaults to the
|
||||||
|
# working directory name when running `supabase init`.
|
||||||
|
project_id = "LivingDexTracker"
|
||||||
|
|
||||||
|
[api]
|
||||||
|
enabled = true
|
||||||
|
# Port to use for the API URL.
|
||||||
|
port = 54321
|
||||||
|
# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API
|
||||||
|
# endpoints. `public` and `graphql_public` schemas are included by default.
|
||||||
|
schemas = ["public", "graphql_public"]
|
||||||
|
# Extra schemas to add to the search_path of every request.
|
||||||
|
extra_search_path = ["public", "extensions"]
|
||||||
|
# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size
|
||||||
|
# for accidental or malicious requests.
|
||||||
|
max_rows = 1000
|
||||||
|
|
||||||
|
[api.tls]
|
||||||
|
# Enable HTTPS endpoints locally using a self-signed certificate.
|
||||||
|
enabled = false
|
||||||
|
|
||||||
|
[db]
|
||||||
|
# Port to use for the local database URL.
|
||||||
|
port = 54322
|
||||||
|
# Port used by db diff command to initialize the shadow database.
|
||||||
|
shadow_port = 54320
|
||||||
|
# The database major version to use. This has to be the same as your remote database's. Run `SHOW
|
||||||
|
# server_version;` on the remote database to check.
|
||||||
|
major_version = 17
|
||||||
|
|
||||||
|
[db.pooler]
|
||||||
|
enabled = false
|
||||||
|
# Port to use for the local connection pooler.
|
||||||
|
port = 54329
|
||||||
|
# Specifies when a server connection can be reused by other clients.
|
||||||
|
# Configure one of the supported pooler modes: `transaction`, `session`.
|
||||||
|
pool_mode = "transaction"
|
||||||
|
# How many server connections to allow per user/database pair.
|
||||||
|
default_pool_size = 20
|
||||||
|
# Maximum number of client connections allowed.
|
||||||
|
max_client_conn = 100
|
||||||
|
|
||||||
|
# [db.vault]
|
||||||
|
# secret_key = "env(SECRET_VALUE)"
|
||||||
|
|
||||||
|
[db.migrations]
|
||||||
|
# If disabled, migrations will be skipped during a db push or reset.
|
||||||
|
enabled = true
|
||||||
|
# Specifies an ordered list of schema files that describe your database.
|
||||||
|
# Supports glob patterns relative to supabase directory: "./schemas/*.sql"
|
||||||
|
schema_paths = []
|
||||||
|
|
||||||
|
[db.seed]
|
||||||
|
# If enabled, seeds the database after migrations during a db reset.
|
||||||
|
enabled = true
|
||||||
|
# Specifies an ordered list of seed files to load during db reset.
|
||||||
|
# Supports glob patterns relative to supabase directory: "./seeds/*.sql"
|
||||||
|
sql_paths = []
|
||||||
|
|
||||||
|
[db.network_restrictions]
|
||||||
|
# Enable management of network restrictions.
|
||||||
|
enabled = false
|
||||||
|
# List of IPv4 CIDR blocks allowed to connect to the database.
|
||||||
|
# Defaults to allow all IPv4 connections. Set empty array to block all IPs.
|
||||||
|
allowed_cidrs = ["0.0.0.0/0"]
|
||||||
|
# List of IPv6 CIDR blocks allowed to connect to the database.
|
||||||
|
# Defaults to allow all IPv6 connections. Set empty array to block all IPs.
|
||||||
|
allowed_cidrs_v6 = ["::/0"]
|
||||||
|
|
||||||
|
[realtime]
|
||||||
|
enabled = true
|
||||||
|
# Bind realtime via either IPv4 or IPv6. (default: IPv4)
|
||||||
|
# ip_version = "IPv6"
|
||||||
|
# The maximum length in bytes of HTTP request headers. (default: 4096)
|
||||||
|
# max_header_length = 4096
|
||||||
|
|
||||||
|
[studio]
|
||||||
|
enabled = true
|
||||||
|
# Port to use for Supabase Studio.
|
||||||
|
port = 54323
|
||||||
|
# External URL of the API server that frontend connects to.
|
||||||
|
api_url = "http://127.0.0.1"
|
||||||
|
# OpenAI API Key to use for Supabase AI in the Supabase Studio.
|
||||||
|
openai_api_key = "env(OPENAI_API_KEY)"
|
||||||
|
|
||||||
|
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
|
||||||
|
# are monitored, and you can view the emails that would have been sent from the web interface.
|
||||||
|
[inbucket]
|
||||||
|
enabled = true
|
||||||
|
# Port to use for the email testing server web interface.
|
||||||
|
port = 54324
|
||||||
|
# Uncomment to expose additional ports for testing user applications that send emails.
|
||||||
|
# smtp_port = 54325
|
||||||
|
# pop3_port = 54326
|
||||||
|
# admin_email = "admin@email.com"
|
||||||
|
# sender_name = "Admin"
|
||||||
|
|
||||||
|
[storage]
|
||||||
|
enabled = true
|
||||||
|
# The maximum file size allowed (e.g. "5MB", "500KB").
|
||||||
|
file_size_limit = "50MiB"
|
||||||
|
|
||||||
|
# Image transformation API is available to Supabase Pro plan.
|
||||||
|
# [storage.image_transformation]
|
||||||
|
# enabled = true
|
||||||
|
|
||||||
|
# Uncomment to configure local storage buckets
|
||||||
|
# [storage.buckets.images]
|
||||||
|
# public = false
|
||||||
|
# file_size_limit = "50MiB"
|
||||||
|
# allowed_mime_types = ["image/png", "image/jpeg"]
|
||||||
|
# objects_path = "./images"
|
||||||
|
|
||||||
|
[auth]
|
||||||
|
enabled = true
|
||||||
|
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
|
||||||
|
# in emails.
|
||||||
|
site_url = "http://127.0.0.1:3000"
|
||||||
|
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
|
||||||
|
additional_redirect_urls = ["http://127.0.0.1:3000"]
|
||||||
|
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
|
||||||
|
jwt_expiry = 3600
|
||||||
|
# If disabled, the refresh token will never expire.
|
||||||
|
enable_refresh_token_rotation = true
|
||||||
|
# Allows refresh tokens to be reused after expiry, up to the specified interval in seconds.
|
||||||
|
# Requires enable_refresh_token_rotation = true.
|
||||||
|
refresh_token_reuse_interval = 10
|
||||||
|
# Allow/disallow new user signups to your project.
|
||||||
|
enable_signup = true
|
||||||
|
# Allow/disallow anonymous sign-ins to your project.
|
||||||
|
enable_anonymous_sign_ins = false
|
||||||
|
# Allow/disallow testing manual linking of accounts
|
||||||
|
enable_manual_linking = false
|
||||||
|
# Passwords shorter than this value will be rejected as weak. Minimum 6, recommended 8 or more.
|
||||||
|
minimum_password_length = 6
|
||||||
|
# Passwords that do not meet the following requirements will be rejected as weak. Supported values
|
||||||
|
# are: `letters_digits`, `lower_upper_letters_digits`, `lower_upper_letters_digits_symbols`
|
||||||
|
password_requirements = ""
|
||||||
|
|
||||||
|
[auth.rate_limit]
|
||||||
|
# Number of emails that can be sent per hour. Requires auth.email.smtp to be enabled.
|
||||||
|
email_sent = 2
|
||||||
|
# Number of SMS messages that can be sent per hour. Requires auth.sms to be enabled.
|
||||||
|
sms_sent = 30
|
||||||
|
# Number of anonymous sign-ins that can be made per hour per IP address. Requires enable_anonymous_sign_ins = true.
|
||||||
|
anonymous_users = 30
|
||||||
|
# Number of sessions that can be refreshed in a 5 minute interval per IP address.
|
||||||
|
token_refresh = 150
|
||||||
|
# Number of sign up and sign-in requests that can be made in a 5 minute interval per IP address (excludes anonymous users).
|
||||||
|
sign_in_sign_ups = 30
|
||||||
|
# Number of OTP / Magic link verifications that can be made in a 5 minute interval per IP address.
|
||||||
|
token_verifications = 30
|
||||||
|
# Number of Web3 logins that can be made in a 5 minute interval per IP address.
|
||||||
|
web3 = 30
|
||||||
|
|
||||||
|
# Configure one of the supported captcha providers: `hcaptcha`, `turnstile`.
|
||||||
|
# [auth.captcha]
|
||||||
|
# enabled = true
|
||||||
|
# provider = "hcaptcha"
|
||||||
|
# secret = ""
|
||||||
|
|
||||||
|
[auth.email]
|
||||||
|
# Allow/disallow new user signups via email to your project.
|
||||||
|
enable_signup = true
|
||||||
|
# If enabled, a user will be required to confirm any email change on both the old, and new email
|
||||||
|
# addresses. If disabled, only the new email is required to confirm.
|
||||||
|
double_confirm_changes = true
|
||||||
|
# If enabled, users need to confirm their email address before signing in.
|
||||||
|
enable_confirmations = true
|
||||||
|
# If enabled, users will need to reauthenticate or have logged in recently to change their password.
|
||||||
|
secure_password_change = false
|
||||||
|
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
|
||||||
|
max_frequency = "30s"
|
||||||
|
# Number of characters used in the email OTP.
|
||||||
|
otp_length = 6
|
||||||
|
# Number of seconds before the email OTP expires (defaults to 1 hour).
|
||||||
|
otp_expiry = 3600
|
||||||
|
|
||||||
|
# Use a production-ready SMTP server
|
||||||
|
# [auth.email.smtp]
|
||||||
|
# enabled = true
|
||||||
|
# host = "smtp.sendgrid.net"
|
||||||
|
# port = 587
|
||||||
|
# user = "apikey"
|
||||||
|
# pass = "env(SENDGRID_API_KEY)"
|
||||||
|
# admin_email = "admin@email.com"
|
||||||
|
# sender_name = "Admin"
|
||||||
|
|
||||||
|
# Uncomment to customize email template
|
||||||
|
# [auth.email.template.invite]
|
||||||
|
# subject = "You have been invited"
|
||||||
|
# content_path = "./supabase/templates/invite.html"
|
||||||
|
|
||||||
|
[auth.sms]
|
||||||
|
# Allow/disallow new user signups via SMS to your project.
|
||||||
|
enable_signup = false
|
||||||
|
# If enabled, users need to confirm their phone number before signing in.
|
||||||
|
enable_confirmations = false
|
||||||
|
# Template for sending OTP to users
|
||||||
|
template = "Your code is {{ .Code }}"
|
||||||
|
# Controls the minimum amount of time that must pass before sending another sms otp.
|
||||||
|
max_frequency = "5s"
|
||||||
|
|
||||||
|
# Use pre-defined map of phone number to OTP for testing.
|
||||||
|
# [auth.sms.test_otp]
|
||||||
|
# 4152127777 = "123456"
|
||||||
|
|
||||||
|
# Configure logged in session timeouts.
|
||||||
|
# [auth.sessions]
|
||||||
|
# Force log out after the specified duration.
|
||||||
|
# timebox = "24h"
|
||||||
|
# Force log out if the user has been inactive longer than the specified duration.
|
||||||
|
# inactivity_timeout = "8h"
|
||||||
|
|
||||||
|
# This hook runs before a new user is created and allows developers to reject the request based on the incoming user object.
|
||||||
|
# [auth.hook.before_user_created]
|
||||||
|
# enabled = true
|
||||||
|
# uri = "pg-functions://postgres/auth/before-user-created-hook"
|
||||||
|
|
||||||
|
# This hook runs before a token is issued and allows you to add additional claims based on the authentication method used.
|
||||||
|
# [auth.hook.custom_access_token]
|
||||||
|
# enabled = true
|
||||||
|
# uri = "pg-functions://<database>/<schema>/<hook_name>"
|
||||||
|
|
||||||
|
# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`.
|
||||||
|
[auth.sms.twilio]
|
||||||
|
enabled = false
|
||||||
|
account_sid = ""
|
||||||
|
message_service_sid = ""
|
||||||
|
# DO NOT commit your Twilio auth token to git. Use environment variable substitution instead:
|
||||||
|
auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)"
|
||||||
|
|
||||||
|
# Multi-factor-authentication is available to Supabase Pro plan.
|
||||||
|
[auth.mfa]
|
||||||
|
# Control how many MFA factors can be enrolled at once per user.
|
||||||
|
max_enrolled_factors = 10
|
||||||
|
|
||||||
|
# Control MFA via App Authenticator (TOTP)
|
||||||
|
[auth.mfa.totp]
|
||||||
|
enroll_enabled = false
|
||||||
|
verify_enabled = false
|
||||||
|
|
||||||
|
# Configure MFA via Phone Messaging
|
||||||
|
[auth.mfa.phone]
|
||||||
|
enroll_enabled = false
|
||||||
|
verify_enabled = false
|
||||||
|
otp_length = 6
|
||||||
|
template = "Your code is {{ .Code }}"
|
||||||
|
max_frequency = "5s"
|
||||||
|
|
||||||
|
# Configure MFA via WebAuthn
|
||||||
|
# [auth.mfa.web_authn]
|
||||||
|
# enroll_enabled = true
|
||||||
|
# verify_enabled = true
|
||||||
|
|
||||||
|
# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`,
|
||||||
|
# `discord`, `facebook`, `github`, `gitlab`, `google`, `keycloak`, `linkedin_oidc`, `notion`, `twitch`,
|
||||||
|
# `twitter`, `slack`, `spotify`, `workos`, `zoom`.
|
||||||
|
[auth.external.apple]
|
||||||
|
enabled = false
|
||||||
|
client_id = ""
|
||||||
|
# DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead:
|
||||||
|
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
|
||||||
|
# Overrides the default auth redirectUrl.
|
||||||
|
redirect_uri = ""
|
||||||
|
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
|
||||||
|
# or any other third-party OIDC providers.
|
||||||
|
url = ""
|
||||||
|
# If enabled, the nonce check will be skipped. Required for local sign in with Google auth.
|
||||||
|
skip_nonce_check = false
|
||||||
|
|
||||||
|
# Allow Solana wallet holders to sign in to your project via the Sign in with Solana (SIWS, EIP-4361) standard.
|
||||||
|
# You can configure "web3" rate limit in the [auth.rate_limit] section and set up [auth.captcha] if self-hosting.
|
||||||
|
[auth.web3.solana]
|
||||||
|
enabled = false
|
||||||
|
|
||||||
|
# Use Firebase Auth as a third-party provider alongside Supabase Auth.
|
||||||
|
[auth.third_party.firebase]
|
||||||
|
enabled = false
|
||||||
|
# project_id = "my-firebase-project"
|
||||||
|
|
||||||
|
# Use Auth0 as a third-party provider alongside Supabase Auth.
|
||||||
|
[auth.third_party.auth0]
|
||||||
|
enabled = false
|
||||||
|
# tenant = "my-auth0-tenant"
|
||||||
|
# tenant_region = "us"
|
||||||
|
|
||||||
|
# Use AWS Cognito (Amplify) as a third-party provider alongside Supabase Auth.
|
||||||
|
[auth.third_party.aws_cognito]
|
||||||
|
enabled = false
|
||||||
|
# user_pool_id = "my-user-pool-id"
|
||||||
|
# user_pool_region = "us-east-1"
|
||||||
|
|
||||||
|
# Use Clerk as a third-party provider alongside Supabase Auth.
|
||||||
|
[auth.third_party.clerk]
|
||||||
|
enabled = false
|
||||||
|
# Obtain from https://clerk.com/setup/supabase
|
||||||
|
# domain = "example.clerk.accounts.dev"
|
||||||
|
|
||||||
|
[edge_runtime]
|
||||||
|
enabled = true
|
||||||
|
# Configure one of the supported request policies: `oneshot`, `per_worker`.
|
||||||
|
# Use `oneshot` for hot reload, or `per_worker` for load testing.
|
||||||
|
policy = "oneshot"
|
||||||
|
# Port to attach the Chrome inspector for debugging edge functions.
|
||||||
|
inspector_port = 8083
|
||||||
|
# The Deno major version to use.
|
||||||
|
deno_version = 1
|
||||||
|
|
||||||
|
# [edge_runtime.secrets]
|
||||||
|
# secret_key = "env(SECRET_VALUE)"
|
||||||
|
|
||||||
|
[analytics]
|
||||||
|
enabled = true
|
||||||
|
port = 54327
|
||||||
|
# Configure one of the supported backends: `postgres`, `bigquery`.
|
||||||
|
backend = "postgres"
|
||||||
|
|
||||||
|
# Experimental features may be deprecated any time
|
||||||
|
[experimental]
|
||||||
|
# Configures Postgres storage engine to use OrioleDB (S3)
|
||||||
|
orioledb_version = ""
|
||||||
|
# Configures S3 bucket URL, eg. <bucket_name>.s3-<region>.amazonaws.com
|
||||||
|
s3_host = "env(S3_HOST)"
|
||||||
|
# Configures S3 bucket region, eg. us-east-1
|
||||||
|
s3_region = "env(S3_REGION)"
|
||||||
|
# Configures AWS_ACCESS_KEY_ID for S3 bucket
|
||||||
|
s3_access_key = "env(S3_ACCESS_KEY)"
|
||||||
|
# Configures AWS_SECRET_ACCESS_KEY for S3 bucket
|
||||||
|
s3_secret_key = "env(S3_SECRET_KEY)"
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
CREATE TABLE pokedex_entries (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
"pokedexNumber" INTEGER NOT NULL,
|
||||||
|
pokemon TEXT NOT NULL,
|
||||||
|
form TEXT,
|
||||||
|
"canGigantamax" BOOLEAN DEFAULT FALSE,
|
||||||
|
"regionToCatchIn" TEXT,
|
||||||
|
"gamesToCatchIn" TEXT[],
|
||||||
|
"regionToEvolveIn" TEXT,
|
||||||
|
"evolutionInformation" TEXT,
|
||||||
|
"catchInformation" TEXT[],
|
||||||
|
|
||||||
|
-- Box placement for forms view
|
||||||
|
"boxPlacementFormsBox" INTEGER,
|
||||||
|
"boxPlacementFormsRow" INTEGER,
|
||||||
|
"boxPlacementFormsColumn" INTEGER,
|
||||||
|
|
||||||
|
-- Box placement for no-forms view
|
||||||
|
"boxPlacementBox" INTEGER,
|
||||||
|
"boxPlacementRow" INTEGER,
|
||||||
|
"boxPlacementColumn" INTEGER,
|
||||||
|
|
||||||
|
"createdAt" TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
"updatedAt" TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add unique constraint to prevent duplicate pokemon forms
|
||||||
|
ALTER TABLE pokedex_entries ADD CONSTRAINT unique_pokemon_form
|
||||||
|
UNIQUE("pokedexNumber", form);
|
||||||
|
|
||||||
|
CREATE TABLE catch_records (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
"userId" UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
|
||||||
|
"pokedexEntryId" BIGINT NOT NULL REFERENCES pokedex_entries(id) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
-- Catch status fields
|
||||||
|
"haveToEvolve" BOOLEAN DEFAULT FALSE,
|
||||||
|
caught BOOLEAN DEFAULT FALSE,
|
||||||
|
"inHome" BOOLEAN DEFAULT FALSE,
|
||||||
|
"hasGigantamaxed" BOOLEAN DEFAULT FALSE,
|
||||||
|
"personalNotes" TEXT,
|
||||||
|
|
||||||
|
"createdAt" TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
"updatedAt" TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
|
||||||
|
-- Ensure one record per user per pokemon entry
|
||||||
|
UNIQUE("userId", "pokedexEntryId")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE region_game_mappings (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
region TEXT NOT NULL,
|
||||||
|
game TEXT NOT NULL,
|
||||||
|
UNIQUE(region, game)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE metadata (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
key TEXT UNIQUE NOT NULL,
|
||||||
|
value TEXT,
|
||||||
|
"createdAt" TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
"updatedAt" TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create indexes for better performance
|
||||||
|
CREATE INDEX idx_pokedex_entries_pokedex_number ON pokedex_entries("pokedexNumber");
|
||||||
|
CREATE INDEX idx_pokedex_entries_pokemon ON pokedex_entries(pokemon);
|
||||||
|
CREATE INDEX idx_pokedex_entries_box_placement_forms ON pokedex_entries("boxPlacementFormsBox", "boxPlacementFormsRow", "boxPlacementFormsColumn");
|
||||||
|
CREATE INDEX idx_pokedex_entries_box_placement ON pokedex_entries("boxPlacementBox", "boxPlacementRow", "boxPlacementColumn");
|
||||||
|
|
||||||
|
CREATE INDEX idx_catch_records_user_id ON catch_records("userId");
|
||||||
|
CREATE INDEX idx_catch_records_pokedex_entry_id ON catch_records("pokedexEntryId");
|
||||||
|
CREATE INDEX idx_catch_records_caught ON catch_records(caught);
|
||||||
|
CREATE INDEX idx_catch_records_in_home ON catch_records("inHome");
|
||||||
|
CREATE INDEX idx_catch_records_user_caught ON catch_records("userId", caught);
|
||||||
|
|
||||||
|
-- Function to automatically update updated_at timestamp
|
||||||
|
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW."updatedAt" = NOW();
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Create triggers for updated_at
|
||||||
|
CREATE TRIGGER update_pokedex_entries_updated_at
|
||||||
|
BEFORE UPDATE ON pokedex_entries
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||||
|
|
||||||
|
CREATE TRIGGER update_catch_records_updated_at
|
||||||
|
BEFORE UPDATE ON catch_records
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||||
|
|
||||||
|
-- Enable RLS on all tables
|
||||||
|
ALTER TABLE pokedex_entries ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE catch_records ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE region_game_mappings ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE metadata ENABLE ROW LEVEL SECURITY;
|
||||||
|
|
||||||
|
-- RLS policies for pokedex_entries (public read)
|
||||||
|
CREATE POLICY "Anyone can view pokemon entries" ON pokedex_entries
|
||||||
|
FOR SELECT USING (true);
|
||||||
|
|
||||||
|
-- RLS policies for catch_records (user-specific)
|
||||||
|
CREATE POLICY "Users can view own catch records" ON catch_records
|
||||||
|
FOR SELECT USING (auth.uid() = "userId");
|
||||||
|
|
||||||
|
CREATE POLICY "Users can insert own catch records" ON catch_records
|
||||||
|
FOR INSERT WITH CHECK (auth.uid() = "userId");
|
||||||
|
|
||||||
|
CREATE POLICY "Users can update own catch records" ON catch_records
|
||||||
|
FOR UPDATE USING (auth.uid() = "userId");
|
||||||
|
|
||||||
|
CREATE POLICY "Users can delete own catch records" ON catch_records
|
||||||
|
FOR DELETE USING (auth.uid() = "userId");
|
||||||
|
|
||||||
|
-- RLS policies for region_game_mappings (public read)
|
||||||
|
CREATE POLICY "Anyone can view region game mappings" ON region_game_mappings
|
||||||
|
FOR SELECT USING (true);
|
||||||
|
|
||||||
|
-- RLS policies for metadata (public read)
|
||||||
|
CREATE POLICY "Anyone can view metadata" ON metadata
|
||||||
|
FOR SELECT USING (true);
|
||||||
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -17,7 +17,8 @@
|
|||||||
"virtual:pwa-assets"
|
"virtual:pwa-assets"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": ["node_modules/vite-plugin-pwa/client.d.ts", "node_modules/**/*.d.ts"]
|
"include": ["src/**/*.ts", "src/**/*.svelte", "node_modules/vite-plugin-pwa/client.d.ts"],
|
||||||
|
"exclude": [".svelte-kit/**/*", "node_modules/**/*"]
|
||||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||||
//
|
//
|
||||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const csv = require('csv-parser');
|
|
||||||
|
|
||||||
const inputFilePath = 'seed-data.tsv'; // Replace with the path to your TSV file
|
|
||||||
const outputFilePath = 'pokedex.json';
|
|
||||||
|
|
||||||
const results = [];
|
|
||||||
|
|
||||||
fs.createReadStream(inputFilePath)
|
|
||||||
.pipe(csv({ separator: '\t' }))
|
|
||||||
.on('data', (data) => {
|
|
||||||
const entry = {
|
|
||||||
pokedexNumber: parseInt(data['Dex #']),
|
|
||||||
boxPlacement: {
|
|
||||||
box: parseInt(data['No Form Box']),
|
|
||||||
row: parseInt(data['No Form Row']),
|
|
||||||
column: parseInt(data['No Form Column'])
|
|
||||||
},
|
|
||||||
boxPlacementForms: {
|
|
||||||
box: parseInt(data['Home Box']),
|
|
||||||
row: parseInt(data['Home Row']),
|
|
||||||
column: parseInt(data['Home Column'])
|
|
||||||
},
|
|
||||||
pokemon: data['Pokemon'],
|
|
||||||
form: data['Form'],
|
|
||||||
canGigantamax: data['Can Gigantamax'].toLowerCase(),
|
|
||||||
regionToCatchIn: data['Region'],
|
|
||||||
gamesToCatchIn: data['Catch In These Games'].split(',').map((game) => game.trim()),
|
|
||||||
regionToEvolveIn: data['Evolve In Region'],
|
|
||||||
evolutionInformation: data['Evolution Info'],
|
|
||||||
catchInformation: []
|
|
||||||
};
|
|
||||||
results.push(entry);
|
|
||||||
})
|
|
||||||
.on('end', () => {
|
|
||||||
fs.writeFile(outputFilePath, JSON.stringify(results, null, 2), (err) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('Error writing to JSON file', err);
|
|
||||||
} else {
|
|
||||||
console.log('JSON file has been successfully created');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Generated
-47
@@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "tsv-parser",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {
|
|
||||||
"": {
|
|
||||||
"name": "tsv-parser",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"csv-parser": "^3.0.0",
|
|
||||||
"fs": "^0.0.1-security"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/csv-parser": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/csv-parser/-/csv-parser-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"minimist": "^1.2.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"csv-parser": "bin/csv-parser"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/fs": {
|
|
||||||
"version": "0.0.1-security",
|
|
||||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
|
||||||
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==",
|
|
||||||
"license": "ISC"
|
|
||||||
},
|
|
||||||
"node_modules/minimist": {
|
|
||||||
"version": "1.2.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
|
||||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "tsv-parser",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"description": "",
|
|
||||||
"dependencies": {
|
|
||||||
"csv-parser": "^3.0.0",
|
|
||||||
"fs": "^0.0.1-security"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-35491
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user