diff --git a/package-lock.json b/package-lock.json index 0dacd87a4..ea1ebe086 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "client": { "name": "@trek/client", "version": "4.2.0", + "hasInstallScript": true, "dependencies": { "@fontsource/bebas-neue": "^5.3.0", "@fontsource/eb-garamond": "^5.3.0", @@ -99,8 +100,7 @@ "vite": "8.1.0", "vite-plugin-pwa": "^1.3.0", "vitest": "^4.1.11" - }, - "hasInstallScript": true + } }, "client/node_modules/cookie": { "version": "1.1.1", @@ -2544,6 +2544,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2560,6 +2561,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2576,6 +2578,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2592,6 +2595,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2608,6 +2612,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2624,6 +2629,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2640,6 +2646,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2656,6 +2663,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2672,6 +2680,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2688,6 +2697,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2704,6 +2714,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2720,6 +2731,7 @@ "cpu": [ "loong64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2736,6 +2748,7 @@ "cpu": [ "mips64el" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2752,6 +2765,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2768,6 +2782,7 @@ "cpu": [ "riscv64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2784,6 +2799,7 @@ "cpu": [ "s390x" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2800,6 +2816,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2816,6 +2833,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2832,6 +2850,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2848,6 +2867,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2864,6 +2884,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2880,6 +2901,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2896,6 +2918,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2912,6 +2935,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2928,6 +2952,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -2944,6 +2969,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4887,6 +4913,125 @@ "integrity": "sha512-xgAyonlVVS+q7Vc7qLW0UrJU7rSFcETRWsqdXZtjzRU8dF+6CkozTK4V4y1LwOX7j8r/vHphjDeMeGI4tNGeGA==", "license": "MIT" }, + "node_modules/@mikro-orm/core": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@mikro-orm/core/-/core-7.2.1.tgz", + "integrity": "sha512-+gtJoScbin/C3wPItSZkj5vlMTq/LphBLIxHyi5brCbeA6VDcYuoMopiqoFUMQxdhXXrZlKNIHXGrhb8r3biVg==", + "license": "MIT", + "engines": { + "node": ">= 22.17.0" + }, + "funding": { + "url": "https://github.com/sponsors/b4nan" + }, + "peerDependencies": { + "dataloader": "2.2.3" + }, + "peerDependenciesMeta": { + "dataloader": { + "optional": true + } + } + }, + "node_modules/@mikro-orm/entity-generator": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@mikro-orm/entity-generator/-/entity-generator-7.2.1.tgz", + "integrity": "sha512-SMzqZ9VsIAbbO4x4IEWgMmMoujKcUxJQMIFKbOPard0D+eNpy4wiTKnP44nLHLPJ8CtDqUPh7W9eC9K9JW3C9w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@mikro-orm/sql": "7.2.1" + }, + "engines": { + "node": ">= 22.17.0" + }, + "peerDependencies": { + "@mikro-orm/core": "7.2.1" + } + }, + "node_modules/@mikro-orm/nestjs": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@mikro-orm/nestjs/-/nestjs-7.1.0.tgz", + "integrity": "sha512-S7UXOR4jYtl+lSl23GxQNoWaI3naf5WGUaWMjqZ1o+xcp+fha8une9Yu3qEizZNA+iulE4qA+yaB6sKnA67fbw==", + "license": "MIT", + "engines": { + "node": ">= 22.17.0" + }, + "peerDependencies": { + "@mikro-orm/core": "^7.0.0 || ^7.0.0-dev.0", + "@nestjs/common": "^11.0.5 || ^12.0.0", + "@nestjs/core": "^11.0.5 || ^12.0.0", + "reflect-metadata": "^0.1.0 || ^0.2.0" + } + }, + "node_modules/@mikro-orm/postgresql": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@mikro-orm/postgresql/-/postgresql-7.2.1.tgz", + "integrity": "sha512-PQ1qe4Bj/hQSHYJjR02l06FfEDwniAvncduwZSCLSKuaCUddHc5AN2Utj3yo4xRIVRY8pOa7DFitEQPBozTMJA==", + "license": "MIT", + "dependencies": { + "@mikro-orm/sql": "7.2.1", + "kysely": "0.29.6", + "pg": "8.23.0", + "pg-cursor": "2.22.0", + "postgres-array": "3.0.4", + "postgres-date": "2.1.0", + "postgres-interval": "4.1.0" + }, + "engines": { + "node": ">= 22.17.0" + }, + "peerDependencies": { + "@mikro-orm/core": "7.2.1" + } + }, + "node_modules/@mikro-orm/sql": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@mikro-orm/sql/-/sql-7.2.1.tgz", + "integrity": "sha512-3M9dQeUDLlvAT5VJr/KBGAk9C7xez+psVCnvNkAO4hRhwx2Wm7N1HkuyP4Bwj0MjkHVB6LYvhTw/V6pYsVM8lA==", + "license": "MIT", + "dependencies": { + "kysely": "0.29.6" + }, + "engines": { + "node": ">= 22.17.0" + }, + "peerDependencies": { + "@mikro-orm/core": "7.2.1" + } + }, + "node_modules/@mikro-orm/sqlite": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@mikro-orm/sqlite/-/sqlite-7.2.1.tgz", + "integrity": "sha512-+iAPGORAqLl+TcBF+JSLOfRq+PwTQG1NLts+AvN9D8C2czlbDpyjyeaAFSR+5wJlMEZ4wv2rdzt4jSS5T7x3XQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@mikro-orm/sql": "7.2.1", + "better-sqlite3": "13.0.3", + "kysely": "0.29.6" + }, + "engines": { + "node": ">= 22.17.0" + }, + "peerDependencies": { + "@mikro-orm/core": "7.2.1" + } + }, + "node_modules/@mikro-orm/sqlite/node_modules/better-sqlite3": { + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.3.tgz", + "integrity": "sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-addon-api": "^8.0.0" + }, + "engines": { + "node": ">=22" + } + }, "node_modules/@modelcontextprotocol/sdk": { "version": "1.30.0", "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.30.0.tgz", @@ -11038,6 +11183,7 @@ "version": "0.28.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", + "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -12084,6 +12230,7 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -13868,6 +14015,15 @@ "json-buffer": "3.0.1" } }, + "node_modules/kysely": { + "version": "0.29.6", + "resolved": "https://registry.npmjs.org/kysely/-/kysely-0.29.6.tgz", + "integrity": "sha512-hHaB8C/rfzDDtr/t8YZwxAuPJTT0zHyaPoVzcXwDYhYNAgH/4sIfVhi/XLLIY+bL/FqaIJnjATDbi8ObSELmxg==", + "license": "MIT", + "engines": { + "node": ">=22.0.0" + } + }, "node_modules/lazystream": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz", @@ -15867,6 +16023,16 @@ "node": ">=10" } }, + "node_modules/node-addon-api": { + "version": "8.9.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.9.2.tgz", + "integrity": "sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -16458,6 +16624,134 @@ "@napi-rs/canvas": "^0.1.80" } }, + "node_modules/pg": { + "version": "8.23.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.23.0.tgz", + "integrity": "sha512-Ip2EQCngowJLGOfCwkFhPXU7/ljlhn6Rxlmy4XYfL2Y+vyRM59+8uR2xqRWKdYmbXmxCFOAmKxBuSUCdF34qLg==", + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.14.0", + "pg-pool": "^3.14.0", + "pg-protocol": "^1.16.0", + "pg-types": "2.2.0", + "pgpass": "1.0.5" + }, + "engines": { + "node": ">= 16.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.4.0" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.0.tgz", + "integrity": "sha512-Vo7z/6rrQYxpNRylp4Tlob2elzbh+N/MOQbxFVWCxS7oEx6jF53GTJFxK2WWpKuBRkmiin4Mt+xofFDjx09R0A==", + "license": "MIT", + "optional": true + }, + "node_modules/pg-connection-string": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.0.tgz", + "integrity": "sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==", + "license": "MIT" + }, + "node_modules/pg-cursor": { + "version": "2.22.0", + "resolved": "https://registry.npmjs.org/pg-cursor/-/pg-cursor-2.22.0.tgz", + "integrity": "sha512-knzXLKqarTjOvb3qDSW0JiGsazmxwEKXrqHfWRte7XUsOYccQRafn3BLnQobWwInkzFJSyOej8y8cQRh2z3kGw==", + "license": "MIT", + "peerDependencies": { + "pg": "^8" + } + }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "license": "ISC", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz", + "integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==", + "license": "MIT", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.16.0.tgz", + "integrity": "sha512-sILXutLVjCLjcDuOmvhX5e2Z4cS5qG/6Bu3VkpFwdf/633ElGLpEh9bgmuI5I4sqKqkifQiGyiCcx1HdtrK7tg==", + "license": "MIT" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pg-types/node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/pg-types/node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pg-types/node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "license": "MIT", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "license": "MIT", + "dependencies": { + "split2": "^4.1.0" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -16770,6 +17064,42 @@ "dev": true, "license": "MIT" }, + "node_modules/postgres-array": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.4.tgz", + "integrity": "sha512-nAUSGfSDGOaOAEGwqsRY27GPOea7CNipJPOA7lPbdEpx5Kg3qzdP0AaWC5MlhTWV9s4hFX39nomVZ+C4tnGOJQ==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz", + "integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz", + "integrity": "sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/postgres-interval": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-4.1.0.tgz", + "integrity": "sha512-nJLACcOHi2iyRuMJeW6CuIA0Dc0i1YEpRr26XDyHAfxPjYUJOFxwZjmOc5oFFctTTh/OlRAMlnlXEJvr170fJg==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/potpack": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/potpack/-/potpack-2.1.0.tgz", @@ -18808,6 +19138,15 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/stackback": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", @@ -19824,9 +20163,10 @@ "license": "0BSD" }, "node_modules/tsx": { - "version": "4.22.4", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz", - "integrity": "sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==", + "version": "4.23.13", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.13.tgz", + "integrity": "sha512-BL5MGkRln6aDYhb0xbQlEAGw743BaZYWdbWtdJOBriYJboKgUUYCadFp2/FpBBZquBC/ezNBn7wMMPx7FDZUDw==", + "dev": true, "license": "MIT", "dependencies": { "esbuild": "~0.28.0" @@ -21676,6 +22016,15 @@ "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", "license": "MIT" }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -21795,6 +22144,8 @@ "dependencies": { "@aws-lite/client": "^0.23.7", "@aws-lite/s3": "^0.2.7", + "@mikro-orm/nestjs": "^7.1.0", + "@mikro-orm/postgresql": "^7.2.1", "@modelcontextprotocol/sdk": "^1.30.0", "@nestjs/common": "^11.1.24", "@nestjs/config": "^4.0.4", @@ -21830,7 +22181,6 @@ "rxjs": "^7.8.2", "semver": "^7.7.4", "tsconfig-paths": "^4.2.0", - "tsx": "^4.21.0", "typescript": "^6.0.2", "tz-lookup": "^6.1.25", "undici": "^7.29.0", @@ -21842,6 +22192,9 @@ "devDependencies": { "@aws-lite/s3-types": "^0.2.8", "@eslint/js": "^10.0.1", + "@mikro-orm/core": "^7.2.1", + "@mikro-orm/entity-generator": "^7.2.1", + "@mikro-orm/sqlite": "^7.2.1", "@nestjs/testing": "^11.1.24", "@swc/core": "^1.15.40", "@trivago/prettier-plugin-sort-imports": "^6.0.2", @@ -21872,6 +22225,7 @@ "prettier": "^3.8.3", "prettier-plugin-organize-imports": "^4.3.0", "supertest": "^7.2.2", + "tsx": "^4.23.13", "typescript-eslint": "^8.58.2", "unplugin-swc": "^1.5.9", "vitest": "^4.1.11" diff --git a/server/package.json b/server/package.json index f424df0b2..60f922d6c 100644 --- a/server/package.json +++ b/server/package.json @@ -27,6 +27,8 @@ "dependencies": { "@aws-lite/client": "^0.23.7", "@aws-lite/s3": "^0.2.7", + "@mikro-orm/nestjs": "^7.1.0", + "@mikro-orm/postgresql": "^7.2.1", "@modelcontextprotocol/sdk": "^1.30.0", "@nestjs/common": "^11.1.24", "@nestjs/config": "^4.0.4", @@ -62,7 +64,6 @@ "rxjs": "^7.8.2", "semver": "^7.7.4", "tsconfig-paths": "^4.2.0", - "tsx": "^4.21.0", "typescript": "^6.0.2", "tz-lookup": "^6.1.25", "undici": "^7.29.0", @@ -84,6 +85,9 @@ "devDependencies": { "@aws-lite/s3-types": "^0.2.8", "@eslint/js": "^10.0.1", + "@mikro-orm/core": "^7.2.1", + "@mikro-orm/entity-generator": "^7.2.1", + "@mikro-orm/sqlite": "^7.2.1", "@nestjs/testing": "^11.1.24", "@swc/core": "^1.15.40", "@trivago/prettier-plugin-sort-imports": "^6.0.2", @@ -114,6 +118,7 @@ "prettier": "^3.8.3", "prettier-plugin-organize-imports": "^4.3.0", "supertest": "^7.2.2", + "tsx": "^4.23.13", "typescript-eslint": "^8.58.2", "unplugin-swc": "^1.5.9", "vitest": "^4.1.11" diff --git a/server/src/db/entities/Addons.ts b/server/src/db/entities/Addons.ts new file mode 100644 index 000000000..ce9ad31c6 --- /dev/null +++ b/server/src/db/entities/Addons.ts @@ -0,0 +1,33 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export interface AddonConfig { + [key: string]: unknown; +} + +export class Addons { + id?: string | null; + name!: string; + description?: string | null; + type: string & Opt = 'global'; + icon: string & Opt = 'Puzzle'; + enabled?: boolean & Opt = false; + config: AddonConfig & Opt | null = {}; + sortOrder?: number | null = 0; +} + +export class AddonsRepository extends EntityRepository{} + +export const AddonsSchema = defineEntity({ + class: Addons, + repository: () => AddonsRepository, + properties: { + id: p.text().primary(), + name: p.text(), + description: p.text().nullable(), + type: p.text(), + icon: p.text().nullable(), + enabled: p.boolean().default(false), + config: p.json().nullable(), + sortOrder: p.integer().nullable(), + }, +}); diff --git a/server/src/db/entities/AppSettings.ts b/server/src/db/entities/AppSettings.ts new file mode 100644 index 000000000..930dbeea0 --- /dev/null +++ b/server/src/db/entities/AppSettings.ts @@ -0,0 +1,18 @@ +import { PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class AppSettings { + [PrimaryKeyProp]?: 'key'; + key?: string | null; + value?: string | null; +} + +export class AppSettingsRepository extends EntityRepository {} + +export const AppSettingsSchema = defineEntity({ + class: AppSettings, + repository: () => AppSettingsRepository, + properties: { + key: p.text().primary().nullable(), + value: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/AssignmentParticipants.ts b/server/src/db/entities/AssignmentParticipants.ts new file mode 100644 index 000000000..482406a8b --- /dev/null +++ b/server/src/db/entities/AssignmentParticipants.ts @@ -0,0 +1,21 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { DayAssignments } from './DayAssignments.js'; +import { Users } from './Users.js'; + +export class AssignmentParticipants { + id?: number | null; + assignment!: Ref; + user!: Ref; +} + +export class AssignmentParticipantsRepository extends EntityRepository {} + +export const AssignmentParticipantsSchema = defineEntity({ + class: AssignmentParticipants, + repository: () => AssignmentParticipantsRepository, + properties: { + id: p.integer().primary().autoincrement(), + assignment: () => p.manyToOne(DayAssignments).ref().index('idx_assignment_participants_assignment'), + user: () => p.manyToOne(Users).ref(), + }, +}); diff --git a/server/src/db/entities/AuditLog.ts b/server/src/db/entities/AuditLog.ts new file mode 100644 index 000000000..b2070104a --- /dev/null +++ b/server/src/db/entities/AuditLog.ts @@ -0,0 +1,31 @@ +import { Users } from './Users.js'; +import { defineEntity, p, type Ref, EntityRepository } from '@mikro-orm/core'; + +export class AuditLog { + id?: number | null; + createdAt: Date; + user?: Ref | null; + action!: string; + resource?: string | null; + details?: string | null; + ip?: string | null; +} + +export class AuditLogRepository extends EntityRepository {} + +export const AuditLogSchema = defineEntity({ + class: AuditLog, + repository: () => AuditLogRepository, + properties: { + id: p.integer().primary().autoincrement(), + createdAt: p + .datetime() + .onCreate(() => new Date()) + .index('idx_audit_log_created'), + user: () => p.manyToOne(Users).ref().nullable(), + action: p.text(), + resource: p.text().nullable(), + details: p.text().nullable(), + ip: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/BucketList.ts b/server/src/db/entities/BucketList.ts new file mode 100644 index 000000000..9ba44d873 --- /dev/null +++ b/server/src/db/entities/BucketList.ts @@ -0,0 +1,41 @@ +import { DawarichVisitSuggestions } from './DawarichVisitSuggestions.js'; +import { Users } from './Users.js'; +import { Collection, defineEntity, p, type Ref, EntityRepository } from '@mikro-orm/core'; + +export class BucketList { + id?: number | null; + user!: Ref; + name!: string; + lat?: unknown | null; + lng?: unknown | null; + countryCode?: string | null; + notes?: string | null; + createdAt?: Date | null; + targetDate?: string | null; + visitedAt?: string | null; + visitedSource?: string | null; + dawarichAcceptedBucketListItem = new Collection(this); + dawarichMatchedBucketListItem = new Collection(this); +} + +export class BucketListRepository extends EntityRepository {} + +export const BucketListSchema = defineEntity({ + class: BucketList, + repository: () => BucketListRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + name: p.text(), + lat: p.double().nullable(), + lng: p.double().nullable(), + countryCode: p.text().nullable(), + notes: p.text().nullable(), + createdAt: p.datetime().onCreate(() => new Date()), + targetDate: p.text().nullable(), + visitedAt: p.text().nullable(), + visitedSource: p.text().nullable(), + dawarichAcceptedBucketListItem: () => p.oneToMany(DawarichVisitSuggestions).mappedBy('acceptedBucketListItem'), + dawarichMatchedBucketListItem: () => p.oneToMany(DawarichVisitSuggestions).mappedBy('matchedBucketListItem'), + }, +}); diff --git a/server/src/db/entities/BudgetCategoryOrder.ts b/server/src/db/entities/BudgetCategoryOrder.ts new file mode 100644 index 000000000..d015113fd --- /dev/null +++ b/server/src/db/entities/BudgetCategoryOrder.ts @@ -0,0 +1,21 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; + +export class BudgetCategoryOrder { + [PrimaryKeyProp]?: ['trip', 'category']; + trip!: Ref; + category!: string; + sortOrder: number & Opt = 0; +} + +export class BudgetCategoryOrderRepository extends EntityRepository {} + +export const BudgetCategoryOrderSchema = defineEntity({ + class: BudgetCategoryOrder, + repository: () => BudgetCategoryOrderRepository, + properties: { + trip: () => p.manyToOne(Trips).primary().ref().deleteRule('cascade'), + category: p.text().primary(), + sortOrder: p.integer(), + }, +}); diff --git a/server/src/db/entities/BudgetItemMembers.ts b/server/src/db/entities/BudgetItemMembers.ts new file mode 100644 index 000000000..720bf89e1 --- /dev/null +++ b/server/src/db/entities/BudgetItemMembers.ts @@ -0,0 +1,25 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetItems } from './BudgetItems.js'; +import { Users } from './Users.js'; + +export class BudgetItemMembers { + id?: number | null; + budgetItem!: Ref; + user!: Ref; + paid: number & Opt = 0; + amount?: unknown | null; +} + +export class BudgetItemMembersRepository extends EntityRepository {} + +export const BudgetItemMembersSchema = defineEntity({ + class: BudgetItemMembers, + repository: () => BudgetItemMembersRepository, + properties: { + id: p.integer().primary().autoincrement(), + budgetItem: () => p.manyToOne(BudgetItems).ref().deleteRule('cascade').index('idx_budget_item_members_item'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_budget_item_members_user'), + paid: p.integer(), + amount: p.double().nullable(), + }, +}); diff --git a/server/src/db/entities/BudgetItemPayers.ts b/server/src/db/entities/BudgetItemPayers.ts new file mode 100644 index 000000000..120c88eca --- /dev/null +++ b/server/src/db/entities/BudgetItemPayers.ts @@ -0,0 +1,23 @@ +import { BudgetItems } from './BudgetItems.js'; +import { Users } from './Users.js'; +import { type Ref, defineEntity, p, Opt, EntityRepository } from '@mikro-orm/core'; + +export class BudgetItemPayers { + id?: number | null; + budgetItem!: Ref; + user!: Ref; + amount: number & Opt = 0; +} + +export class BudgetItemPayersRepository extends EntityRepository {} + +export const BudgetItemPayersSchema = defineEntity({ + class: BudgetItemPayers, + repository: () => BudgetItemPayersRepository, + properties: { + id: p.integer().primary().autoincrement(), + budgetItem: () => p.manyToOne(BudgetItems).ref().deleteRule('cascade').index('idx_budget_item_payers_item'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + amount: p.double().default(0), + }, +}); diff --git a/server/src/db/entities/BudgetItems.ts b/server/src/db/entities/BudgetItems.ts new file mode 100644 index 000000000..e8a0a3f25 --- /dev/null +++ b/server/src/db/entities/BudgetItems.ts @@ -0,0 +1,60 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetItemMembers } from './BudgetItemMembers.js'; +import { BudgetItemPayers } from './BudgetItemPayers.js'; +import { FileLinks } from './FileLinks.js'; +import { Places } from './Places.js'; +import { Reservations } from './Reservations.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class BudgetItems { + id?: number | null; + trip!: Ref; + category: string & Opt = 'Other'; + name!: string; + totalPrice!: number & Opt; + persons?: number | null = NaN; + days?: number | null = NaN; + note?: string | null; + sortOrder?: number | null = 0; + createdAt?: Date | null; + paidByUser?: Ref | null; + expenseDate?: string | null; + reservation?: Ref | null; + currency?: string | null; + exchangeRate!: number & Opt; + ticketJson?: string | null; + place?: Ref | null; + budgetItemMembersCollection = new Collection(this); + budgetItemPayersCollection = new Collection(this); + fileLinksCollection = new Collection(this); +} + +export class BudgetItemsRepository extends EntityRepository {} + +export const BudgetItemsSchema = defineEntity({ + class: BudgetItems, + repository: () => BudgetItemsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_budget_items_trip_id'), + category: p.text(), + name: p.text(), + totalPrice: p.double().default(0), + persons: p.integer().nullable(), + days: p.integer().nullable(), + note: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + paidByUser: () => p.manyToOne(Users).ref().nullable(), + expenseDate: p.text().nullable(), + reservation: () => p.manyToOne(Reservations).ref().nullable(), + currency: p.text().nullable(), + exchangeRate: p.double().default(1), + ticketJson: p.text().nullable(), + place: () => p.manyToOne(Places).ref().nullable(), + budgetItemMembersCollection: () => p.oneToMany(BudgetItemMembers).mappedBy('budgetItem'), + budgetItemPayersCollection: () => p.oneToMany(BudgetItemPayers).mappedBy('budgetItem'), + fileLinksCollection: () => p.oneToMany(FileLinks).mappedBy('budgetItem'), + }, +}); diff --git a/server/src/db/entities/BudgetSettlements.ts b/server/src/db/entities/BudgetSettlements.ts new file mode 100644 index 000000000..fc222d0d9 --- /dev/null +++ b/server/src/db/entities/BudgetSettlements.ts @@ -0,0 +1,35 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class BudgetSettlements { + id?: number | null; + trip!: Ref; + fromUser!: Ref; + toUser!: Ref; + amount!: number; + createdAt?: Date | null; + createdByUser?: Ref | null; + currency?: string | null; + exchangeRate!: number; + settledAt?: string | null; +} + +export class BudgetSettlementsRepository extends EntityRepository {} + +export const BudgetSettlementsSchema = defineEntity({ + class: BudgetSettlements, + repository: () => BudgetSettlementsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_budget_settlements_trip'), + fromUser: () => p.manyToOne(Users).ref().deleteRule('cascade'), + toUser: () => p.manyToOne(Users).ref().deleteRule('cascade'), + amount: p.double().default(0), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + createdByUser: () => p.manyToOne(Users).ref().nullable(), + currency: p.text().nullable(), + exchangeRate: p.double().default(1), + settledAt: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Categories.ts b/server/src/db/entities/Categories.ts new file mode 100644 index 000000000..c18267a44 --- /dev/null +++ b/server/src/db/entities/Categories.ts @@ -0,0 +1,32 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Places } from './Places.js'; +import { Users } from './Users.js'; + +export class Categories { + id?: number | null; + name!: string; + color?: string | null = '#6366f1'; + icon?: string | null = '📍'; + user?: Ref | null; + createdAt?: Date | null; + collectionPlacesCollection = new Collection(this); + placesCollection = new Collection(this); +} + +export class CategoriesRepository extends EntityRepository {} + +export const CategoriesSchema = defineEntity({ + class: Categories, + repository: () => CategoriesRepository, + properties: { + id: p.integer().primary().autoincrement(), + name: p.text(), + color: p.text().nullable(), + icon: p.text().nullable(), + user: () => p.manyToOne(Users).ref().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + collectionPlacesCollection: () => p.oneToMany(CollectionPlaces).mappedBy('category'), + placesCollection: () => p.oneToMany(Places).mappedBy('category'), + }, +}); diff --git a/server/src/db/entities/CollabLinks.ts b/server/src/db/entities/CollabLinks.ts new file mode 100644 index 000000000..7ffb15e08 --- /dev/null +++ b/server/src/db/entities/CollabLinks.ts @@ -0,0 +1,31 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class CollabLinks { + id?: number | null; + trip!: Ref; + user!: Ref; + title!: string; + url!: string; + pinned?: number | null = 0; + createdAt?: Date | null; + updatedAt?: Date | null; +} + +export class CollabLinksRepository extends EntityRepository {} + +export const CollabLinksSchema = defineEntity({ + class: CollabLinks, + repository: () => CollabLinksRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_collab_links_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + title: p.text(), + url: p.text(), + pinned: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/CollabMessageReactions.ts b/server/src/db/entities/CollabMessageReactions.ts new file mode 100644 index 000000000..dd2aa2f2f --- /dev/null +++ b/server/src/db/entities/CollabMessageReactions.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollabMessages } from './CollabMessages.js'; +import { Users } from './Users.js'; + +export class CollabMessageReactions { + id?: number | null; + message!: Ref; + user!: Ref; + emoji!: string; + createdAt?: Date | null; +} + +export class CollabMessageReactionsRepository extends EntityRepository {} + +export const CollabMessageReactionsSchema = defineEntity({ + class: CollabMessageReactions, + repository: () => CollabMessageReactionsRepository, + properties: { + id: p.integer().primary().autoincrement(), + message: () => p.manyToOne(CollabMessages).ref().deleteRule('cascade').index('idx_collab_reactions_msg'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + emoji: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/CollabMessages.ts b/server/src/db/entities/CollabMessages.ts new file mode 100644 index 000000000..ea31783c1 --- /dev/null +++ b/server/src/db/entities/CollabMessages.ts @@ -0,0 +1,37 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollabMessageReactions } from './CollabMessageReactions.js'; +import { TripFiles } from './TripFiles.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class CollabMessages { + id?: number | null; + trip!: Ref; + user!: Ref; + text!: string; + replyTo?: Ref | null; + createdAt?: Date | null; + deleted?: number | null = 0; + collabMessageReactionsCollection = new Collection(this); + collabMessagesCollection = new Collection(this); + tripFilesCollection = new Collection(this); +} + +export class CollabMessagesRepository extends EntityRepository {} + +export const CollabMessagesSchema = defineEntity({ + class: CollabMessages, + repository: () => CollabMessagesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_collab_messages_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + text: p.text(), + replyTo: () => p.manyToOne(CollabMessages).ref().name('reply_to').nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + deleted: p.integer().nullable(), + collabMessageReactionsCollection: () => p.oneToMany(CollabMessageReactions).mappedBy('message'), + collabMessagesCollection: () => p.oneToMany(CollabMessages).mappedBy('replyTo'), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('message'), + }, +}); diff --git a/server/src/db/entities/CollabNotes.ts b/server/src/db/entities/CollabNotes.ts new file mode 100644 index 000000000..f035adee5 --- /dev/null +++ b/server/src/db/entities/CollabNotes.ts @@ -0,0 +1,40 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { TripFiles } from './TripFiles.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class CollabNotes { + id?: number | null; + trip!: Ref; + user!: Ref; + category?: string | null = 'General'; + title!: string; + content?: string | null; + color?: string | null = '#6366f1'; + pinned?: number | null = 0; + createdAt?: Date | null; + updatedAt?: Date | null; + website?: string | null; + tripFilesCollection = new Collection(this); +} + +export class CollabNotesRepository extends EntityRepository {} + +export const CollabNotesSchema = defineEntity({ + class: CollabNotes, + repository: () => CollabNotesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_collab_notes_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + category: p.text().nullable(), + title: p.text(), + content: p.text().nullable(), + color: p.text().nullable(), + pinned: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + website: p.text().nullable(), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('note'), + }, +}); diff --git a/server/src/db/entities/CollabPollVotes.ts b/server/src/db/entities/CollabPollVotes.ts new file mode 100644 index 000000000..cd0d6e697 --- /dev/null +++ b/server/src/db/entities/CollabPollVotes.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollabPolls } from './CollabPolls.js'; +import { Users } from './Users.js'; + +export class CollabPollVotes { + id?: number | null; + poll!: Ref; + user!: Ref; + optionIndex!: number; + createdAt?: Date | null; +} + +export class CollabPollVotesRepository extends EntityRepository {} + +export const CollabPollVotesSchema = defineEntity({ + class: CollabPollVotes, + repository: () => CollabPollVotesRepository, + properties: { + id: p.integer().primary().autoincrement(), + poll: () => p.manyToOne(CollabPolls).ref().deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + optionIndex: p.integer(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/CollabPolls.ts b/server/src/db/entities/CollabPolls.ts new file mode 100644 index 000000000..e86aac5a2 --- /dev/null +++ b/server/src/db/entities/CollabPolls.ts @@ -0,0 +1,36 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollabPollVotes } from './CollabPollVotes.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class CollabPolls { + id?: number | null; + trip!: Ref; + user!: Ref; + question!: string; + options!: string; + multiple?: number | null = 0; + closed?: number | null = 0; + deadline?: string | null; + createdAt?: Date | null; + collabPollVotesCollection = new Collection(this); +} + +export class CollabPollsRepository extends EntityRepository {} + +export const CollabPollsSchema = defineEntity({ + class: CollabPolls, + repository: () => CollabPollsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_collab_polls_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + question: p.text(), + options: p.text(), + multiple: p.integer().nullable(), + closed: p.integer().nullable(), + deadline: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + collabPollVotesCollection: () => p.oneToMany(CollabPollVotes).mappedBy('poll'), + }, +}); diff --git a/server/src/db/entities/CollectionLabels.ts b/server/src/db/entities/CollectionLabels.ts new file mode 100644 index 000000000..07319ab9f --- /dev/null +++ b/server/src/db/entities/CollectionLabels.ts @@ -0,0 +1,29 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Collections } from './Collections.js'; + +export class CollectionLabels { + id?: number | null; + collection!: Ref; + name!: string; + color?: string | null = '#6366f1'; + sortOrder?: number | null = 0; + createdAt?: Date | null; + collectionPlaceLabelsInverse = new Collection(this); +} + +export class CollectionLabelsRepository extends EntityRepository {} + +export const CollectionLabelsSchema = defineEntity({ + class: CollectionLabels, + repository: () => CollectionLabelsRepository, + properties: { + id: p.integer().primary().autoincrement(), + collection: () => p.manyToOne(Collections).ref().deleteRule('cascade').index('idx_collection_labels_collection'), + name: p.text(), + color: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + collectionPlaceLabelsInverse: () => p.manyToMany(CollectionPlaces).mappedBy('collectionPlaceLabels'), + }, +}); diff --git a/server/src/db/entities/CollectionMembers.ts b/server/src/db/entities/CollectionMembers.ts new file mode 100644 index 000000000..34375a5d0 --- /dev/null +++ b/server/src/db/entities/CollectionMembers.ts @@ -0,0 +1,27 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Collections } from './Collections.js'; +import { Users } from './Users.js'; + +export class CollectionMembers { + id?: number | null; + collection!: Ref; + user!: Ref; + status: string & Opt = 'pending'; + role: string & Opt = 'editor'; + createdAt?: Date | null; +} + +export class CollectionMembersRepository extends EntityRepository {} + +export const CollectionMembersSchema = defineEntity({ + class: CollectionMembers, + repository: () => CollectionMembersRepository, + properties: { + id: p.integer().primary().autoincrement(), + collection: () => p.manyToOne(Collections).ref().deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_collection_members_user'), + status: p.text(), + role: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/CollectionPlaceRatings.ts b/server/src/db/entities/CollectionPlaceRatings.ts new file mode 100644 index 000000000..131890393 --- /dev/null +++ b/server/src/db/entities/CollectionPlaceRatings.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Users } from './Users.js'; + +export class CollectionPlaceRatings { + id?: number | null; + collectionPlace!: Ref; + user!: Ref; + rating!: number; + createdAt?: Date | null; +} + +export class CollectionPlaceRatingsRepository extends EntityRepository {} + +export const CollectionPlaceRatingsSchema = defineEntity({ + class: CollectionPlaceRatings, + repository: () => CollectionPlaceRatingsRepository, + properties: { + id: p.integer().primary().autoincrement(), + collectionPlace: () => p.manyToOne(CollectionPlaces).ref().deleteRule('cascade').index('idx_collection_place_ratings_place'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + rating: p.integer(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/CollectionPlaces.ts b/server/src/db/entities/CollectionPlaces.ts new file mode 100644 index 000000000..673d06a68 --- /dev/null +++ b/server/src/db/entities/CollectionPlaces.ts @@ -0,0 +1,77 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Categories } from './Categories.js'; +import { CollectionLabels } from './CollectionLabels.js'; +import { CollectionPlaceRatings } from './CollectionPlaceRatings.js'; +import { Collections } from './Collections.js'; +import { Tags } from './Tags.js'; +import { Users } from './Users.js'; + +export class CollectionPlaces { + id?: number | null; + collection!: Ref; + owner!: Ref; + savedBy?: Ref | null; + name!: string; + description?: string | null; + lat?: unknown | null; + lng?: unknown | null; + address?: string | null; + category?: Ref | null; + price?: unknown | null; + currency?: string | null; + notes?: string | null; + imageUrl?: string | null; + googlePlaceId?: string | null; + googleFtid?: string | null; + osmId?: string | null; + website?: string | null; + phone?: string | null; + status: string & Opt = 'idea'; + sourceTripId?: number | null; + sourcePlaceId?: number | null; + links?: string | null; + sortOrder?: number | null = 0; + createdAt?: Date | null; + updatedAt?: Date | null; + collectionPlaceLabels = new Collection(this); + collectionPlaceTags = new Collection(this); + collectionPlaceRatingsCollection = new Collection(this); +} + +export class CollectionPlacesRepository extends EntityRepository {} + +export const CollectionPlacesSchema = defineEntity({ + class: CollectionPlaces, + repository: () => CollectionPlacesRepository, + properties: { + id: p.integer().primary().autoincrement(), + collection: () => p.manyToOne(Collections).ref().deleteRule('cascade').index('idx_collection_places_collection'), + owner: () => p.manyToOne(Users).ref().deleteRule('cascade'), + savedBy: () => p.manyToOne(Users).ref().name('saved_by').nullable(), + name: p.text(), + description: p.text().nullable(), + lat: p.double().nullable(), + lng: p.double().nullable(), + address: p.text().nullable(), + category: () => p.manyToOne(Categories).ref().nullable(), + price: p.double().nullable(), + currency: p.text().nullable(), + notes: p.text().nullable(), + imageUrl: p.text().nullable(), + googlePlaceId: p.text().nullable(), + googleFtid: p.text().nullable(), + osmId: p.text().nullable(), + website: p.text().nullable(), + phone: p.text().nullable(), + status: p.text(), + sourceTripId: p.integer().nullable(), + sourcePlaceId: p.integer().nullable(), + links: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + collectionPlaceLabels: () => p.manyToMany(CollectionLabels).pivotTable('collection_place_labels').joinColumn('collection_place_id').inverseJoinColumn('label_id'), + collectionPlaceTags: () => p.manyToMany(Tags).pivotTable('collection_place_tags').joinColumn('collection_place_id').inverseJoinColumn('tag_id'), + collectionPlaceRatingsCollection: () => p.oneToMany(CollectionPlaceRatings).mappedBy('collectionPlace'), + }, +}); diff --git a/server/src/db/entities/Collections.ts b/server/src/db/entities/Collections.ts new file mode 100644 index 000000000..5be005569 --- /dev/null +++ b/server/src/db/entities/Collections.ts @@ -0,0 +1,45 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollectionLabels } from './CollectionLabels.js'; +import { CollectionMembers } from './CollectionMembers.js'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Users } from './Users.js'; + +export class Collections { + id?: number | null; + owner!: Ref; + name!: string; + description?: string | null; + color?: string | null = '#6366f1'; + icon?: string | null = 'Bookmark'; + coverImage?: string | null; + links?: string | null; + sortOrder?: number | null = 0; + createdAt?: Date | null; + updatedAt?: Date | null; + collectionLabelsCollection = new Collection(this); + collectionMembersCollection = new Collection(this); + collectionPlacesCollection = new Collection(this); +} + +export class CollectionsRepository extends EntityRepository {} + +export const CollectionsSchema = defineEntity({ + class: Collections, + repository: () => CollectionsRepository, + properties: { + id: p.integer().primary().autoincrement(), + owner: () => p.manyToOne(Users).ref().deleteRule('cascade'), + name: p.text(), + description: p.text().nullable(), + color: p.text().nullable(), + icon: p.text().nullable(), + coverImage: p.text().nullable(), + links: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + collectionLabelsCollection: () => p.oneToMany(CollectionLabels).mappedBy('collection'), + collectionMembersCollection: () => p.oneToMany(CollectionMembers).mappedBy('collection'), + collectionPlacesCollection: () => p.oneToMany(CollectionPlaces).mappedBy('collection'), + }, +}); diff --git a/server/src/db/entities/DawarichConnections.ts b/server/src/db/entities/DawarichConnections.ts new file mode 100644 index 000000000..8e63492f9 --- /dev/null +++ b/server/src/db/entities/DawarichConnections.ts @@ -0,0 +1,37 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class DawarichConnections { + [PrimaryKeyProp]?: 'user'; + user?: Ref | null; + url?: string | null; + apiKey?: string | null; + allowInsecureTls: number & Opt = 0; + syncEnabled: number & Opt = 1; + lastSyncAt?: string | null; + lastSyncState: string & Opt = 'never'; + lastSyncError?: string | null; + capabilities?: string | null; + createdAt?: Date | null; + updatedAt?: Date | null; +} + +export class DawarichConnectionsRepository extends EntityRepository {} + +export const DawarichConnectionsSchema = defineEntity({ + class: DawarichConnections, + repository: () => DawarichConnectionsRepository, + properties: { + user: () => p.oneToOne(Users).primary().ref().nullable(), + url: p.text().nullable(), + apiKey: p.text().nullable(), + allowInsecureTls: p.integer(), + syncEnabled: p.integer(), + lastSyncAt: p.text().nullable(), + lastSyncState: p.text(), + lastSyncError: p.text().nullable(), + capabilities: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/DawarichVisitSuggestions.ts b/server/src/db/entities/DawarichVisitSuggestions.ts new file mode 100644 index 000000000..acde0cb7c --- /dev/null +++ b/server/src/db/entities/DawarichVisitSuggestions.ts @@ -0,0 +1,72 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BucketList } from './BucketList.js'; +import { Places } from './Places.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class DawarichVisitSuggestions { + id?: number | null; + user!: Ref; + sourceVisitId!: string; + trip?: Ref | null; + name!: string; + lat?: unknown | null; + lng?: unknown | null; + startedAt!: string; + endedAt!: string; + durationMinutes: number & Opt = 0; + localDate!: string; + sourceStatus: string & Opt = 'suggested'; + confidence?: unknown | null; + confidenceBand?: string | null; + countryCode?: string | null; + state: string & Opt = 'new'; + target?: string | null; + acceptedPlace?: Ref | null; + acceptedJournalEntryId?: number | null; + acceptedBucketListItem?: Ref | null; + matchedBucketListItem?: Ref | null; + sourceHash!: string; + acceptedHash?: string | null; + sourceMissingAt?: string | null; + firstSeenAt!: string & Opt; + lastSeenAt!: string & Opt; +} + +export class DawarichVisitSuggestionsRepository extends EntityRepository {} + +export const DawarichVisitSuggestionsSchema = defineEntity({ + class: DawarichVisitSuggestions, + repository: () => DawarichVisitSuggestionsRepository, + indexes: [ + { name: 'idx_dawarich_suggestions_user_state', properties: ['user', 'state'] }, + ], + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + sourceVisitId: p.text(), + trip: () => p.manyToOne(Trips).ref().nullable().index('idx_dawarich_suggestions_trip'), + name: p.text(), + lat: p.double().nullable(), + lng: p.double().nullable(), + startedAt: p.text(), + endedAt: p.text(), + durationMinutes: p.integer(), + localDate: p.text(), + sourceStatus: p.text(), + confidence: p.double().nullable(), + confidenceBand: p.text().nullable(), + countryCode: p.text().nullable(), + state: p.text(), + target: p.text().nullable(), + acceptedPlace: () => p.manyToOne(Places).ref().nullable(), + acceptedJournalEntryId: p.integer().nullable(), + acceptedBucketListItem: () => p.manyToOne(BucketList).ref().nullable(), + matchedBucketListItem: () => p.manyToOne(BucketList).ref().nullable(), + sourceHash: p.text(), + acceptedHash: p.text().nullable(), + sourceMissingAt: p.text().nullable(), + firstSeenAt: p.text().onCreate(() => new Date()), + lastSeenAt: p.text().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/DayAccommodations.ts b/server/src/db/entities/DayAccommodations.ts new file mode 100644 index 000000000..1fdf64190 --- /dev/null +++ b/server/src/db/entities/DayAccommodations.ts @@ -0,0 +1,38 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; +import { Places } from './Places.js'; +import { Trips } from './Trips.js'; + +export class DayAccommodations { + id?: number | null; + trip!: Ref; + place?: Ref | null; + startDay!: Ref; + endDay!: Ref; + checkIn?: string | null; + checkInEnd?: string | null; + checkOut?: string | null; + confirmation?: string | null; + notes?: string | null; + createdAt?: Date | null; +} + +export class DayAccommodationsRepository extends EntityRepository {} + +export const DayAccommodationsSchema = defineEntity({ + class: DayAccommodations, + repository: () => DayAccommodationsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_day_accommodations_trip_id'), + place: () => p.manyToOne(Places).ref().nullable(), + startDay: () => p.manyToOne(Days).ref().deleteRule('cascade').index('idx_day_accommodations_start_day_id'), + endDay: () => p.manyToOne(Days).ref().deleteRule('cascade').index('idx_day_accommodations_end_day_id'), + checkIn: p.text().nullable(), + checkInEnd: p.text().nullable(), + checkOut: p.text().nullable(), + confirmation: p.text().nullable(), + notes: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/DayAssignments.ts b/server/src/db/entities/DayAssignments.ts new file mode 100644 index 000000000..4de754769 --- /dev/null +++ b/server/src/db/entities/DayAssignments.ts @@ -0,0 +1,59 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { AssignmentParticipants } from './AssignmentParticipants.js'; +import { Days } from './Days.js'; +import { FileLinks } from './FileLinks.js'; +import { Places } from './Places.js'; +import { Reservations } from './Reservations.js'; +import { RoadtripDayBoundaries } from './RoadtripDayBoundaries.js'; + +export class DayAssignments { + id?: number | null; + day!: Ref; + place!: Ref; + orderIndex?: number | null = 0; + notes?: string | null; + reservationStatus?: string | null = 'none'; + reservationNotes?: string | null; + reservationDatetime?: string | null; + createdAt?: Date | null; + assignmentTime?: string | null; + assignmentEndTime?: string | null; + legTransportMode?: string | null; + incomingLegTransportMode?: string | null; + endDay: number & Opt = 0; + accommodationId?: number | null; + assignmentParticipantsCollection = new Collection(this); + fileLinksCollection = new Collection(this); + reservationsCollection = new Collection(this); + roadtripDayBoundariesCollection = new Collection(this); + roadtripDayBoundariesCollection1 = new Collection(this); +} + +export class DayAssignmentsRepository extends EntityRepository {} + +export const DayAssignmentsSchema = defineEntity({ + class: DayAssignments, + repository: () => DayAssignmentsRepository, + properties: { + id: p.integer().primary().autoincrement(), + day: () => p.manyToOne(Days).ref().deleteRule('cascade').index('idx_day_assignments_day_id'), + place: () => p.manyToOne(Places).ref().deleteRule('cascade').index('idx_day_assignments_place_id'), + orderIndex: p.integer().nullable(), + notes: p.text().nullable(), + reservationStatus: p.text().nullable(), + reservationNotes: p.text().nullable(), + reservationDatetime: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + assignmentTime: p.text().nullable(), + assignmentEndTime: p.text().nullable(), + legTransportMode: p.text().nullable(), + incomingLegTransportMode: p.text().nullable(), + endDay: p.integer(), + accommodationId: p.integer().nullable().index('idx_day_assignments_accommodation_id'), + assignmentParticipantsCollection: () => p.oneToMany(AssignmentParticipants).mappedBy('assignment'), + fileLinksCollection: () => p.oneToMany(FileLinks).mappedBy('assignment'), + reservationsCollection: () => p.oneToMany(Reservations).mappedBy('assignment'), + roadtripDayBoundariesCollection: () => p.oneToMany(RoadtripDayBoundaries).mappedBy('fromAssignment'), + roadtripDayBoundariesCollection1: () => p.oneToMany(RoadtripDayBoundaries).mappedBy('toAssignment'), + }, +}); diff --git a/server/src/db/entities/DayNotes.ts b/server/src/db/entities/DayNotes.ts new file mode 100644 index 000000000..afae8bdef --- /dev/null +++ b/server/src/db/entities/DayNotes.ts @@ -0,0 +1,33 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; +import { Trips } from './Trips.js'; + +export class DayNotes { + id?: number | null; + day!: Ref; + trip!: Ref; + text!: string; + time?: string | null; + icon?: string | null = '📝'; + sortOrder?: unknown | null; + createdAt?: Date | null; + color?: string | null; +} + +export class DayNotesRepository extends EntityRepository {} + +export const DayNotesSchema = defineEntity({ + class: DayNotes, + repository: () => DayNotesRepository, + properties: { + id: p.integer().primary().autoincrement(), + day: () => p.manyToOne(Days).ref().deleteRule('cascade').index('idx_day_notes_day_id'), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + text: p.text(), + time: p.text().nullable(), + icon: p.text().nullable(), + sortOrder: p.double().nullable().default(0), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + color: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Days.ts b/server/src/db/entities/Days.ts new file mode 100644 index 000000000..f763ba031 --- /dev/null +++ b/server/src/db/entities/Days.ts @@ -0,0 +1,56 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { DayAccommodations } from './DayAccommodations.js'; +import { DayAssignments } from './DayAssignments.js'; +import { DayNotes } from './DayNotes.js'; +import { Photos } from './Photos.js'; +import { ReservationDayPositions } from './ReservationDayPositions.js'; +import { Reservations } from './Reservations.js'; +import { RoadtripDayTracks } from './RoadtripDayTracks.js'; +import { RoadtripVias } from './RoadtripVias.js'; +import { Trips } from './Trips.js'; + +export class Days { + id?: number | null; + trip!: Ref; + dayNumber!: number; + date?: string | null; + notes?: string | null; + title?: string | null; + defaultTransportMode?: string | null; + dayAccommodationsCollection = new Collection(this); + dayAccommodationsCollection1 = new Collection(this); + dayAssignmentsCollection = new Collection(this); + dayNotesCollection = new Collection(this); + photosCollection = new Collection(this); + reservationDayPositionsCollection = new Collection(this); + reservationsCollection = new Collection(this); + reservationsCollection1 = new Collection(this); + roadtripDayTracks: Ref | null = null; + roadtripViasCollection = new Collection(this); +} + +export class DaysRepository extends EntityRepository {} + +export const DaysSchema = defineEntity({ + class: Days, + repository: () => DaysRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_days_trip_id'), + dayNumber: p.integer(), + date: p.text().nullable(), + notes: p.text().nullable(), + title: p.text().nullable(), + defaultTransportMode: p.text().nullable(), + dayAccommodationsCollection: () => p.oneToMany(DayAccommodations).mappedBy('startDay'), + dayAccommodationsCollection1: () => p.oneToMany(DayAccommodations).mappedBy('endDay'), + dayAssignmentsCollection: () => p.oneToMany(DayAssignments).mappedBy('day'), + dayNotesCollection: () => p.oneToMany(DayNotes).mappedBy('day'), + photosCollection: () => p.oneToMany(Photos).mappedBy('day'), + reservationDayPositionsCollection: () => p.oneToMany(ReservationDayPositions).mappedBy('day'), + reservationsCollection: () => p.oneToMany(Reservations).mappedBy('day'), + reservationsCollection1: () => p.oneToMany(Reservations).mappedBy('endDay'), + roadtripDayTracks: () => p.oneToOne(RoadtripDayTracks).ref().mappedBy('day'), + roadtripViasCollection: () => p.oneToMany(RoadtripVias).mappedBy('day'), + }, +}); diff --git a/server/src/db/entities/FileLinks.ts b/server/src/db/entities/FileLinks.ts new file mode 100644 index 000000000..53cf653bc --- /dev/null +++ b/server/src/db/entities/FileLinks.ts @@ -0,0 +1,35 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetItems } from './BudgetItems.js'; +import { DayAssignments } from './DayAssignments.js'; +import { Places } from './Places.js'; +import { Reservations } from './Reservations.js'; +import { TripFiles } from './TripFiles.js'; + +export class FileLinks { + id?: number | null; + file!: Ref; + reservation?: Ref | null; + assignment?: Ref | null; + place?: Ref | null; + createdAt?: Date | null; + budgetItem?: Ref | null; +} + +export class FileLinksRepository extends EntityRepository {} + +export const FileLinksSchema = defineEntity({ + class: FileLinks, + repository: () => FileLinksRepository, + uniques: [ + { name: 'idx_file_links_file_budget', properties: ['file', 'budgetItem'] }, + ], + properties: { + id: p.integer().primary().autoincrement(), + file: () => p.manyToOne(TripFiles).ref().deleteRule('cascade'), + reservation: () => p.manyToOne(Reservations).ref().deleteRule('cascade').nullable(), + assignment: () => p.manyToOne(DayAssignments).ref().deleteRule('cascade').nullable(), + place: () => p.manyToOne(Places).ref().deleteRule('cascade').nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + budgetItem: () => p.manyToOne(BudgetItems).ref().nullable().index('idx_file_links_budget_item_id'), + }, +}); diff --git a/server/src/db/entities/GooglePlacePhotoMeta.ts b/server/src/db/entities/GooglePlacePhotoMeta.ts new file mode 100644 index 000000000..9ec7f028f --- /dev/null +++ b/server/src/db/entities/GooglePlacePhotoMeta.ts @@ -0,0 +1,22 @@ +import { PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class GooglePlacePhotoMeta { + [PrimaryKeyProp]?: 'placeId'; + placeId?: string | null; + attribution?: string | null; + fetchedAt!: number; + errorAt?: number | null; +} + +export class GooglePlacePhotoMetaRepository extends EntityRepository {} + +export const GooglePlacePhotoMetaSchema = defineEntity({ + class: GooglePlacePhotoMeta, + repository: () => GooglePlacePhotoMetaRepository, + properties: { + placeId: p.text().primary().nullable(), + attribution: p.text().nullable(), + fetchedAt: p.integer(), + errorAt: p.integer().nullable(), + }, +}); diff --git a/server/src/db/entities/HiddenCountries.ts b/server/src/db/entities/HiddenCountries.ts new file mode 100644 index 000000000..1342b9299 --- /dev/null +++ b/server/src/db/entities/HiddenCountries.ts @@ -0,0 +1,22 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class HiddenCountries { + id?: number | null; + user!: Ref; + countryCode!: string; + createdAt?: Date | null; +} + +export class HiddenCountriesRepository extends EntityRepository {} + +export const HiddenCountriesSchema = defineEntity({ + class: HiddenCountries, + repository: () => HiddenCountriesRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_hidden_countries_user'), + countryCode: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/HiddenRegions.ts b/server/src/db/entities/HiddenRegions.ts new file mode 100644 index 000000000..6508b9d8e --- /dev/null +++ b/server/src/db/entities/HiddenRegions.ts @@ -0,0 +1,24 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class HiddenRegions { + id?: number | null; + user!: Ref; + regionCode!: string; + countryCode!: string; + createdAt?: Date | null; +} + +export class HiddenRegionsRepository extends EntityRepository {} + +export const HiddenRegionsSchema = defineEntity({ + class: HiddenRegions, + repository: () => HiddenRegionsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_hidden_regions_user'), + regionCode: p.text(), + countryCode: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/IdempotencyKeys.ts b/server/src/db/entities/IdempotencyKeys.ts new file mode 100644 index 000000000..81bcf067a --- /dev/null +++ b/server/src/db/entities/IdempotencyKeys.ts @@ -0,0 +1,29 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class IdempotencyKeys { + [PrimaryKeyProp]?: ['key', 'user', 'method', 'path']; + key!: string; + user!: Ref; + method!: string; + path!: string; + statusCode!: number; + responseBody!: string; + createdAt: number & Opt = NaN; +} + +export class IdempotencyKeysRepository extends EntityRepository {} + +export const IdempotencyKeysSchema = defineEntity({ + class: IdempotencyKeys, + repository: () => IdempotencyKeysRepository, + properties: { + key: p.text().primary(), + user: () => p.manyToOne(Users).primary().ref().deleteRule('cascade'), + method: p.text().primary(), + path: p.text().primary(), + statusCode: p.integer(), + responseBody: p.text(), + createdAt: p.integer().defaultRaw(`(strftime('%s','now'))`).index('idx_idempotency_keys_created'), + }, +}); diff --git a/server/src/db/entities/InviteTokens.ts b/server/src/db/entities/InviteTokens.ts new file mode 100644 index 000000000..3a707a266 --- /dev/null +++ b/server/src/db/entities/InviteTokens.ts @@ -0,0 +1,31 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class InviteTokens { + id?: number | null; + token!: string; + maxUses: number & Opt = 1; + usedCount: number & Opt = 0; + expiresAt?: string | null; + createdBy!: Ref; + createdAt?: Date | null; + trip?: Ref | null; +} + +export class InviteTokensRepository extends EntityRepository {} + +export const InviteTokensSchema = defineEntity({ + class: InviteTokens, + repository: () => InviteTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + token: p.text(), + maxUses: p.integer(), + usedCount: p.integer(), + expiresAt: p.text().nullable(), + createdBy: () => p.manyToOne(Users).ref().name('created_by').deleteRule('cascade'), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + trip: () => p.manyToOne(Trips).ref().nullable(), + }, +}); diff --git a/server/src/db/entities/JourneyBooks.ts b/server/src/db/entities/JourneyBooks.ts new file mode 100644 index 000000000..ba469f953 --- /dev/null +++ b/server/src/db/entities/JourneyBooks.ts @@ -0,0 +1,33 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Journeys } from './Journeys.js'; +import { Users } from './Users.js'; + +export class JourneyBooks { + id?: number | null; + journey!: Ref; + title: string & Opt = ''; + document!: string; + version: number & Opt = 1; + createdBy?: Ref | null; + updatedBy?: Ref | null; + createdAt?: Date | null; + updatedAt?: Date | null; +} + +export class JourneyBooksRepository extends EntityRepository {} + +export const JourneyBooksSchema = defineEntity({ + class: JourneyBooks, + repository: () => JourneyBooksRepository, + properties: { + id: p.integer().primary().autoincrement(), + journey: () => p.manyToOne(Journeys).ref().deleteRule('cascade').index('idx_journey_books_journey'), + title: p.text(), + document: p.text(), + version: p.integer(), + createdBy: () => p.manyToOne(Users).ref().name('created_by').nullable(), + updatedBy: () => p.manyToOne(Users).ref().name('updated_by').nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/JourneyContributors.ts b/server/src/db/entities/JourneyContributors.ts new file mode 100644 index 000000000..575631042 --- /dev/null +++ b/server/src/db/entities/JourneyContributors.ts @@ -0,0 +1,26 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Journeys } from './Journeys.js'; +import { Users } from './Users.js'; + +export class JourneyContributors { + [PrimaryKeyProp]?: ['journey', 'user']; + journey!: Ref; + user!: Ref; + role!: string; + addedAt!: number; + hideSkeletons: number & Opt = 0; +} + +export class JourneyContributorsRepository extends EntityRepository {} + +export const JourneyContributorsSchema = defineEntity({ + class: JourneyContributors, + repository: () => JourneyContributorsRepository, + properties: { + journey: () => p.manyToOne(Journeys).primary().ref(), + user: () => p.manyToOne(Users).primary().ref().index('idx_journey_contributors_user'), + role: p.text(), + addedAt: p.integer(), + hideSkeletons: p.integer(), + }, +}); diff --git a/server/src/db/entities/JourneyEntries.ts b/server/src/db/entities/JourneyEntries.ts new file mode 100644 index 000000000..c1a16b280 --- /dev/null +++ b/server/src/db/entities/JourneyEntries.ts @@ -0,0 +1,81 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { JourneyEntryPhotos } from './JourneyEntryPhotos.js'; +import { Journeys } from './Journeys.js'; +import { Places } from './Places.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class JourneyEntries { + id?: number | null; + journey!: Ref; + sourceTrip?: Ref | null; + sourcePlace?: Ref | null; + author!: Ref; + type!: string; + title?: string | null; + story?: string | null; + entryDate!: string; + entryTime?: string | null; + locationName?: string | null; + locationLat?: unknown | null; + locationLng?: unknown | null; + mood?: string | null; + weather?: string | null; + tags?: string | null; + visibility?: string | null = 'private'; + sortOrder?: number | null = 0; + createdAt!: number; + updatedAt!: number; + prosCons?: string | null; + statsExcluded: number & Opt = 0; + dismissed: number & Opt = 0; + countryCode?: string | null; + sourceAssignmentId?: number | null; + journeyEntryPhotosCollection = new Collection(this); +} + +export class JourneyEntriesRepository extends EntityRepository {} + +export const JourneyEntriesSchema = defineEntity({ + class: JourneyEntries, + repository: () => JourneyEntriesRepository, + indexes: [ + { + name: 'idx_journey_entries_source_assignment', + properties: ['sourcePlace', 'sourceAssignmentId'], + }, + { + name: 'idx_journey_entries_order', + properties: ['journey', 'entryDate', 'sortOrder'], + }, + { name: 'idx_journey_entries_journey', properties: ['journey', 'entryDate'] }, + ], + properties: { + id: p.integer().primary().autoincrement(), + journey: () => p.manyToOne(Journeys).ref().deleteRule('cascade'), + sourceTrip: () => p.manyToOne(Trips).ref().nullable(), + sourcePlace: () => p.manyToOne(Places).ref().nullable().index('idx_journey_entries_source'), + author: () => p.manyToOne(Users).ref(), + type: p.text(), + title: p.text().nullable(), + story: p.text().nullable(), + entryDate: p.text(), + entryTime: p.text().nullable(), + locationName: p.text().nullable(), + locationLat: p.double().nullable(), + locationLng: p.double().nullable(), + mood: p.text().nullable(), + weather: p.text().nullable(), + tags: p.text().nullable(), + visibility: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.integer(), + updatedAt: p.integer(), + prosCons: p.text().nullable(), + statsExcluded: p.integer(), + dismissed: p.integer(), + countryCode: p.text().nullable(), + sourceAssignmentId: p.integer().nullable(), + journeyEntryPhotosCollection: () => p.oneToMany(JourneyEntryPhotos).mappedBy('entry'), + }, +}); diff --git a/server/src/db/entities/JourneyEntryPhotos.ts b/server/src/db/entities/JourneyEntryPhotos.ts new file mode 100644 index 000000000..faaddb690 --- /dev/null +++ b/server/src/db/entities/JourneyEntryPhotos.ts @@ -0,0 +1,24 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { JourneyEntries } from './JourneyEntries.js'; +import { JourneyPhotos } from './JourneyPhotos.js'; + +export class JourneyEntryPhotos { + [PrimaryKeyProp]?: ['entry', 'journeyPhoto']; + entry!: Ref; + journeyPhoto!: Ref; + sortOrder?: number | null = 0; + createdAt!: number; +} + +export class JourneyEntryPhotosRepository extends EntityRepository {} + +export const JourneyEntryPhotosSchema = defineEntity({ + class: JourneyEntryPhotos, + repository: () => JourneyEntryPhotosRepository, + properties: { + entry: () => p.manyToOne(JourneyEntries).primary().ref().index('idx_journey_entry_photos_entry'), + journeyPhoto: () => p.manyToOne(JourneyPhotos).primary().ref().index('idx_journey_entry_photos_photo'), + sortOrder: p.integer().nullable(), + createdAt: p.integer(), + }, +}); diff --git a/server/src/db/entities/JourneyPhotos.ts b/server/src/db/entities/JourneyPhotos.ts new file mode 100644 index 000000000..015e9a067 --- /dev/null +++ b/server/src/db/entities/JourneyPhotos.ts @@ -0,0 +1,38 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { JourneyEntryPhotos } from './JourneyEntryPhotos.js'; +import { Journeys } from './Journeys.js'; +import { TrekPhotos } from './TrekPhotos.js'; + +export class JourneyPhotos { + id?: number | null; + journey!: Ref; + photo!: Ref; + caption?: string | null; + shared?: number | null = 0; + sortOrder?: number | null = 0; + provider?: string | null; + assetId?: string | null; + ownerId?: number | null; + createdAt!: number; + journeyEntryPhotosCollection = new Collection(this); +} + +export class JourneyPhotosRepository extends EntityRepository {} + +export const JourneyPhotosSchema = defineEntity({ + class: JourneyPhotos, + repository: () => JourneyPhotosRepository, + properties: { + id: p.integer().primary().autoincrement(), + journey: () => p.manyToOne(Journeys).ref().deleteRule('cascade').index('idx_journey_photos_journey'), + photo: () => p.manyToOne(TrekPhotos).ref().deleteRule('cascade'), + caption: p.text().nullable(), + shared: p.integer().nullable(), + sortOrder: p.integer().nullable(), + provider: p.text().nullable(), + assetId: p.text().nullable(), + ownerId: p.integer().nullable(), + createdAt: p.integer(), + journeyEntryPhotosCollection: () => p.oneToMany(JourneyEntryPhotos).mappedBy('journeyPhoto'), + }, +}); diff --git a/server/src/db/entities/JourneyShareTokens.ts b/server/src/db/entities/JourneyShareTokens.ts new file mode 100644 index 000000000..51389d342 --- /dev/null +++ b/server/src/db/entities/JourneyShareTokens.ts @@ -0,0 +1,33 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Journeys } from './Journeys.js'; +import { Users } from './Users.js'; + +export class JourneyShareTokens { + id?: number | null; + journey!: Ref; + token!: string; + createdBy!: Ref; + shareTimeline?: number | null = 1; + shareGallery?: number | null = 1; + shareMap?: number | null = 1; + createdAt?: Date | null; + newestFirst: number & Opt = 0; +} + +export class JourneyShareTokensRepository extends EntityRepository {} + +export const JourneyShareTokensSchema = defineEntity({ + class: JourneyShareTokens, + repository: () => JourneyShareTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + journey: () => p.oneToOne(Journeys).ref().deleteRule('cascade').unique('idx_journey_share_journey'), + token: p.text(), + createdBy: () => p.manyToOne(Users).ref().name('created_by'), + shareTimeline: p.integer().nullable(), + shareGallery: p.integer().nullable(), + shareMap: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + newestFirst: p.integer(), + }, +}); diff --git a/server/src/db/entities/JourneyTrips.ts b/server/src/db/entities/JourneyTrips.ts new file mode 100644 index 000000000..7215a53a4 --- /dev/null +++ b/server/src/db/entities/JourneyTrips.ts @@ -0,0 +1,22 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Journeys } from './Journeys.js'; +import { Trips } from './Trips.js'; + +export class JourneyTrips { + [PrimaryKeyProp]?: ['journey', 'trip']; + journey!: Ref; + trip!: Ref; + addedAt!: number; +} + +export class JourneyTripsRepository extends EntityRepository {} + +export const JourneyTripsSchema = defineEntity({ + class: JourneyTrips, + repository: () => JourneyTripsRepository, + properties: { + journey: () => p.manyToOne(Journeys).primary().ref().index('idx_journey_trips_journey'), + trip: () => p.manyToOne(Trips).primary().ref(), + addedAt: p.integer(), + }, +}); diff --git a/server/src/db/entities/Journeys.ts b/server/src/db/entities/Journeys.ts new file mode 100644 index 000000000..ad791c4ed --- /dev/null +++ b/server/src/db/entities/Journeys.ts @@ -0,0 +1,58 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { JourneyBooks } from './JourneyBooks.js'; +import { JourneyContributors } from './JourneyContributors.js'; +import { JourneyEntries } from './JourneyEntries.js'; +import { JourneyPhotos } from './JourneyPhotos.js'; +import { JourneyShareTokens } from './JourneyShareTokens.js'; +import { JourneyTrips } from './JourneyTrips.js'; +import { Users } from './Users.js'; + +export class Journeys { + id?: number | null; + user!: Ref; + title!: string; + subtitle?: string | null; + coverGradient?: string | null; + status?: string | null = 'draft'; + createdAt!: number; + updatedAt!: number; + coverImage?: string | null; + showTripTracks: number & Opt = 0; + showVerdict: number & Opt = 1; + showMood: number & Opt = 1; + showWeather: number & Opt = 1; + journeyBooksCollection = new Collection(this); + journeyContributorsCollection = new Collection(this); + journeyEntriesCollection = new Collection(this); + journeyPhotosCollection = new Collection(this); + journeyShareTokens: Ref | null = null; + journeyTripsCollection = new Collection(this); +} + +export class JourneysRepository extends EntityRepository {} + +export const JourneysSchema = defineEntity({ + class: Journeys, + repository: () => JourneysRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().index('idx_journeys_user'), + title: p.text(), + subtitle: p.text().nullable(), + coverGradient: p.text().nullable(), + status: p.text().nullable(), + createdAt: p.integer(), + updatedAt: p.integer(), + coverImage: p.text().nullable(), + showTripTracks: p.integer(), + showVerdict: p.integer(), + showMood: p.integer(), + showWeather: p.integer(), + journeyBooksCollection: () => p.oneToMany(JourneyBooks).mappedBy('journey'), + journeyContributorsCollection: () => p.oneToMany(JourneyContributors).mappedBy('journey'), + journeyEntriesCollection: () => p.oneToMany(JourneyEntries).mappedBy('journey'), + journeyPhotosCollection: () => p.oneToMany(JourneyPhotos).mappedBy('journey'), + journeyShareTokens: () => p.oneToOne(JourneyShareTokens).ref().mappedBy('journey'), + journeyTripsCollection: () => p.oneToMany(JourneyTrips).mappedBy('journey'), + }, +}); diff --git a/server/src/db/entities/McpTokens.ts b/server/src/db/entities/McpTokens.ts new file mode 100644 index 000000000..7b4f7a97e --- /dev/null +++ b/server/src/db/entities/McpTokens.ts @@ -0,0 +1,34 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class McpTokens { + id?: number | null; + user!: Ref; + name!: string; + tokenHash!: string; + tokenPrefix!: string; + createdAt?: Date | null; + lastUsedAt?: Date | null; + kind: string & Opt = 'mcp'; + scopeMode: string & Opt = 'all'; + apiScopes?: string | null; +} + +export class McpTokensRepository extends EntityRepository {} + +export const McpTokensSchema = defineEntity({ + class: McpTokens, + repository: () => McpTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + name: p.text(), + tokenHash: p.text().unique('idx_mcp_tokens_hash'), + tokenPrefix: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + lastUsedAt: p.datetime().nullable(), + kind: p.text(), + scopeMode: p.text(), + apiScopes: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Migrations.ts b/server/src/db/entities/Migrations.ts new file mode 100644 index 000000000..c8bafc26d --- /dev/null +++ b/server/src/db/entities/Migrations.ts @@ -0,0 +1,19 @@ +import { defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class Migrations { + id!: number; + timestamp!: bigint; + name!: string; +} + +export class MigrationsRepository extends EntityRepository {} + +export const MigrationsSchema = defineEntity({ + class: Migrations, + repository: () => MigrationsRepository, + properties: { + id: p.integer().primary(), + timestamp: p.bigint(), + name: p.string(), + }, +}); diff --git a/server/src/db/entities/NotificationChannelPreferences.ts b/server/src/db/entities/NotificationChannelPreferences.ts new file mode 100644 index 000000000..0fc932ea1 --- /dev/null +++ b/server/src/db/entities/NotificationChannelPreferences.ts @@ -0,0 +1,23 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class NotificationChannelPreferences { + [PrimaryKeyProp]?: ['user', 'eventType', 'channel']; + user!: Ref; + eventType!: string; + channel!: string; + enabled: number & Opt = 1; +} + +export class NotificationChannelPreferencesRepository extends EntityRepository {} + +export const NotificationChannelPreferencesSchema = defineEntity({ + class: NotificationChannelPreferences, + repository: () => NotificationChannelPreferencesRepository, + properties: { + user: () => p.manyToOne(Users).primary().ref().deleteRule('cascade').index('idx_ncp_user'), + eventType: p.text().primary(), + channel: p.text().primary(), + enabled: p.integer(), + }, +}); diff --git a/server/src/db/entities/Notifications.ts b/server/src/db/entities/Notifications.ts new file mode 100644 index 000000000..d0642b17f --- /dev/null +++ b/server/src/db/entities/Notifications.ts @@ -0,0 +1,63 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class Notifications { + id?: number | null; + type!: string; + scope!: string; + target!: number; + sender?: Ref | null; + recipient!: Ref; + titleKey!: string; + titleParams?: string | null = '{}'; + textKey!: string; + textParams?: string | null = '{}'; + positiveTextKey?: string | null; + negativeTextKey?: string | null; + positiveCallback?: string | null; + negativeCallback?: string | null; + response?: string | null; + navigateTextKey?: string | null; + navigateTarget?: string | null; + isRead?: number | null = 0; + createdAt?: Date | null; +} + +export class NotificationsRepository extends EntityRepository {} + +export const NotificationsSchema = defineEntity({ + class: Notifications, + repository: () => NotificationsRepository, + indexes: [ + { name: 'idx_notifications_target_scope', properties: ['target', 'scope'] }, + { + name: 'idx_notifications_recipient_created', + properties: ['recipient', 'createdAt'], + }, + { + name: 'idx_notifications_recipient', + properties: ['recipient', 'isRead', 'createdAt'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + type: p.text(), + scope: p.text(), + target: p.integer(), + sender: () => p.manyToOne(Users).ref().nullable(), + recipient: () => p.manyToOne(Users).ref().deleteRule('cascade'), + titleKey: p.text(), + titleParams: p.text().nullable(), + textKey: p.text(), + textParams: p.text().nullable(), + positiveTextKey: p.text().nullable(), + negativeTextKey: p.text().nullable(), + positiveCallback: p.text().nullable(), + negativeCallback: p.text().nullable(), + response: p.text().nullable(), + navigateTextKey: p.text().nullable(), + navigateTarget: p.text().nullable(), + isRead: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/OauthClients.ts b/server/src/db/entities/OauthClients.ts new file mode 100644 index 000000000..d4875c586 --- /dev/null +++ b/server/src/db/entities/OauthClients.ts @@ -0,0 +1,42 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { OauthConsents } from './OauthConsents.js'; +import { OauthTokens } from './OauthTokens.js'; +import { Users } from './Users.js'; + +export class OauthClients { + id?: string | null; + user?: Ref | null; + name!: string; + clientId!: string; + clientSecretHash!: string; + redirectUris: string & Opt = '[]'; + allowedScopes: string & Opt = '[]'; + createdAt?: Date | null; + isPublic: number & Opt = 0; + createdVia: string & Opt = 'settings_ui'; + allowsClientCredentials: number & Opt = 0; + oauthConsentsCollection = new Collection(this); + oauthTokensCollection = new Collection(this); +} + +export class OauthClientsRepository extends EntityRepository {} + +export const OauthClientsSchema = defineEntity({ + class: OauthClients, + repository: () => OauthClientsRepository, + properties: { + id: p.text().primary().nullable(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').nullable().index('idx_oauth_clients_user'), + name: p.text(), + clientId: p.text().unique('idx_oauth_clients_client_id'), + clientSecretHash: p.text(), + redirectUris: p.text(), + allowedScopes: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + isPublic: p.integer(), + createdVia: p.text(), + allowsClientCredentials: p.integer(), + oauthConsentsCollection: () => p.oneToMany(OauthConsents).mappedBy('client'), + oauthTokensCollection: () => p.oneToMany(OauthTokens).mappedBy('client'), + }, +}); diff --git a/server/src/db/entities/OauthConsents.ts b/server/src/db/entities/OauthConsents.ts new file mode 100644 index 000000000..1fa9b6cbc --- /dev/null +++ b/server/src/db/entities/OauthConsents.ts @@ -0,0 +1,25 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { OauthClients } from './OauthClients.js'; +import { Users } from './Users.js'; + +export class OauthConsents { + id?: number | null; + client!: Ref; + user!: Ref; + scopes: string & Opt = '[]'; + updatedAt?: Date | null; +} + +export class OauthConsentsRepository extends EntityRepository {} + +export const OauthConsentsSchema = defineEntity({ + class: OauthConsents, + repository: () => OauthConsentsRepository, + properties: { + id: p.integer().primary().autoincrement(), + client: () => p.manyToOne(OauthClients).ref().name('client_id').deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + scopes: p.text(), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/OauthTokens.ts b/server/src/db/entities/OauthTokens.ts new file mode 100644 index 000000000..c3a3715c6 --- /dev/null +++ b/server/src/db/entities/OauthTokens.ts @@ -0,0 +1,41 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { OauthClients } from './OauthClients.js'; +import { Users } from './Users.js'; + +export class OauthTokens { + id?: number | null; + client!: Ref; + user!: Ref; + accessTokenHash!: string; + refreshTokenHash!: string; + scopes: string & Opt = '[]'; + accessTokenExpiresAt!: Date; + refreshTokenExpiresAt!: Date; + revokedAt?: Date | null; + createdAt?: Date | null; + parentToken?: Ref | null; + audience?: string | null; + oauthTokensCollection = new Collection(this); +} + +export class OauthTokensRepository extends EntityRepository {} + +export const OauthTokensSchema = defineEntity({ + class: OauthTokens, + repository: () => OauthTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + client: () => p.manyToOne(OauthClients).ref().name('client_id').deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_oauth_tokens_user'), + accessTokenHash: p.text().unique('idx_oauth_tokens_access'), + refreshTokenHash: p.text().unique('idx_oauth_tokens_refresh'), + scopes: p.text(), + accessTokenExpiresAt: p.datetime(), + refreshTokenExpiresAt: p.datetime(), + revokedAt: p.datetime().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + parentToken: () => p.manyToOne(OauthTokens).ref().nullable().index('idx_oauth_tokens_parent'), + audience: p.text().nullable(), + oauthTokensCollection: () => p.oneToMany(OauthTokens).mappedBy('parentToken'), + }, +}); diff --git a/server/src/db/entities/PackingBags.ts b/server/src/db/entities/PackingBags.ts new file mode 100644 index 000000000..503d64070 --- /dev/null +++ b/server/src/db/entities/PackingBags.ts @@ -0,0 +1,36 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingItems } from './PackingItems.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class PackingBags { + id?: number | null; + trip!: Ref; + name!: string; + color: string & Opt = '#6366f1'; + weightLimitGrams?: number | null; + sortOrder?: number | null = 0; + createdAt?: Date | null; + user?: Ref | null; + packingBagMembers = new Collection(this); + packingItemsCollection = new Collection(this); +} + +export class PackingBagsRepository extends EntityRepository {} + +export const PackingBagsSchema = defineEntity({ + class: PackingBags, + repository: () => PackingBagsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + name: p.text(), + color: p.text(), + weightLimitGrams: p.integer().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + user: () => p.manyToOne(Users).ref().nullable(), + packingBagMembers: () => p.manyToMany(Users).pivotTable('packing_bag_members').joinColumn('bag_id').inverseJoinColumn('user_id'), + packingItemsCollection: () => p.oneToMany(PackingItems).mappedBy('bag'), + }, +}); diff --git a/server/src/db/entities/PackingCategoryAssignees.ts b/server/src/db/entities/PackingCategoryAssignees.ts new file mode 100644 index 000000000..7453a8718 --- /dev/null +++ b/server/src/db/entities/PackingCategoryAssignees.ts @@ -0,0 +1,23 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class PackingCategoryAssignees { + id?: number | null; + trip!: Ref; + categoryName!: string; + user!: Ref; +} + +export class PackingCategoryAssigneesRepository extends EntityRepository {} + +export const PackingCategoryAssigneesSchema = defineEntity({ + class: PackingCategoryAssignees, + repository: () => PackingCategoryAssigneesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + categoryName: p.text(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + }, +}); diff --git a/server/src/db/entities/PackingItemContributors.ts b/server/src/db/entities/PackingItemContributors.ts new file mode 100644 index 000000000..f2f0c7d11 --- /dev/null +++ b/server/src/db/entities/PackingItemContributors.ts @@ -0,0 +1,24 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingItems } from './PackingItems.js'; +import { Users } from './Users.js'; + +export class PackingItemContributors { + [PrimaryKeyProp]?: ['item', 'user']; + item!: Ref; + user!: Ref; + status: string & Opt = 'accepted'; + createdAt?: Date | null; +} + +export class PackingItemContributorsRepository extends EntityRepository {} + +export const PackingItemContributorsSchema = defineEntity({ + class: PackingItemContributors, + repository: () => PackingItemContributorsRepository, + properties: { + item: () => p.manyToOne(PackingItems).primary().ref(), + user: () => p.manyToOne(Users).primary().ref(), + status: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/PackingItems.ts b/server/src/db/entities/PackingItems.ts new file mode 100644 index 000000000..15be649ca --- /dev/null +++ b/server/src/db/entities/PackingItems.ts @@ -0,0 +1,49 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingBags } from './PackingBags.js'; +import { PackingItemContributors } from './PackingItemContributors.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class PackingItems { + id?: number | null; + trip!: Ref; + name!: string; + checked?: number | null = 0; + category?: string | null; + sortOrder?: number | null = 0; + createdAt?: Date | null; + weightGrams?: number | null; + bag?: Ref | null; + quantity: number & Opt = 1; + updatedAt?: Date | null; + isPrivate: number & Opt = 0; + owner?: Ref | null; + packingItemContributors = new Collection(this); + packingItemRecipients = new Collection(this); + packingItemContributorsCollection = new Collection(this); +} + +export class PackingItemsRepository extends EntityRepository {} + +export const PackingItemsSchema = defineEntity({ + class: PackingItems, + repository: () => PackingItemsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_packing_items_trip_id'), + name: p.text(), + checked: p.integer().nullable(), + category: p.text().nullable(), + sortOrder: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + weightGrams: p.integer().nullable(), + bag: () => p.manyToOne(PackingBags).ref().nullable(), + quantity: p.integer(), + updatedAt: p.datetime().nullable(), + isPrivate: p.integer(), + owner: () => p.manyToOne(Users).ref().nullable(), + packingItemContributors: () => p.manyToMany(Users).pivotTable('packing_item_contributors').pivotEntity(() => PackingItemContributors).joinColumn('item_id').inverseJoinColumn('user_id'), + packingItemRecipients: () => p.manyToMany(Users).pivotTable('packing_item_recipients').joinColumn('item_id').inverseJoinColumn('user_id'), + packingItemContributorsCollection: () => p.oneToMany(PackingItemContributors).mappedBy('item'), + }, +}); diff --git a/server/src/db/entities/PackingTemplateCategories.ts b/server/src/db/entities/PackingTemplateCategories.ts new file mode 100644 index 000000000..d6f2b92dd --- /dev/null +++ b/server/src/db/entities/PackingTemplateCategories.ts @@ -0,0 +1,25 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingTemplateItems } from './PackingTemplateItems.js'; +import { PackingTemplates } from './PackingTemplates.js'; + +export class PackingTemplateCategories { + id?: number | null; + template!: Ref; + name!: string; + sortOrder: number & Opt = 0; + packingTemplateItemsCollection = new Collection(this); +} + +export class PackingTemplateCategoriesRepository extends EntityRepository {} + +export const PackingTemplateCategoriesSchema = defineEntity({ + class: PackingTemplateCategories, + repository: () => PackingTemplateCategoriesRepository, + properties: { + id: p.integer().primary().autoincrement(), + template: () => p.manyToOne(PackingTemplates).ref().deleteRule('cascade'), + name: p.text(), + sortOrder: p.integer(), + packingTemplateItemsCollection: () => p.oneToMany(PackingTemplateItems).mappedBy('category'), + }, +}); diff --git a/server/src/db/entities/PackingTemplateItems.ts b/server/src/db/entities/PackingTemplateItems.ts new file mode 100644 index 000000000..f58539c4c --- /dev/null +++ b/server/src/db/entities/PackingTemplateItems.ts @@ -0,0 +1,22 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingTemplateCategories } from './PackingTemplateCategories.js'; + +export class PackingTemplateItems { + id?: number | null; + category!: Ref; + name!: string; + sortOrder: number & Opt = 0; +} + +export class PackingTemplateItemsRepository extends EntityRepository {} + +export const PackingTemplateItemsSchema = defineEntity({ + class: PackingTemplateItems, + repository: () => PackingTemplateItemsRepository, + properties: { + id: p.integer().primary().autoincrement(), + category: () => p.manyToOne(PackingTemplateCategories).ref().deleteRule('cascade'), + name: p.text(), + sortOrder: p.integer(), + }, +}); diff --git a/server/src/db/entities/PackingTemplates.ts b/server/src/db/entities/PackingTemplates.ts new file mode 100644 index 000000000..e8a20de70 --- /dev/null +++ b/server/src/db/entities/PackingTemplates.ts @@ -0,0 +1,25 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PackingTemplateCategories } from './PackingTemplateCategories.js'; +import { Users } from './Users.js'; + +export class PackingTemplates { + id?: number | null; + name!: string; + createdBy!: Ref; + createdAt?: Date | null; + packingTemplateCategoriesCollection = new Collection(this); +} + +export class PackingTemplatesRepository extends EntityRepository {} + +export const PackingTemplatesSchema = defineEntity({ + class: PackingTemplates, + repository: () => PackingTemplatesRepository, + properties: { + id: p.integer().primary().autoincrement(), + name: p.text(), + createdBy: () => p.manyToOne(Users).ref().name('created_by').deleteRule('cascade'), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + packingTemplateCategoriesCollection: () => p.oneToMany(PackingTemplateCategories).mappedBy('template'), + }, +}); diff --git a/server/src/db/entities/PasswordResetTokens.ts b/server/src/db/entities/PasswordResetTokens.ts new file mode 100644 index 000000000..da9575c22 --- /dev/null +++ b/server/src/db/entities/PasswordResetTokens.ts @@ -0,0 +1,28 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class PasswordResetTokens { + id?: number | null; + user!: Ref; + tokenHash!: string; + expiresAt!: Date; + consumedAt?: Date | null; + createdAt?: Date | null; + createdIp?: string | null; +} + +export class PasswordResetTokensRepository extends EntityRepository {} + +export const PasswordResetTokensSchema = defineEntity({ + class: PasswordResetTokens, + repository: () => PasswordResetTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_prt_user'), + tokenHash: p.text().index('idx_prt_hash'), + expiresAt: p.datetime(), + consumedAt: p.datetime().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + createdIp: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/PhotoProviderFields.ts b/server/src/db/entities/PhotoProviderFields.ts new file mode 100644 index 000000000..926d89b54 --- /dev/null +++ b/server/src/db/entities/PhotoProviderFields.ts @@ -0,0 +1,38 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PhotoProviders } from './PhotoProviders.js'; + +export class PhotoProviderFields { + id?: number | null; + provider!: Ref; + fieldKey!: string; + label!: string; + inputType: string & Opt = 'text'; + placeholder?: string | null; + hint?: string | null; + required?: number | null = 0; + secret?: number | null = 0; + settingsKey?: string | null; + payloadKey?: string | null; + sortOrder?: number | null = 0; +} + +export class PhotoProviderFieldsRepository extends EntityRepository {} + +export const PhotoProviderFieldsSchema = defineEntity({ + class: PhotoProviderFields, + repository: () => PhotoProviderFieldsRepository, + properties: { + id: p.integer().primary().autoincrement(), + provider: () => p.manyToOne(PhotoProviders).ref().deleteRule('cascade'), + fieldKey: p.text(), + label: p.text(), + inputType: p.text(), + placeholder: p.text().nullable(), + hint: p.text().nullable(), + required: p.integer().nullable(), + secret: p.integer().nullable(), + settingsKey: p.text().nullable(), + payloadKey: p.text().nullable(), + sortOrder: p.integer().nullable(), + }, +}); diff --git a/server/src/db/entities/PhotoProviders.ts b/server/src/db/entities/PhotoProviders.ts new file mode 100644 index 000000000..8cd055b1f --- /dev/null +++ b/server/src/db/entities/PhotoProviders.ts @@ -0,0 +1,28 @@ +import { Collection, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { PhotoProviderFields } from './PhotoProviderFields.js'; + +export class PhotoProviders { + id?: string | null; + name!: string; + description?: string | null; + icon?: string | null = 'Image'; + enabled?: number | null = 0; + sortOrder?: number | null = 0; + photoProviderFieldsCollection = new Collection(this); +} + +export class PhotoProvidersRepository extends EntityRepository {} + +export const PhotoProvidersSchema = defineEntity({ + class: PhotoProviders, + repository: () => PhotoProvidersRepository, + properties: { + id: p.text().primary().nullable(), + name: p.text(), + description: p.text().nullable(), + icon: p.text().nullable(), + enabled: p.integer().nullable(), + sortOrder: p.integer().nullable(), + photoProviderFieldsCollection: () => p.oneToMany(PhotoProviderFields).mappedBy('provider'), + }, +}); diff --git a/server/src/db/entities/Photos.ts b/server/src/db/entities/Photos.ts new file mode 100644 index 000000000..0eed4ac35 --- /dev/null +++ b/server/src/db/entities/Photos.ts @@ -0,0 +1,38 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; +import { Places } from './Places.js'; +import { Trips } from './Trips.js'; + +export class Photos { + id?: number | null; + trip!: Ref; + day?: Ref | null; + place?: Ref | null; + filename!: string; + originalName!: string; + fileSize?: number | null; + mimeType?: string | null; + caption?: string | null; + takenAt?: string | null; + createdAt?: Date | null; +} + +export class PhotosRepository extends EntityRepository {} + +export const PhotosSchema = defineEntity({ + class: Photos, + repository: () => PhotosRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_photos_trip_id'), + day: () => p.manyToOne(Days).ref().nullable().index('idx_photos_day_id'), + place: () => p.manyToOne(Places).ref().nullable().index('idx_photos_place_id'), + filename: p.text(), + originalName: p.text(), + fileSize: p.integer().nullable(), + mimeType: p.text().nullable(), + caption: p.text().nullable(), + takenAt: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/PlaceDetailsCache.ts b/server/src/db/entities/PlaceDetailsCache.ts new file mode 100644 index 000000000..dc51de62e --- /dev/null +++ b/server/src/db/entities/PlaceDetailsCache.ts @@ -0,0 +1,24 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PlaceDetailsCache { + [PrimaryKeyProp]?: ['placeId', 'lang', 'expanded']; + placeId!: string; + lang: string & Opt = ''; + expanded: number & Opt = 0; + payloadJson!: string; + fetchedAt!: number; +} + +export class PlaceDetailsCacheRepository extends EntityRepository {} + +export const PlaceDetailsCacheSchema = defineEntity({ + class: PlaceDetailsCache, + repository: () => PlaceDetailsCacheRepository, + properties: { + placeId: p.text().primary(), + lang: p.text().primary(), + expanded: p.integer().primary(), + payloadJson: p.text(), + fetchedAt: p.integer(), + }, +}); diff --git a/server/src/db/entities/PlaceRatings.ts b/server/src/db/entities/PlaceRatings.ts new file mode 100644 index 000000000..948f58998 --- /dev/null +++ b/server/src/db/entities/PlaceRatings.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Places } from './Places.js'; +import { Users } from './Users.js'; + +export class PlaceRatings { + id?: number | null; + place!: Ref; + user!: Ref; + rating!: number; + createdAt?: Date | null; +} + +export class PlaceRatingsRepository extends EntityRepository {} + +export const PlaceRatingsSchema = defineEntity({ + class: PlaceRatings, + repository: () => PlaceRatingsRepository, + properties: { + id: p.integer().primary().autoincrement(), + place: () => p.manyToOne(Places).ref().deleteRule('cascade').index('idx_place_ratings_place'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + rating: p.integer(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/PlaceRegions.ts b/server/src/db/entities/PlaceRegions.ts new file mode 100644 index 000000000..cbebcf6c6 --- /dev/null +++ b/server/src/db/entities/PlaceRegions.ts @@ -0,0 +1,23 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Places } from './Places.js'; + +export class PlaceRegions { + [PrimaryKeyProp]?: 'place'; + place?: Ref | null; + countryCode!: string; + regionCode!: string; + regionName!: string; +} + +export class PlaceRegionsRepository extends EntityRepository {} + +export const PlaceRegionsSchema = defineEntity({ + class: PlaceRegions, + repository: () => PlaceRegionsRepository, + properties: { + place: () => p.oneToOne(Places).primary().ref().nullable(), + countryCode: p.text().index('idx_place_regions_country'), + regionCode: p.text().index('idx_place_regions_region'), + regionName: p.text(), + }, +}); diff --git a/server/src/db/entities/PlaceShadowPicks.ts b/server/src/db/entities/PlaceShadowPicks.ts new file mode 100644 index 000000000..ada709086 --- /dev/null +++ b/server/src/db/entities/PlaceShadowPicks.ts @@ -0,0 +1,39 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PlaceShadowPicks { + id?: number | null; + createdAt!: string & Opt; + query!: string; + lang?: string | null; + biasLat?: unknown | null; + biasLng?: unknown | null; + source!: string; + liveRank!: number; + liveCount!: number; + pickedName!: string; + pickedLat!: unknown; + pickedLng!: unknown; + pickedPlaceId?: string | null; +} + +export class PlaceShadowPicksRepository extends EntityRepository {} + +export const PlaceShadowPicksSchema = defineEntity({ + class: PlaceShadowPicks, + repository: () => PlaceShadowPicksRepository, + properties: { + id: p.integer().primary().autoincrement(), + createdAt: p.text().defaultRaw(`(datetime('now'))`).index('idx_place_shadow_created'), + query: p.text(), + lang: p.text().nullable(), + biasLat: p.double().nullable(), + biasLng: p.double().nullable(), + source: p.text(), + liveRank: p.integer(), + liveCount: p.integer(), + pickedName: p.text(), + pickedLat: p.double(), + pickedLng: p.double(), + pickedPlaceId: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Places.ts b/server/src/db/entities/Places.ts new file mode 100644 index 000000000..6afef97aa --- /dev/null +++ b/server/src/db/entities/Places.ts @@ -0,0 +1,118 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetItems } from './BudgetItems.js'; +import { Categories } from './Categories.js'; +import { DawarichVisitSuggestions } from './DawarichVisitSuggestions.js'; +import { DayAccommodations } from './DayAccommodations.js'; +import { DayAssignments } from './DayAssignments.js'; +import { FileLinks } from './FileLinks.js'; +import { JourneyEntries } from './JourneyEntries.js'; +import { Photos } from './Photos.js'; +import { PlaceRatings } from './PlaceRatings.js'; +import { PlaceRegions } from './PlaceRegions.js'; +import { Reservations } from './Reservations.js'; +import { RoadtripDayTracks } from './RoadtripDayTracks.js'; +import { Tags } from './Tags.js'; +import { TripFiles } from './TripFiles.js'; +import { Trips } from './Trips.js'; + +export class Places { + id?: number | null; + trip!: Ref; + name!: string; + description?: string | null; + lat?: unknown | null; + lng?: unknown | null; + address?: string | null; + category?: Ref | null; + price?: unknown | null; + currency?: string | null; + reservationStatus?: string | null = 'none'; + reservationNotes?: string | null; + reservationDatetime?: string | null; + placeTime?: string | null; + endTime?: string | null; + durationMinutes?: number | null = 60; + notes?: string | null; + imageUrl?: string | null; + googlePlaceId?: string | null; + googleFtid?: string | null; + website?: string | null; + phone?: string | null; + transportMode?: string | null = 'walking'; + createdAt?: Date | null; + updatedAt?: Date | null; + osmId?: string | null; + routeGeometry?: string | null; + routeColor?: string | null; + stopType?: string | null; + fillPercent?: number | null; + amapPoiId?: string | null; + source?: string | null; + placeTags = new Collection(this); + budgetItemsCollection = new Collection(this); + dawarichVisitSuggestionsCollection = new Collection(this); + dayAccommodationsCollection = new Collection(this); + dayAssignmentsCollection = new Collection(this); + fileLinksCollection = new Collection(this); + journeyEntriesCollection = new Collection(this); + photosCollection = new Collection(this); + placeRatingsCollection = new Collection(this); + placeRegions: Ref | null = null; + reservationsCollection = new Collection(this); + roadtripDayTracksCollection = new Collection(this); + tripFilesCollection = new Collection(this); +} + +export class PlacesRepository extends EntityRepository {} + +export const PlacesSchema = defineEntity({ + class: Places, + repository: () => PlacesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_places_trip_id'), + name: p.text(), + description: p.text().nullable(), + lat: p.double().nullable(), + lng: p.double().nullable(), + address: p.text().nullable(), + category: () => p.manyToOne(Categories).ref().nullable().index('idx_places_category_id'), + price: p.double().nullable(), + currency: p.text().nullable(), + reservationStatus: p.text().nullable(), + reservationNotes: p.text().nullable(), + reservationDatetime: p.text().nullable(), + placeTime: p.text().nullable(), + endTime: p.text().nullable(), + durationMinutes: p.integer().nullable(), + notes: p.text().nullable(), + imageUrl: p.text().nullable(), + googlePlaceId: p.text().nullable(), + googleFtid: p.text().nullable(), + website: p.text().nullable(), + phone: p.text().nullable(), + transportMode: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + osmId: p.text().nullable(), + routeGeometry: p.text().nullable(), + routeColor: p.text().nullable(), + stopType: p.text().nullable(), + fillPercent: p.integer().nullable(), + amapPoiId: p.text().nullable(), + source: p.text().nullable(), + placeTags: () => p.manyToMany(Tags).pivotTable('place_tags').joinColumn('place_id').inverseJoinColumn('tag_id'), + budgetItemsCollection: () => p.oneToMany(BudgetItems).mappedBy('place'), + dawarichVisitSuggestionsCollection: () => p.oneToMany(DawarichVisitSuggestions).mappedBy('acceptedPlace'), + dayAccommodationsCollection: () => p.oneToMany(DayAccommodations).mappedBy('place'), + dayAssignmentsCollection: () => p.oneToMany(DayAssignments).mappedBy('place'), + fileLinksCollection: () => p.oneToMany(FileLinks).mappedBy('place'), + journeyEntriesCollection: () => p.oneToMany(JourneyEntries).mappedBy('sourcePlace'), + photosCollection: () => p.oneToMany(Photos).mappedBy('place'), + placeRatingsCollection: () => p.oneToMany(PlaceRatings).mappedBy('place'), + placeRegions: () => p.oneToOne(PlaceRegions).ref().mappedBy('place'), + reservationsCollection: () => p.oneToMany(Reservations).mappedBy('place'), + roadtripDayTracksCollection: () => p.oneToMany(RoadtripDayTracks).mappedBy('place'), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('place'), + }, +}); diff --git a/server/src/db/entities/PluginActions.ts b/server/src/db/entities/PluginActions.ts new file mode 100644 index 000000000..3bbe7e6e8 --- /dev/null +++ b/server/src/db/entities/PluginActions.ts @@ -0,0 +1,28 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginActions { + [PrimaryKeyProp]?: ['pluginId', 'actionKey']; + pluginId!: string; + actionKey!: string; + label!: string; + hint?: string | null; + danger: number & Opt = 0; + sortOrder: number & Opt = 0; + scope: string & Opt = 'user'; +} + +export class PluginActionsRepository extends EntityRepository {} + +export const PluginActionsSchema = defineEntity({ + class: PluginActions, + repository: () => PluginActionsRepository, + properties: { + pluginId: p.text().primary(), + actionKey: p.text().primary(), + label: p.text(), + hint: p.text().nullable(), + danger: p.integer(), + sortOrder: p.integer(), + scope: p.text(), + }, +}); diff --git a/server/src/db/entities/PluginCapabilityAudit.ts b/server/src/db/entities/PluginCapabilityAudit.ts new file mode 100644 index 000000000..4dc8147de --- /dev/null +++ b/server/src/db/entities/PluginCapabilityAudit.ts @@ -0,0 +1,32 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginCapabilityAudit { + id?: number | null; + pluginId!: string; + actingUserId?: number | null; + method!: string; + resource?: string | null; + code!: string; + ts!: string & Opt; + prevHash?: string | null; + hash!: string; +} + +export class PluginCapabilityAuditRepository extends EntityRepository {} + +export const PluginCapabilityAuditSchema = defineEntity({ + class: PluginCapabilityAudit, + repository: () => PluginCapabilityAuditRepository, + indexes: [{ name: 'idx_plugin_audit_plugin', properties: ['pluginId', 'id'] }], + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text(), + actingUserId: p.integer().nullable(), + method: p.text(), + resource: p.text().nullable(), + code: p.text(), + ts: p.text().defaultRaw(`(datetime('now'))`), + prevHash: p.text().nullable(), + hash: p.text(), + }, +}); diff --git a/server/src/db/entities/PluginEgressHosts.ts b/server/src/db/entities/PluginEgressHosts.ts new file mode 100644 index 000000000..b20f368e8 --- /dev/null +++ b/server/src/db/entities/PluginEgressHosts.ts @@ -0,0 +1,21 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginEgressHosts { + id?: number | null; + pluginId!: string; + host!: string; + createdAt!: string & Opt; +} + +export class PluginEgressHostsRepository extends EntityRepository {} + +export const PluginEgressHostsSchema = defineEntity({ + class: PluginEgressHosts, + repository: () => PluginEgressHostsRepository, + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text().index('idx_plugin_egress_hosts_plugin'), + host: p.text(), + createdAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/PluginEntityMetadata.ts b/server/src/db/entities/PluginEntityMetadata.ts new file mode 100644 index 000000000..0458975df --- /dev/null +++ b/server/src/db/entities/PluginEntityMetadata.ts @@ -0,0 +1,33 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginEntityMetadata { + id?: number | null; + pluginId!: string; + entityType!: string; + entityId!: number; + key!: string; + value?: string | null; + updatedAt!: string & Opt; +} + +export class PluginEntityMetadataRepository extends EntityRepository {} + +export const PluginEntityMetadataSchema = defineEntity({ + class: PluginEntityMetadata, + repository: () => PluginEntityMetadataRepository, + indexes: [ + { + name: 'idx_plugin_meta_entity', + properties: ['pluginId', 'entityType', 'entityId'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text(), + entityType: p.text(), + entityId: p.integer(), + key: p.text(), + value: p.text().nullable(), + updatedAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/PluginErrorLog.ts b/server/src/db/entities/PluginErrorLog.ts new file mode 100644 index 000000000..7f754546d --- /dev/null +++ b/server/src/db/entities/PluginErrorLog.ts @@ -0,0 +1,28 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginErrorLog { + id?: number | null; + pluginId!: string; + ts?: Date | null; + level: string & Opt = 'error'; + message?: string | null; + stack?: string | null; +} + +export class PluginErrorLogRepository extends EntityRepository {} + +export const PluginErrorLogSchema = defineEntity({ + class: PluginErrorLog, + repository: () => PluginErrorLogRepository, + indexes: [ + { name: 'idx_plugin_error_log_plugin', properties: ['pluginId', 'ts'] }, + ], + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text(), + ts: p.datetime().nullable().onCreate(() => new Date()), + level: p.text(), + message: p.text().nullable(), + stack: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/PluginMetaMigrations.ts b/server/src/db/entities/PluginMetaMigrations.ts new file mode 100644 index 000000000..d0dbfa1d1 --- /dev/null +++ b/server/src/db/entities/PluginMetaMigrations.ts @@ -0,0 +1,20 @@ +import { PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginMetaMigrations { + [PrimaryKeyProp]?: ['pluginId', 'migrationId']; + pluginId!: string; + migrationId!: string; + appliedAt?: Date | null; +} + +export class PluginMetaMigrationsRepository extends EntityRepository {} + +export const PluginMetaMigrationsSchema = defineEntity({ + class: PluginMetaMigrations, + repository: () => PluginMetaMigrationsRepository, + properties: { + pluginId: p.text().primary(), + migrationId: p.text().primary(), + appliedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/PluginOauthState.ts b/server/src/db/entities/PluginOauthState.ts new file mode 100644 index 000000000..4e96c788f --- /dev/null +++ b/server/src/db/entities/PluginOauthState.ts @@ -0,0 +1,24 @@ +import { PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginOauthState { + [PrimaryKeyProp]?: 'state'; + state?: string | null; + pluginId!: string; + userId!: number; + verifier!: string; + createdAt!: number; +} + +export class PluginOauthStateRepository extends EntityRepository {} + +export const PluginOauthStateSchema = defineEntity({ + class: PluginOauthState, + repository: () => PluginOauthStateRepository, + properties: { + state: p.text().primary().nullable(), + pluginId: p.text(), + userId: p.integer(), + verifier: p.text(), + createdAt: p.integer(), + }, +}); diff --git a/server/src/db/entities/PluginOauthTokens.ts b/server/src/db/entities/PluginOauthTokens.ts new file mode 100644 index 000000000..0b14289c2 --- /dev/null +++ b/server/src/db/entities/PluginOauthTokens.ts @@ -0,0 +1,28 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginOauthTokens { + [PrimaryKeyProp]?: ['pluginId', 'userId']; + pluginId!: string; + userId!: number; + accessToken?: string | null; + refreshToken?: string | null; + expiresAt?: number | null; + scope?: string | null; + updatedAt!: string & Opt; +} + +export class PluginOauthTokensRepository extends EntityRepository {} + +export const PluginOauthTokensSchema = defineEntity({ + class: PluginOauthTokens, + repository: () => PluginOauthTokensRepository, + properties: { + pluginId: p.text().primary(), + userId: p.integer().primary(), + accessToken: p.text().nullable(), + refreshToken: p.text().nullable(), + expiresAt: p.integer().nullable(), + scope: p.text().nullable(), + updatedAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/PluginScheduledTasks.ts b/server/src/db/entities/PluginScheduledTasks.ts new file mode 100644 index 000000000..cc73d7dd1 --- /dev/null +++ b/server/src/db/entities/PluginScheduledTasks.ts @@ -0,0 +1,27 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginScheduledTasks { + id?: number | null; + pluginId!: string; + name!: string; + dueAt!: number; + payload: string & Opt = 'null'; + everyMs?: number | null; + createdAt!: string & Opt; +} + +export class PluginScheduledTasksRepository extends EntityRepository {} + +export const PluginScheduledTasksSchema = defineEntity({ + class: PluginScheduledTasks, + repository: () => PluginScheduledTasksRepository, + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text(), + name: p.text(), + dueAt: p.integer().index('idx_plugin_sched_due'), + payload: p.text(), + everyMs: p.integer().nullable(), + createdAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/PluginSettingsFields.ts b/server/src/db/entities/PluginSettingsFields.ts new file mode 100644 index 000000000..ba1333a04 --- /dev/null +++ b/server/src/db/entities/PluginSettingsFields.ts @@ -0,0 +1,41 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginSettingsFields { + id?: number | null; + pluginId!: string; + fieldKey!: string; + label?: string | null; + inputType: string & Opt = 'text'; + placeholder?: string | null; + hint?: string | null; + required: number & Opt = 0; + secret: number & Opt = 0; + scope: string & Opt = 'instance'; + options?: string | null; + oauthConfig?: string | null; + sortOrder: number & Opt = 0; + defaultValue?: string | null; +} + +export class PluginSettingsFieldsRepository extends EntityRepository {} + +export const PluginSettingsFieldsSchema = defineEntity({ + class: PluginSettingsFields, + repository: () => PluginSettingsFieldsRepository, + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text(), + fieldKey: p.text(), + label: p.text().nullable(), + inputType: p.text(), + placeholder: p.text().nullable(), + hint: p.text().nullable(), + required: p.integer(), + secret: p.integer(), + scope: p.text(), + options: p.text().nullable(), + oauthConfig: p.text().nullable(), + sortOrder: p.integer(), + defaultValue: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/PluginUserConfig.ts b/server/src/db/entities/PluginUserConfig.ts new file mode 100644 index 000000000..1694aff15 --- /dev/null +++ b/server/src/db/entities/PluginUserConfig.ts @@ -0,0 +1,22 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginUserConfig { + [PrimaryKeyProp]?: ['pluginId', 'userId']; + pluginId!: string; + userId!: number; + config: string & Opt = '{}'; + updatedAt!: string & Opt; +} + +export class PluginUserConfigRepository extends EntityRepository {} + +export const PluginUserConfigSchema = defineEntity({ + class: PluginUserConfig, + repository: () => PluginUserConfigRepository, + properties: { + pluginId: p.text().primary(), + userId: p.integer().primary(), + config: p.text(), + updatedAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/PluginUserErasureQueue.ts b/server/src/db/entities/PluginUserErasureQueue.ts new file mode 100644 index 000000000..a7abbc911 --- /dev/null +++ b/server/src/db/entities/PluginUserErasureQueue.ts @@ -0,0 +1,21 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class PluginUserErasureQueue { + id?: number | null; + pluginId!: string; + userId!: number; + createdAt!: string & Opt; +} + +export class PluginUserErasureQueueRepository extends EntityRepository {} + +export const PluginUserErasureQueueSchema = defineEntity({ + class: PluginUserErasureQueue, + repository: () => PluginUserErasureQueueRepository, + properties: { + id: p.integer().primary().autoincrement(), + pluginId: p.text().index('idx_plugin_erasure_plugin'), + userId: p.integer(), + createdAt: p.text().defaultRaw(`(datetime('now'))`), + }, +}); diff --git a/server/src/db/entities/Plugins.ts b/server/src/db/entities/Plugins.ts new file mode 100644 index 000000000..64977e99a --- /dev/null +++ b/server/src/db/entities/Plugins.ts @@ -0,0 +1,75 @@ +import { type Opt, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class Plugins { + id?: string | null; + name!: string; + description?: string | null; + type: string & Opt = 'integration'; + icon?: string | null = 'Blocks'; + version?: string | null; + apiVersion?: number | null = 1; + minTrekVersion?: string | null; + permissions?: string | null = '[]'; + grantedPermissions?: string | null = '[]'; + status: string & Opt = 'inactive'; + config?: string | null = '{}'; + sourceRepo?: string | null; + sourceCommit?: string | null; + sha256?: string | null; + crashCount: number & Opt = 0; + lastError?: string | null; + reviewedAt?: string | null; + sortOrder: number & Opt = 0; + installedAt?: Date | null; + updatedAt?: Date | null; + enabled: number & Opt = 0; + capabilities: string & Opt = '{}'; + authorPubkey?: string | null; + dependencies: string & Opt = '{}'; + operatorEgress: number & Opt = 0; + updateBlockCode?: string | null; + updateBlockDetail?: string | null; + updateBlockVersion?: string | null; + trekRange?: string | null; + updateHold: number & Opt = 0; +} + +export class PluginsRepository extends EntityRepository {} + +export const PluginsSchema = defineEntity({ + class: Plugins, + repository: () => PluginsRepository, + properties: { + id: p.text().primary().nullable(), + name: p.text(), + description: p.text().nullable(), + type: p.text(), + icon: p.text().nullable(), + version: p.text().nullable(), + apiVersion: p.integer().nullable(), + minTrekVersion: p.text().nullable(), + permissions: p.text().nullable(), + grantedPermissions: p.text().nullable(), + status: p.text(), + config: p.text().nullable(), + sourceRepo: p.text().nullable(), + sourceCommit: p.text().nullable(), + sha256: p.text().nullable(), + crashCount: p.integer(), + lastError: p.text().nullable(), + reviewedAt: p.text().nullable(), + sortOrder: p.integer(), + installedAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + enabled: p.integer(), + capabilities: p.text(), + authorPubkey: p.text().nullable(), + dependencies: p.text(), + operatorEgress: p.integer(), + updateBlockCode: p.text().nullable(), + updateBlockDetail: p.text().nullable(), + updateBlockVersion: p.text().nullable(), + trekRange: p.text().nullable(), + updateHold: p.integer(), + }, +}); diff --git a/server/src/db/entities/ReservationDayPositions.ts b/server/src/db/entities/ReservationDayPositions.ts new file mode 100644 index 000000000..28cec8e94 --- /dev/null +++ b/server/src/db/entities/ReservationDayPositions.ts @@ -0,0 +1,22 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; +import { Reservations } from './Reservations.js'; + +export class ReservationDayPositions { + [PrimaryKeyProp]?: ['reservation', 'day']; + reservation!: Ref; + day!: Ref; + position!: unknown; +} + +export class ReservationDayPositionsRepository extends EntityRepository {} + +export const ReservationDayPositionsSchema = defineEntity({ + class: ReservationDayPositions, + repository: () => ReservationDayPositionsRepository, + properties: { + reservation: () => p.manyToOne(Reservations).primary().ref(), + day: () => p.manyToOne(Days).primary().ref(), + position: p.double(), + }, +}); diff --git a/server/src/db/entities/ReservationEndpoints.ts b/server/src/db/entities/ReservationEndpoints.ts new file mode 100644 index 000000000..517d70dc5 --- /dev/null +++ b/server/src/db/entities/ReservationEndpoints.ts @@ -0,0 +1,38 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Reservations } from './Reservations.js'; + +export class ReservationEndpoints { + id?: number | null; + reservation!: Ref; + role!: string; + sequence: number & Opt = 0; + name!: string; + code?: string | null; + lat!: unknown; + lng!: unknown; + timezone?: string | null; + localTime?: string | null; + localDate?: string | null; + createdAt?: Date | null; +} + +export class ReservationEndpointsRepository extends EntityRepository {} + +export const ReservationEndpointsSchema = defineEntity({ + class: ReservationEndpoints, + repository: () => ReservationEndpointsRepository, + properties: { + id: p.integer().primary().autoincrement(), + reservation: () => p.manyToOne(Reservations).ref().deleteRule('cascade').index('idx_reservation_endpoints_reservation_id'), + role: p.text(), + sequence: p.integer(), + name: p.text(), + code: p.text().nullable(), + lat: p.double(), + lng: p.double(), + timezone: p.text().nullable(), + localTime: p.text().nullable(), + localDate: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/ReservationTravelers.ts b/server/src/db/entities/ReservationTravelers.ts new file mode 100644 index 000000000..b69fb9135 --- /dev/null +++ b/server/src/db/entities/ReservationTravelers.ts @@ -0,0 +1,21 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Reservations } from './Reservations.js'; +import { Users } from './Users.js'; + +export class ReservationTravelers { + id?: number | null; + reservation!: Ref; + user!: Ref; +} + +export class ReservationTravelersRepository extends EntityRepository {} + +export const ReservationTravelersSchema = defineEntity({ + class: ReservationTravelers, + repository: () => ReservationTravelersRepository, + properties: { + id: p.integer().primary().autoincrement(), + reservation: () => p.manyToOne(Reservations).ref().index('idx_reservation_travelers_res'), + user: () => p.manyToOne(Users).ref().index('idx_reservation_travelers_user'), + }, +}); diff --git a/server/src/db/entities/Reservations.ts b/server/src/db/entities/Reservations.ts new file mode 100644 index 000000000..678e288a2 --- /dev/null +++ b/server/src/db/entities/Reservations.ts @@ -0,0 +1,95 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetItems } from './BudgetItems.js'; +import { DayAssignments } from './DayAssignments.js'; +import { Days } from './Days.js'; +import { FileLinks } from './FileLinks.js'; +import { Places } from './Places.js'; +import { ReservationDayPositions } from './ReservationDayPositions.js'; +import { ReservationEndpoints } from './ReservationEndpoints.js'; +import { ReservationTravelers } from './ReservationTravelers.js'; +import { TripFiles } from './TripFiles.js'; +import { Trips } from './Trips.js'; + +export class Reservations { + id?: number | null; + trip!: Ref; + day?: Ref | null; + endDay?: Ref | null; + place?: Ref | null; + assignment?: Ref | null; + title!: string; + accommodationId?: string | null; + reservationTime?: string | null; + reservationEndTime?: string | null; + location?: string | null; + confirmationNumber?: string | null; + notes?: string | null; + status?: string | null = 'pending'; + type?: string | null = 'other'; + createdAt?: Date | null; + metadata?: string | null; + dayPlanPosition?: unknown | null; + needsReview: number & Opt = 0; + externalSource?: string | null; + externalId?: string | null; + externalOwnerUserId?: number | null; + externalSyncedAt?: string | null; + syncEnabled?: number | null = 1; + externalHash?: string | null; + url?: string | null; + ingestState: string & Opt = 'live'; + budgetItemsCollection = new Collection(this); + fileLinksCollection = new Collection(this); + reservationDayPositionsCollection = new Collection(this); + reservationEndpointsCollection = new Collection(this); + reservationTravelersCollection = new Collection(this); + tripFilesCollection = new Collection(this); +} + +export class ReservationsRepository extends EntityRepository {} + +export const ReservationsSchema = defineEntity({ + class: Reservations, + repository: () => ReservationsRepository, + uniques: [ + { + name: 'idx_reservations_external', + properties: ['externalSource', 'externalId', 'trip'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_reservations_trip_id'), + day: () => p.manyToOne(Days).ref().nullable().index('idx_reservations_day_id'), + endDay: () => p.manyToOne(Days).ref().nullable(), + place: () => p.manyToOne(Places).ref().nullable(), + assignment: () => p.manyToOne(DayAssignments).ref().nullable(), + title: p.text(), + accommodationId: p.text().nullable(), + reservationTime: p.text().nullable(), + reservationEndTime: p.text().nullable(), + location: p.text().nullable(), + confirmationNumber: p.text().nullable(), + notes: p.text().nullable(), + status: p.text().nullable(), + type: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + metadata: p.text().nullable(), + dayPlanPosition: p.double().nullable(), + needsReview: p.integer(), + externalSource: p.text().nullable(), + externalId: p.text().nullable(), + externalOwnerUserId: p.integer().nullable(), + externalSyncedAt: p.text().nullable(), + syncEnabled: p.integer().nullable(), + externalHash: p.text().nullable(), + url: p.text().nullable(), + ingestState: p.text(), + budgetItemsCollection: () => p.oneToMany(BudgetItems).mappedBy('reservation'), + fileLinksCollection: () => p.oneToMany(FileLinks).mappedBy('reservation'), + reservationDayPositionsCollection: () => p.oneToMany(ReservationDayPositions).mappedBy('reservation'), + reservationEndpointsCollection: () => p.oneToMany(ReservationEndpoints).mappedBy('reservation'), + reservationTravelersCollection: () => p.oneToMany(ReservationTravelers).mappedBy('reservation'), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('reservation'), + }, +}); diff --git a/server/src/db/entities/RoadtripDayBoundaries.ts b/server/src/db/entities/RoadtripDayBoundaries.ts new file mode 100644 index 000000000..cc60dbfdc --- /dev/null +++ b/server/src/db/entities/RoadtripDayBoundaries.ts @@ -0,0 +1,36 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { DayAssignments } from './DayAssignments.js'; +import { Trips } from './Trips.js'; + +export class RoadtripDayBoundaries { + [PrimaryKeyProp]?: ['trip', 'dayNumber']; + trip!: Ref; + dayNumber!: number; + fromAssignment!: Ref; + toAssignment?: Ref | null; + fraction!: unknown; +} + +export class RoadtripDayBoundariesRepository extends EntityRepository {} + +export const RoadtripDayBoundariesSchema = defineEntity({ + class: RoadtripDayBoundaries, + repository: () => RoadtripDayBoundariesRepository, + checks: [ + { + name: 'roadtrip_day_boundaries_fraction_check', + expression: 'fraction BETWEEN 0 AND 1), PRIMARY KEY (trip_id, day_number', + }, + { + name: 'roadtrip_day_boundaries_day_number_check', + expression: 'day_number BETWEEN 1 AND 366', + }, + ], + properties: { + trip: () => p.manyToOne(Trips).primary().ref().deleteRule('cascade'), + dayNumber: p.integer().primary(), + fromAssignment: () => p.manyToOne(DayAssignments).ref().deleteRule('cascade'), + toAssignment: () => p.manyToOne(DayAssignments).ref().deleteRule('cascade').nullable(), + fraction: p.double(), + }, +}); diff --git a/server/src/db/entities/RoadtripDayTracks.ts b/server/src/db/entities/RoadtripDayTracks.ts new file mode 100644 index 000000000..6b63443c2 --- /dev/null +++ b/server/src/db/entities/RoadtripDayTracks.ts @@ -0,0 +1,24 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; +import { Places } from './Places.js'; + +export class RoadtripDayTracks { + [PrimaryKeyProp]?: 'day'; + day?: Ref | null; + place!: Ref; + strayKm?: unknown | null; + createdAt?: string | null; +} + +export class RoadtripDayTracksRepository extends EntityRepository {} + +export const RoadtripDayTracksSchema = defineEntity({ + class: RoadtripDayTracks, + repository: () => RoadtripDayTracksRepository, + properties: { + day: () => p.oneToOne(Days).primary().ref().nullable(), + place: () => p.manyToOne(Places).ref().deleteRule('cascade').index('idx_roadtrip_day_tracks_place'), + strayKm: p.double().nullable(), + createdAt: p.text().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/RoadtripPreferences.ts b/server/src/db/entities/RoadtripPreferences.ts new file mode 100644 index 000000000..1e363bca3 --- /dev/null +++ b/server/src/db/entities/RoadtripPreferences.ts @@ -0,0 +1,21 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; + +export class RoadtripPreferences { + [PrimaryKeyProp]?: ['trip', 'key']; + trip!: Ref; + key!: string; + value!: string; +} + +export class RoadtripPreferencesRepository extends EntityRepository {} + +export const RoadtripPreferencesSchema = defineEntity({ + class: RoadtripPreferences, + repository: () => RoadtripPreferencesRepository, + properties: { + trip: () => p.manyToOne(Trips).primary().ref().deleteRule('cascade'), + key: p.text().primary(), + value: p.text(), + }, +}); diff --git a/server/src/db/entities/RoadtripVias.ts b/server/src/db/entities/RoadtripVias.ts new file mode 100644 index 000000000..111d3df9b --- /dev/null +++ b/server/src/db/entities/RoadtripVias.ts @@ -0,0 +1,34 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Days } from './Days.js'; + +export class RoadtripVias { + id?: number | null; + day!: Ref; + afterOrderIndex!: number; + sequence: number & Opt = 0; + lat!: unknown; + lng!: unknown; + createdAt?: string | null; +} + +export class RoadtripViasRepository extends EntityRepository {} + +export const RoadtripViasSchema = defineEntity({ + class: RoadtripVias, + repository: () => RoadtripViasRepository, + indexes: [ + { + name: 'idx_roadtrip_vias_day', + properties: ['day', 'afterOrderIndex', 'sequence'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + day: () => p.manyToOne(Days).ref().deleteRule('cascade'), + afterOrderIndex: p.integer(), + sequence: p.integer(), + lat: p.double(), + lng: p.double(), + createdAt: p.text().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/RouteUsageDaily.ts b/server/src/db/entities/RouteUsageDaily.ts new file mode 100644 index 000000000..8ad61424d --- /dev/null +++ b/server/src/db/entities/RouteUsageDaily.ts @@ -0,0 +1,30 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class RouteUsageDaily { + [PrimaryKeyProp]?: ['day', 'profile', 'surface', 'selfHosted']; + day!: string; + profile!: string; + surface!: string; + selfHosted!: number; + requests: number & Opt = 0; + waypoints: number & Opt = 0; + km!: number; + failed: number & Opt = 0; +} + +export class RouteUsageDailyRepository extends EntityRepository {} + +export const RouteUsageDailySchema = defineEntity({ + class: RouteUsageDaily, + repository: () => RouteUsageDailyRepository, + properties: { + day: p.text().primary().index('idx_route_usage_day'), + profile: p.text().primary(), + surface: p.text().primary(), + selfHosted: p.integer().primary(), + requests: p.integer(), + waypoints: p.integer(), + km: p.double().default(0), + failed: p.integer(), + }, +}); diff --git a/server/src/db/entities/SchemaVersion.ts b/server/src/db/entities/SchemaVersion.ts new file mode 100644 index 000000000..1704216b0 --- /dev/null +++ b/server/src/db/entities/SchemaVersion.ts @@ -0,0 +1,17 @@ +import { defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class SchemaVersion { + id?: number | null; + version!: number; +} + +export class SchemaVersionRepository extends EntityRepository {} + +export const SchemaVersionSchema = defineEntity({ + class: SchemaVersion, + repository: () => SchemaVersionRepository, + properties: { + id: p.integer().primary().autoincrement(), + version: p.integer(), + }, +}); diff --git a/server/src/db/entities/SchoolHolidayCountries.ts b/server/src/db/entities/SchoolHolidayCountries.ts new file mode 100644 index 000000000..ed6a44aed --- /dev/null +++ b/server/src/db/entities/SchoolHolidayCountries.ts @@ -0,0 +1,21 @@ +import { Collection, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { SchoolHolidayRegions } from './SchoolHolidayRegions.js'; + +export class SchoolHolidayCountries { + [PrimaryKeyProp]?: 'code'; + code?: string | null; + name!: string; + schoolHolidayRegionsCollection = new Collection(this); +} + +export class SchoolHolidayCountriesRepository extends EntityRepository {} + +export const SchoolHolidayCountriesSchema = defineEntity({ + class: SchoolHolidayCountries, + repository: () => SchoolHolidayCountriesRepository, + properties: { + code: p.text().primary().nullable(), + name: p.text(), + schoolHolidayRegionsCollection: () => p.oneToMany(SchoolHolidayRegions).mappedBy('country'), + }, +}); diff --git a/server/src/db/entities/SchoolHolidayPeriods.ts b/server/src/db/entities/SchoolHolidayPeriods.ts new file mode 100644 index 000000000..14d724d40 --- /dev/null +++ b/server/src/db/entities/SchoolHolidayPeriods.ts @@ -0,0 +1,30 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { SchoolHolidayRegions } from './SchoolHolidayRegions.js'; + +export class SchoolHolidayPeriods { + id?: number | null; + region!: Ref; + name!: string; + startDate!: string; + endDate!: string; +} + +export class SchoolHolidayPeriodsRepository extends EntityRepository {} + +export const SchoolHolidayPeriodsSchema = defineEntity({ + class: SchoolHolidayPeriods, + repository: () => SchoolHolidayPeriodsRepository, + checks: [ + { + name: 'school_holiday_periods_end_date_check', + expression: 'end_date >= start_date', + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + region: () => p.manyToOne(SchoolHolidayRegions).ref().deleteRule('cascade').index('idx_school_holiday_periods_region'), + name: p.text(), + startDate: p.text(), + endDate: p.text(), + }, +}); diff --git a/server/src/db/entities/SchoolHolidayRegions.ts b/server/src/db/entities/SchoolHolidayRegions.ts new file mode 100644 index 000000000..f08ce0439 --- /dev/null +++ b/server/src/db/entities/SchoolHolidayRegions.ts @@ -0,0 +1,25 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { SchoolHolidayCountries } from './SchoolHolidayCountries.js'; +import { SchoolHolidayPeriods } from './SchoolHolidayPeriods.js'; + +export class SchoolHolidayRegions { + id?: number | null; + country!: Ref; + name!: string; + revision: number & Opt = 1; + schoolHolidayPeriodsCollection = new Collection(this); +} + +export class SchoolHolidayRegionsRepository extends EntityRepository {} + +export const SchoolHolidayRegionsSchema = defineEntity({ + class: SchoolHolidayRegions, + repository: () => SchoolHolidayRegionsRepository, + properties: { + id: p.integer().primary().autoincrement(), + country: () => p.manyToOne(SchoolHolidayCountries).ref().name('country'), + name: p.text().collation('NOCASE'), + revision: p.integer(), + schoolHolidayPeriodsCollection: () => p.oneToMany(SchoolHolidayPeriods).mappedBy('region'), + }, +}); diff --git a/server/src/db/entities/Settings.ts b/server/src/db/entities/Settings.ts new file mode 100644 index 000000000..093d50b91 --- /dev/null +++ b/server/src/db/entities/Settings.ts @@ -0,0 +1,22 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class Settings { + id?: number | null; + user!: Ref; + key!: string; + value?: string | null; +} + +export class SettingsRepository extends EntityRepository {} + +export const SettingsSchema = defineEntity({ + class: Settings, + repository: () => SettingsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + key: p.text(), + value: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/ShareTokens.ts b/server/src/db/entities/ShareTokens.ts new file mode 100644 index 000000000..5a0e73226 --- /dev/null +++ b/server/src/db/entities/ShareTokens.ts @@ -0,0 +1,37 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class ShareTokens { + id?: number | null; + trip!: Ref; + token!: string; + createdBy!: Ref; + shareMap?: number | null = 1; + shareBookings?: number | null = 1; + sharePacking?: number | null = 0; + shareBudget?: number | null = 0; + shareCollab?: number | null = 0; + createdAt?: Date | null; + expiresAt?: string | null; +} + +export class ShareTokensRepository extends EntityRepository {} + +export const ShareTokensSchema = defineEntity({ + class: ShareTokens, + repository: () => ShareTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + token: p.text().index('idx_share_tokens_token'), + createdBy: () => p.manyToOne(Users).ref().name('created_by'), + shareMap: p.integer().nullable(), + shareBookings: p.integer().nullable(), + sharePacking: p.integer().nullable(), + shareBudget: p.integer().nullable(), + shareCollab: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + expiresAt: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Tags.ts b/server/src/db/entities/Tags.ts new file mode 100644 index 000000000..d95025aca --- /dev/null +++ b/server/src/db/entities/Tags.ts @@ -0,0 +1,30 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Places } from './Places.js'; +import { Users } from './Users.js'; + +export class Tags { + id?: number | null; + user!: Ref; + name!: string; + color?: string | null = '#10b981'; + createdAt?: Date | null; + collectionPlaceTagsInverse = new Collection(this); + placeTagsInverse = new Collection(this); +} + +export class TagsRepository extends EntityRepository {} + +export const TagsSchema = defineEntity({ + class: Tags, + repository: () => TagsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + name: p.text(), + color: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + collectionPlaceTagsInverse: () => p.manyToMany(CollectionPlaces).mappedBy('collectionPlaceTags'), + placeTagsInverse: () => p.manyToMany(Places).mappedBy('placeTags'), + }, +}); diff --git a/server/src/db/entities/TodoCategoryAssignees.ts b/server/src/db/entities/TodoCategoryAssignees.ts new file mode 100644 index 000000000..1b660c949 --- /dev/null +++ b/server/src/db/entities/TodoCategoryAssignees.ts @@ -0,0 +1,23 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TodoCategoryAssignees { + id?: number | null; + trip!: Ref; + categoryName!: string; + user!: Ref; +} + +export class TodoCategoryAssigneesRepository extends EntityRepository {} + +export const TodoCategoryAssigneesSchema = defineEntity({ + class: TodoCategoryAssignees, + repository: () => TodoCategoryAssigneesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + categoryName: p.text(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + }, +}); diff --git a/server/src/db/entities/TodoItems.ts b/server/src/db/entities/TodoItems.ts new file mode 100644 index 000000000..fc8f625b1 --- /dev/null +++ b/server/src/db/entities/TodoItems.ts @@ -0,0 +1,39 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TodoItems { + id?: number | null; + trip!: Ref; + name!: string; + checked?: number | null = 0; + category?: string | null; + sortOrder?: number | null = 0; + dueDate?: string | null; + description?: string | null; + assignedUser?: Ref | null; + priority?: number | null = 0; + createdAt?: Date | null; + remindedAt?: Date | null; +} + +export class TodoItemsRepository extends EntityRepository {} + +export const TodoItemsSchema = defineEntity({ + class: TodoItems, + repository: () => TodoItemsRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_todo_items_trip_id'), + name: p.text(), + checked: p.integer().nullable(), + category: p.text().nullable(), + sortOrder: p.integer().nullable(), + dueDate: p.text().nullable(), + description: p.text().nullable(), + assignedUser: () => p.manyToOne(Users).ref().nullable(), + priority: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + remindedAt: p.datetime().nullable(), + }, +}); diff --git a/server/src/db/entities/TrekPhotoCacheMeta.ts b/server/src/db/entities/TrekPhotoCacheMeta.ts new file mode 100644 index 000000000..6a3e86fe9 --- /dev/null +++ b/server/src/db/entities/TrekPhotoCacheMeta.ts @@ -0,0 +1,20 @@ +import { type Opt, PrimaryKeyProp, defineEntity, p, EntityRepository } from '@mikro-orm/core'; + +export class TrekPhotoCacheMeta { + [PrimaryKeyProp]?: 'cacheKey'; + cacheKey?: string | null; + contentType: string & Opt = 'image/jpeg'; + fetchedAt!: number; +} + +export class TrekPhotoCacheMetaRepository extends EntityRepository {} + +export const TrekPhotoCacheMetaSchema = defineEntity({ + class: TrekPhotoCacheMeta, + repository: () => TrekPhotoCacheMetaRepository, + properties: { + cacheKey: p.text().primary().nullable(), + contentType: p.text(), + fetchedAt: p.integer().index('idx_trek_photo_cache_meta_fetched_at'), + }, +}); diff --git a/server/src/db/entities/TrekPhotos.ts b/server/src/db/entities/TrekPhotos.ts new file mode 100644 index 000000000..42a1dc879 --- /dev/null +++ b/server/src/db/entities/TrekPhotos.ts @@ -0,0 +1,64 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { JourneyPhotos } from './JourneyPhotos.js'; +import { TripPhotos } from './TripPhotos.js'; +import { Users } from './Users.js'; + +export class TrekPhotos { + id?: number | null; + provider!: string; + assetId?: string | null; + owner?: Ref | null; + filePath?: string | null; + thumbnailPath?: string | null; + width?: number | null; + height?: number | null; + createdAt?: Date | null; + passphrase?: string | null; + mediaType: string & Opt = 'image'; + durationMs?: number | null; + takenAt?: string | null; + lat?: unknown | null; + lng?: unknown | null; + journeyPhotosCollection = new Collection(this); + tripPhotosCollection = new Collection(this); +} + +export class TrekPhotosRepository extends EntityRepository {} + +export const TrekPhotosSchema = defineEntity({ + class: TrekPhotos, + repository: () => TrekPhotosRepository, + indexes: [ + { + name: 'idx_trek_photos_geo', + where: 'lat IS NOT NULL AND lng IS NOT NULL', + properties: ['lat', 'lng'], + }, + ], + uniques: [ + { + name: 'idx_trek_photos_provider_asset', + where: 'asset_id IS NOT NULL', + properties: ['provider', 'assetId', 'owner'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + provider: p.text(), + assetId: p.text().nullable(), + owner: () => p.manyToOne(Users).ref().nullable().index('idx_trek_photos_owner'), + filePath: p.text().nullable(), + thumbnailPath: p.text().nullable(), + width: p.integer().nullable(), + height: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + passphrase: p.text().nullable(), + mediaType: p.text(), + durationMs: p.integer().nullable(), + takenAt: p.text().nullable(), + lat: p.double().nullable(), + lng: p.double().nullable(), + journeyPhotosCollection: () => p.oneToMany(JourneyPhotos).mappedBy('photo'), + tripPhotosCollection: () => p.oneToMany(TripPhotos).mappedBy('photo'), + }, +}); diff --git a/server/src/db/entities/TripAlbumLinks.ts b/server/src/db/entities/TripAlbumLinks.ts new file mode 100644 index 000000000..ee4af00cc --- /dev/null +++ b/server/src/db/entities/TripAlbumLinks.ts @@ -0,0 +1,38 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { TripPhotos } from './TripPhotos.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TripAlbumLinks { + id?: number | null; + trip!: Ref; + user!: Ref; + provider!: string; + albumId!: string; + albumName: string & Opt = ''; + syncEnabled: number & Opt = 1; + lastSyncedAt?: Date | null; + createdAt?: Date | null; + passphrase?: string | null; + tripPhotosCollection = new Collection(this); +} + +export class TripAlbumLinksRepository extends EntityRepository {} + +export const TripAlbumLinksSchema = defineEntity({ + class: TripAlbumLinks, + repository: () => TripAlbumLinksRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_trip_album_links_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + provider: p.text(), + albumId: p.text(), + albumName: p.text(), + syncEnabled: p.integer(), + lastSyncedAt: p.datetime().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + passphrase: p.text().nullable(), + tripPhotosCollection: () => p.oneToMany(TripPhotos).mappedBy('albumLink'), + }, +}); diff --git a/server/src/db/entities/TripFiles.ts b/server/src/db/entities/TripFiles.ts new file mode 100644 index 000000000..116db75ab --- /dev/null +++ b/server/src/db/entities/TripFiles.ts @@ -0,0 +1,52 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { CollabMessages } from './CollabMessages.js'; +import { CollabNotes } from './CollabNotes.js'; +import { FileLinks } from './FileLinks.js'; +import { Places } from './Places.js'; +import { Reservations } from './Reservations.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TripFiles { + id?: number | null; + trip!: Ref; + place?: Ref | null; + reservation?: Ref | null; + filename!: string; + originalName!: string; + fileSize?: number | null; + mimeType?: string | null; + description?: string | null; + createdAt?: Date | null; + note?: Ref | null; + uploadedBy?: Ref | null; + starred?: number | null = 0; + deletedAt?: string | null; + message?: Ref | null; + fileLinksCollection = new Collection(this); +} + +export class TripFilesRepository extends EntityRepository {} + +export const TripFilesSchema = defineEntity({ + class: TripFiles, + repository: () => TripFilesRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_trip_files_trip_id'), + place: () => p.manyToOne(Places).ref().nullable(), + reservation: () => p.manyToOne(Reservations).ref().nullable(), + filename: p.text(), + originalName: p.text(), + fileSize: p.integer().nullable(), + mimeType: p.text().nullable(), + description: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + note: () => p.manyToOne(CollabNotes).ref().nullable(), + uploadedBy: () => p.manyToOne(Users).ref().name('uploaded_by').nullable(), + starred: p.integer().nullable(), + deletedAt: p.text().nullable(), + message: () => p.manyToOne(CollabMessages).ref().deleteRule('cascade').nullable().index('idx_trip_files_message_id'), + fileLinksCollection: () => p.oneToMany(FileLinks).mappedBy('file'), + }, +}); diff --git a/server/src/db/entities/TripInviteTokens.ts b/server/src/db/entities/TripInviteTokens.ts new file mode 100644 index 000000000..a012bc1c0 --- /dev/null +++ b/server/src/db/entities/TripInviteTokens.ts @@ -0,0 +1,27 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TripInviteTokens { + id?: number | null; + trip!: Ref; + token!: string; + createdBy?: Ref | null; + expiresAt?: string | null; + createdAt?: Date | null; +} + +export class TripInviteTokensRepository extends EntityRepository {} + +export const TripInviteTokensSchema = defineEntity({ + class: TripInviteTokens, + repository: () => TripInviteTokensRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade'), + token: p.text().index('idx_trip_invite_tokens_token'), + createdBy: () => p.manyToOne(Users).ref().name('created_by').nullable(), + expiresAt: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/TripMembers.ts b/server/src/db/entities/TripMembers.ts new file mode 100644 index 000000000..9d9cb12da --- /dev/null +++ b/server/src/db/entities/TripMembers.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TripMembers { + id?: number | null; + trip!: Ref; + user!: Ref; + invitedBy?: Ref | null; + addedAt?: Date | null; +} + +export class TripMembersRepository extends EntityRepository {} + +export const TripMembersSchema = defineEntity({ + class: TripMembers, + repository: () => TripMembersRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_trip_members_trip_id'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_trip_members_user_id'), + invitedBy: () => p.manyToOne(Users).ref().name('invited_by').nullable(), + addedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/TripPhotos.ts b/server/src/db/entities/TripPhotos.ts new file mode 100644 index 000000000..b8d3d0ffb --- /dev/null +++ b/server/src/db/entities/TripPhotos.ts @@ -0,0 +1,31 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { TrekPhotos } from './TrekPhotos.js'; +import { TripAlbumLinks } from './TripAlbumLinks.js'; +import { Trips } from './Trips.js'; +import { Users } from './Users.js'; + +export class TripPhotos { + id?: number | null; + trip!: Ref; + user!: Ref; + photo!: Ref; + shared: number & Opt = 1; + albumLink?: Ref | null; + addedAt?: Date | null; +} + +export class TripPhotosRepository extends EntityRepository {} + +export const TripPhotosSchema = defineEntity({ + class: TripPhotos, + repository: () => TripPhotosRepository, + properties: { + id: p.integer().primary().autoincrement(), + trip: () => p.manyToOne(Trips).ref().deleteRule('cascade').index('idx_trip_photos_trip'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + photo: () => p.manyToOne(TrekPhotos).ref().deleteRule('cascade').index('idx_trip_photos_photo'), + shared: p.integer(), + albumLink: () => p.manyToOne(TripAlbumLinks).ref().nullable(), + addedAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/Trips.ts b/server/src/db/entities/Trips.ts new file mode 100644 index 000000000..0940ba12e --- /dev/null +++ b/server/src/db/entities/Trips.ts @@ -0,0 +1,137 @@ +import { Collection, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { BudgetCategoryOrder } from './BudgetCategoryOrder.js'; +import { BudgetItems } from './BudgetItems.js'; +import { BudgetSettlements } from './BudgetSettlements.js'; +import { CollabLinks } from './CollabLinks.js'; +import { CollabMessages } from './CollabMessages.js'; +import { CollabNotes } from './CollabNotes.js'; +import { CollabPolls } from './CollabPolls.js'; +import { DawarichVisitSuggestions } from './DawarichVisitSuggestions.js'; +import { DayAccommodations } from './DayAccommodations.js'; +import { DayNotes } from './DayNotes.js'; +import { Days } from './Days.js'; +import { InviteTokens } from './InviteTokens.js'; +import { JourneyEntries } from './JourneyEntries.js'; +import { JourneyTrips } from './JourneyTrips.js'; +import { PackingBags } from './PackingBags.js'; +import { PackingCategoryAssignees } from './PackingCategoryAssignees.js'; +import { PackingItems } from './PackingItems.js'; +import { Photos } from './Photos.js'; +import { Places } from './Places.js'; +import { Reservations } from './Reservations.js'; +import { RoadtripDayBoundaries } from './RoadtripDayBoundaries.js'; +import { RoadtripPreferences } from './RoadtripPreferences.js'; +import { ShareTokens } from './ShareTokens.js'; +import { TodoCategoryAssignees } from './TodoCategoryAssignees.js'; +import { TodoItems } from './TodoItems.js'; +import { TripAlbumLinks } from './TripAlbumLinks.js'; +import { TripFiles } from './TripFiles.js'; +import { TripInviteTokens } from './TripInviteTokens.js'; +import { TripMembers } from './TripMembers.js'; +import { TripPhotos } from './TripPhotos.js'; +import { Users } from './Users.js'; + +export class Trips { + id?: number | null; + user!: Ref; + title!: string; + description?: string | null; + startDate?: string | null; + endDate?: string | null; + currency?: string | null = 'EUR'; + coverImage?: string | null; + isArchived?: number | null = 0; + reminderDays?: number | null = 3; + feedToken?: string | null; + createdAt?: Date | null; + updatedAt?: Date | null; + budgetCategoryOrderCollection = new Collection(this); + budgetItemsCollection = new Collection(this); + budgetSettlementsCollection = new Collection(this); + collabLinksCollection = new Collection(this); + collabMessagesCollection = new Collection(this); + collabNotesCollection = new Collection(this); + collabPollsCollection = new Collection(this); + dawarichVisitSuggestionsCollection = new Collection(this); + dayAccommodationsCollection = new Collection(this); + dayNotesCollection = new Collection(this); + daysCollection = new Collection(this); + inviteTokensCollection = new Collection(this); + journeyEntriesCollection = new Collection(this); + journeyTripsCollection = new Collection(this); + packingBagsCollection = new Collection(this); + packingCategoryAssigneesCollection = new Collection(this); + packingItemsCollection = new Collection(this); + photosCollection = new Collection(this); + placesCollection = new Collection(this); + reservationsCollection = new Collection(this); + roadtripDayBoundariesCollection = new Collection(this); + roadtripPreferencesCollection = new Collection(this); + shareTokensCollection = new Collection(this); + todoCategoryAssigneesCollection = new Collection(this); + todoItemsCollection = new Collection(this); + tripAlbumLinksCollection = new Collection(this); + tripFilesCollection = new Collection(this); + tripInviteTokensCollection = new Collection(this); + tripMembersCollection = new Collection(this); + tripPhotosCollection = new Collection(this); +} + +export class TripsRepository extends EntityRepository {} + +export const TripsSchema = defineEntity({ + class: Trips, + repository: () => TripsRepository, + uniques: [ + { + name: 'idx_trips_feed_token', + where: 'feed_token IS NOT NULL', + properties: ['feedToken'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_trips_user_id'), + title: p.text(), + description: p.text().nullable(), + startDate: p.text().nullable(), + endDate: p.text().nullable(), + currency: p.text().nullable(), + coverImage: p.text().nullable(), + isArchived: p.integer().nullable(), + reminderDays: p.integer().nullable(), + feedToken: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()).index('idx_trips_created_at'), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + budgetCategoryOrderCollection: () => p.oneToMany(BudgetCategoryOrder).mappedBy('trip'), + budgetItemsCollection: () => p.oneToMany(BudgetItems).mappedBy('trip'), + budgetSettlementsCollection: () => p.oneToMany(BudgetSettlements).mappedBy('trip'), + collabLinksCollection: () => p.oneToMany(CollabLinks).mappedBy('trip'), + collabMessagesCollection: () => p.oneToMany(CollabMessages).mappedBy('trip'), + collabNotesCollection: () => p.oneToMany(CollabNotes).mappedBy('trip'), + collabPollsCollection: () => p.oneToMany(CollabPolls).mappedBy('trip'), + dawarichVisitSuggestionsCollection: () => p.oneToMany(DawarichVisitSuggestions).mappedBy('trip'), + dayAccommodationsCollection: () => p.oneToMany(DayAccommodations).mappedBy('trip'), + dayNotesCollection: () => p.oneToMany(DayNotes).mappedBy('trip'), + daysCollection: () => p.oneToMany(Days).mappedBy('trip'), + inviteTokensCollection: () => p.oneToMany(InviteTokens).mappedBy('trip'), + journeyEntriesCollection: () => p.oneToMany(JourneyEntries).mappedBy('sourceTrip'), + journeyTripsCollection: () => p.oneToMany(JourneyTrips).mappedBy('trip'), + packingBagsCollection: () => p.oneToMany(PackingBags).mappedBy('trip'), + packingCategoryAssigneesCollection: () => p.oneToMany(PackingCategoryAssignees).mappedBy('trip'), + packingItemsCollection: () => p.oneToMany(PackingItems).mappedBy('trip'), + photosCollection: () => p.oneToMany(Photos).mappedBy('trip'), + placesCollection: () => p.oneToMany(Places).mappedBy('trip'), + reservationsCollection: () => p.oneToMany(Reservations).mappedBy('trip'), + roadtripDayBoundariesCollection: () => p.oneToMany(RoadtripDayBoundaries).mappedBy('trip'), + roadtripPreferencesCollection: () => p.oneToMany(RoadtripPreferences).mappedBy('trip'), + shareTokensCollection: () => p.oneToMany(ShareTokens).mappedBy('trip'), + todoCategoryAssigneesCollection: () => p.oneToMany(TodoCategoryAssignees).mappedBy('trip'), + todoItemsCollection: () => p.oneToMany(TodoItems).mappedBy('trip'), + tripAlbumLinksCollection: () => p.oneToMany(TripAlbumLinks).mappedBy('trip'), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('trip'), + tripInviteTokensCollection: () => p.oneToMany(TripInviteTokens).mappedBy('trip'), + tripMembersCollection: () => p.oneToMany(TripMembers).mappedBy('trip'), + tripPhotosCollection: () => p.oneToMany(TripPhotos).mappedBy('trip'), + }, +}); diff --git a/server/src/db/entities/UserNoticeDismissals.ts b/server/src/db/entities/UserNoticeDismissals.ts new file mode 100644 index 000000000..2e6905ba6 --- /dev/null +++ b/server/src/db/entities/UserNoticeDismissals.ts @@ -0,0 +1,23 @@ +import { PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class UserNoticeDismissals { + [PrimaryKeyProp]?: ['user', 'noticeId']; + user!: Ref; + noticeId!: string; + dismissedAt!: number; + dismissedAppVersion?: string | null; +} + +export class UserNoticeDismissalsRepository extends EntityRepository {} + +export const UserNoticeDismissalsSchema = defineEntity({ + class: UserNoticeDismissals, + repository: () => UserNoticeDismissalsRepository, + properties: { + user: () => p.manyToOne(Users).primary().ref().deleteRule('cascade'), + noticeId: p.text().primary(), + dismissedAt: p.integer(), + dismissedAppVersion: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/Users.ts b/server/src/db/entities/Users.ts new file mode 100644 index 000000000..2db7b0566 --- /dev/null +++ b/server/src/db/entities/Users.ts @@ -0,0 +1,319 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { AssignmentParticipants } from './AssignmentParticipants.js'; +import { AuditLog } from './AuditLog.js'; +import { BucketList } from './BucketList.js'; +import { BudgetItemMembers } from './BudgetItemMembers.js'; +import { BudgetItemPayers } from './BudgetItemPayers.js'; +import { BudgetItems } from './BudgetItems.js'; +import { BudgetSettlements } from './BudgetSettlements.js'; +import { Categories } from './Categories.js'; +import { CollabLinks } from './CollabLinks.js'; +import { CollabMessageReactions } from './CollabMessageReactions.js'; +import { CollabMessages } from './CollabMessages.js'; +import { CollabNotes } from './CollabNotes.js'; +import { CollabPollVotes } from './CollabPollVotes.js'; +import { CollabPolls } from './CollabPolls.js'; +import { CollectionMembers } from './CollectionMembers.js'; +import { CollectionPlaceRatings } from './CollectionPlaceRatings.js'; +import { CollectionPlaces } from './CollectionPlaces.js'; +import { Collections } from './Collections.js'; +import { DawarichConnections } from './DawarichConnections.js'; +import { DawarichVisitSuggestions } from './DawarichVisitSuggestions.js'; +import { HiddenCountries } from './HiddenCountries.js'; +import { HiddenRegions } from './HiddenRegions.js'; +import { IdempotencyKeys } from './IdempotencyKeys.js'; +import { InviteTokens } from './InviteTokens.js'; +import { JourneyBooks } from './JourneyBooks.js'; +import { JourneyContributors } from './JourneyContributors.js'; +import { JourneyEntries } from './JourneyEntries.js'; +import { JourneyShareTokens } from './JourneyShareTokens.js'; +import { Journeys } from './Journeys.js'; +import { McpTokens } from './McpTokens.js'; +import { NotificationChannelPreferences } from './NotificationChannelPreferences.js'; +import { Notifications } from './Notifications.js'; +import { OauthClients } from './OauthClients.js'; +import { OauthConsents } from './OauthConsents.js'; +import { OauthTokens } from './OauthTokens.js'; +import { PackingBags } from './PackingBags.js'; +import { PackingCategoryAssignees } from './PackingCategoryAssignees.js'; +import { PackingItemContributors } from './PackingItemContributors.js'; +import { PackingItems } from './PackingItems.js'; +import { PackingTemplates } from './PackingTemplates.js'; +import { PasswordResetTokens } from './PasswordResetTokens.js'; +import { PlaceRatings } from './PlaceRatings.js'; +import { ReservationTravelers } from './ReservationTravelers.js'; +import { Settings } from './Settings.js'; +import { ShareTokens } from './ShareTokens.js'; +import { Tags } from './Tags.js'; +import { TodoCategoryAssignees } from './TodoCategoryAssignees.js'; +import { TodoItems } from './TodoItems.js'; +import { TrekPhotos } from './TrekPhotos.js'; +import { TripAlbumLinks } from './TripAlbumLinks.js'; +import { TripFiles } from './TripFiles.js'; +import { TripInviteTokens } from './TripInviteTokens.js'; +import { TripMembers } from './TripMembers.js'; +import { TripPhotos } from './TripPhotos.js'; +import { Trips } from './Trips.js'; +import { UserNoticeDismissals } from './UserNoticeDismissals.js'; +import { VacayEntries } from './VacayEntries.js'; +import { VacayPlanMembers } from './VacayPlanMembers.js'; +import { VacayPlans } from './VacayPlans.js'; +import { VacayShares } from './VacayShares.js'; +import { VacayUserColors } from './VacayUserColors.js'; +import { VacayUserSettings } from './VacayUserSettings.js'; +import { VacayUserYears } from './VacayUserYears.js'; +import { VisitedCountries } from './VisitedCountries.js'; +import { VisitedRegions } from './VisitedRegions.js'; +import { WebauthnChallenges } from './WebauthnChallenges.js'; +import { WebauthnCredentials } from './WebauthnCredentials.js'; + +export class Users { + id?: number | null; + username!: string; + email!: string; + passwordHash!: string; + role: string & Opt = 'user'; + mapsApiKey?: string | null; + unsplashApiKey?: string | null; + amapApiKey?: string | null; + openweatherApiKey?: string | null; + avatar?: string | null; + oidcSub?: string | null; + oidcIssuer?: string | null; + lastLogin?: Date | null; + mfaEnabled?: number | null = 0; + mfaSecret?: string | null; + mfaBackupCodes?: string | null; + immichUrl?: string | null; + immichAccessToken?: string | null; + synologyUrl?: string | null; + synologyUsername?: string | null; + synologyPassword?: string | null; + synologySid?: string | null; + mustChangePassword?: number | null = 0; + passwordVersion: number & Opt = 0; + feedToken?: string | null; + isGuest: number & Opt = 0; + createdAt?: Date | null; + updatedAt?: Date | null; + immichApiKey?: string | null; + synologySkipSsl: number & Opt = 0; + synologyDid?: string | null; + firstSeenVersion: string & Opt = '0.0.0'; + loginCount: number & Opt = 0; + immichAutoUpload: number & Opt = 0; + airtrailUrl?: string | null; + airtrailApiKey?: string | null; + airtrailAllowInsecureTls?: number | null = 0; + airtrailWriteEnabled?: number | null = 0; + displayName?: string | null; + assignmentParticipantsCollection = new Collection(this); + auditLogCollection = new Collection(this); + bucketListCollection = new Collection(this); + budgetItemMembersCollection = new Collection(this); + budgetItemPayersCollection = new Collection(this); + budgetItemsCollection = new Collection(this); + budgetSettlementsCollection = new Collection(this); + budgetSettlementsCollection1 = new Collection(this); + budgetSettlementsCollection2 = new Collection(this); + categoriesCollection = new Collection(this); + collabLinksCollection = new Collection(this); + collabMessageReactionsCollection = new Collection(this); + collabMessagesCollection = new Collection(this); + collabNotesCollection = new Collection(this); + collabPollVotesCollection = new Collection(this); + collabPollsCollection = new Collection(this); + collectionMembersCollection = new Collection(this); + collectionPlaceRatingsCollection = new Collection(this); + collectionPlacesCollection = new Collection(this); + collectionPlacesCollection1 = new Collection(this); + collectionsCollection = new Collection(this); + dawarichConnections: Ref | null = null; + dawarichVisitSuggestionsCollection = new Collection(this); + hiddenCountriesCollection = new Collection(this); + hiddenRegionsCollection = new Collection(this); + idempotencyKeysCollection = new Collection(this); + inviteTokensCollection = new Collection(this); + journeyBooksCollection = new Collection(this); + journeyBooksCollection1 = new Collection(this); + journeyContributorsCollection = new Collection(this); + journeyEntriesCollection = new Collection(this); + journeyShareTokensCollection = new Collection(this); + journeysCollection = new Collection(this); + mcpTokensCollection = new Collection(this); + notificationChannelPreferencesCollection = new Collection(this); + notificationsCollection = new Collection(this); + notificationsCollection1 = new Collection(this); + oauthClientsCollection = new Collection(this); + oauthConsentsCollection = new Collection(this); + oauthTokensCollection = new Collection(this); + packingBagsCollection = new Collection(this); + packingBagMembersInverse = new Collection(this); + packingCategoryAssigneesCollection = new Collection(this); + packingItemContributorsCollection = new Collection(this); + packingItemsCollection = new Collection(this); + packingItemContributorsInverse = new Collection(this); + packingItemRecipientsInverse = new Collection(this); + packingTemplatesCollection = new Collection(this); + passwordResetTokensCollection = new Collection(this); + placeRatingsCollection = new Collection(this); + reservationTravelersCollection = new Collection(this); + settingsCollection = new Collection(this); + shareTokensCollection = new Collection(this); + tagsCollection = new Collection(this); + todoCategoryAssigneesCollection = new Collection(this); + todoItemsCollection = new Collection(this); + trekPhotosCollection = new Collection(this); + tripAlbumLinksCollection = new Collection(this); + tripFilesCollection = new Collection(this); + tripInviteTokensCollection = new Collection(this); + tripMembersCollection = new Collection(this); + tripMembersCollection1 = new Collection(this); + tripPhotosCollection = new Collection(this); + tripsCollection = new Collection(this); + userNoticeDismissalsCollection = new Collection(this); + vacayEntriesCollection = new Collection(this); + vacayPlanMembersCollection = new Collection(this); + vacayPlansCollection = new Collection(this); + vacaySharesCollection = new Collection(this); + vacaySharesCollection1 = new Collection(this); + vacayUserColorsCollection = new Collection(this); + vacayUserSettings: Ref | null = null; + vacayUserYearsCollection = new Collection(this); + visitedCountriesCollection = new Collection(this); + visitedRegionsCollection = new Collection(this); + webauthnChallengesCollection = new Collection(this); + webauthnCredentialsCollection = new Collection(this); +} + +export class UsersRepository extends EntityRepository {} + +export const UsersSchema = defineEntity({ + class: Users, + repository: () => UsersRepository, + uniques: [ + { + name: 'idx_users_feed_token', + where: 'feed_token IS NOT NULL', + properties: ['feedToken'], + }, + ], + properties: { + id: p.integer().primary().autoincrement(), + username: p.text(), + email: p.text().index('idx_users_email'), + passwordHash: p.text(), + role: p.text(), + mapsApiKey: p.text().nullable(), + unsplashApiKey: p.text().nullable(), + amapApiKey: p.text().nullable(), + openweatherApiKey: p.text().nullable(), + avatar: p.text().nullable(), + oidcSub: p.text().nullable(), + oidcIssuer: p.text().nullable(), + lastLogin: p.datetime().nullable(), + mfaEnabled: p.integer().nullable(), + mfaSecret: p.text().nullable(), + mfaBackupCodes: p.text().nullable(), + immichUrl: p.text().nullable(), + immichAccessToken: p.text().nullable(), + synologyUrl: p.text().nullable(), + synologyUsername: p.text().nullable(), + synologyPassword: p.text().nullable(), + synologySid: p.text().nullable(), + mustChangePassword: p.integer().nullable(), + passwordVersion: p.integer(), + feedToken: p.text().nullable(), + isGuest: p.integer(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + updatedAt: p.datetime().nullable().onCreate(() => new Date()), + immichApiKey: p.text().nullable(), + synologySkipSsl: p.integer(), + synologyDid: p.text().nullable(), + firstSeenVersion: p.text(), + loginCount: p.integer(), + immichAutoUpload: p.integer(), + airtrailUrl: p.text().nullable(), + airtrailApiKey: p.text().nullable(), + airtrailAllowInsecureTls: p.integer().nullable(), + airtrailWriteEnabled: p.integer().nullable(), + displayName: p.text().nullable(), + assignmentParticipantsCollection: () => p.oneToMany(AssignmentParticipants).mappedBy('user'), + auditLogCollection: () => p.oneToMany(AuditLog).mappedBy('user'), + bucketListCollection: () => p.oneToMany(BucketList).mappedBy('user'), + budgetItemMembersCollection: () => p.oneToMany(BudgetItemMembers).mappedBy('user'), + budgetItemPayersCollection: () => p.oneToMany(BudgetItemPayers).mappedBy('user'), + budgetItemsCollection: () => p.oneToMany(BudgetItems).mappedBy('paidByUser'), + budgetSettlementsCollection: () => p.oneToMany(BudgetSettlements).mappedBy('fromUser'), + budgetSettlementsCollection1: () => p.oneToMany(BudgetSettlements).mappedBy('toUser'), + budgetSettlementsCollection2: () => p.oneToMany(BudgetSettlements).mappedBy('createdByUser'), + categoriesCollection: () => p.oneToMany(Categories).mappedBy('user'), + collabLinksCollection: () => p.oneToMany(CollabLinks).mappedBy('user'), + collabMessageReactionsCollection: () => p.oneToMany(CollabMessageReactions).mappedBy('user'), + collabMessagesCollection: () => p.oneToMany(CollabMessages).mappedBy('user'), + collabNotesCollection: () => p.oneToMany(CollabNotes).mappedBy('user'), + collabPollVotesCollection: () => p.oneToMany(CollabPollVotes).mappedBy('user'), + collabPollsCollection: () => p.oneToMany(CollabPolls).mappedBy('user'), + collectionMembersCollection: () => p.oneToMany(CollectionMembers).mappedBy('user'), + collectionPlaceRatingsCollection: () => p.oneToMany(CollectionPlaceRatings).mappedBy('user'), + collectionPlacesCollection: () => p.oneToMany(CollectionPlaces).mappedBy('owner'), + collectionPlacesCollection1: () => p.oneToMany(CollectionPlaces).mappedBy('savedBy'), + collectionsCollection: () => p.oneToMany(Collections).mappedBy('owner'), + dawarichConnections: () => p.oneToOne(DawarichConnections).ref().mappedBy('user'), + dawarichVisitSuggestionsCollection: () => p.oneToMany(DawarichVisitSuggestions).mappedBy('user'), + hiddenCountriesCollection: () => p.oneToMany(HiddenCountries).mappedBy('user'), + hiddenRegionsCollection: () => p.oneToMany(HiddenRegions).mappedBy('user'), + idempotencyKeysCollection: () => p.oneToMany(IdempotencyKeys).mappedBy('user'), + inviteTokensCollection: () => p.oneToMany(InviteTokens).mappedBy('createdBy'), + journeyBooksCollection: () => p.oneToMany(JourneyBooks).mappedBy('createdBy'), + journeyBooksCollection1: () => p.oneToMany(JourneyBooks).mappedBy('updatedBy'), + journeyContributorsCollection: () => p.oneToMany(JourneyContributors).mappedBy('user'), + journeyEntriesCollection: () => p.oneToMany(JourneyEntries).mappedBy('author'), + journeyShareTokensCollection: () => p.oneToMany(JourneyShareTokens).mappedBy('createdBy'), + journeysCollection: () => p.oneToMany(Journeys).mappedBy('user'), + mcpTokensCollection: () => p.oneToMany(McpTokens).mappedBy('user'), + notificationChannelPreferencesCollection: () => p.oneToMany(NotificationChannelPreferences).mappedBy('user'), + notificationsCollection: () => p.oneToMany(Notifications).mappedBy('sender'), + notificationsCollection1: () => p.oneToMany(Notifications).mappedBy('recipient'), + oauthClientsCollection: () => p.oneToMany(OauthClients).mappedBy('user'), + oauthConsentsCollection: () => p.oneToMany(OauthConsents).mappedBy('user'), + oauthTokensCollection: () => p.oneToMany(OauthTokens).mappedBy('user'), + packingBagsCollection: () => p.oneToMany(PackingBags).mappedBy('user'), + packingBagMembersInverse: () => p.manyToMany(PackingBags).mappedBy('packingBagMembers'), + packingCategoryAssigneesCollection: () => p.oneToMany(PackingCategoryAssignees).mappedBy('user'), + packingItemContributorsCollection: () => p.oneToMany(PackingItemContributors).mappedBy('user'), + packingItemsCollection: () => p.oneToMany(PackingItems).mappedBy('owner'), + packingItemContributorsInverse: () => p.manyToMany(PackingItems).mappedBy('packingItemContributors'), + packingItemRecipientsInverse: () => p.manyToMany(PackingItems).mappedBy('packingItemRecipients'), + packingTemplatesCollection: () => p.oneToMany(PackingTemplates).mappedBy('createdBy'), + passwordResetTokensCollection: () => p.oneToMany(PasswordResetTokens).mappedBy('user'), + placeRatingsCollection: () => p.oneToMany(PlaceRatings).mappedBy('user'), + reservationTravelersCollection: () => p.oneToMany(ReservationTravelers).mappedBy('user'), + settingsCollection: () => p.oneToMany(Settings).mappedBy('user'), + shareTokensCollection: () => p.oneToMany(ShareTokens).mappedBy('createdBy'), + tagsCollection: () => p.oneToMany(Tags).mappedBy('user'), + todoCategoryAssigneesCollection: () => p.oneToMany(TodoCategoryAssignees).mappedBy('user'), + todoItemsCollection: () => p.oneToMany(TodoItems).mappedBy('assignedUser'), + trekPhotosCollection: () => p.oneToMany(TrekPhotos).mappedBy('owner'), + tripAlbumLinksCollection: () => p.oneToMany(TripAlbumLinks).mappedBy('user'), + tripFilesCollection: () => p.oneToMany(TripFiles).mappedBy('uploadedBy'), + tripInviteTokensCollection: () => p.oneToMany(TripInviteTokens).mappedBy('createdBy'), + tripMembersCollection: () => p.oneToMany(TripMembers).mappedBy('user'), + tripMembersCollection1: () => p.oneToMany(TripMembers).mappedBy('invitedBy'), + tripPhotosCollection: () => p.oneToMany(TripPhotos).mappedBy('user'), + tripsCollection: () => p.oneToMany(Trips).mappedBy('user'), + userNoticeDismissalsCollection: () => p.oneToMany(UserNoticeDismissals).mappedBy('user'), + vacayEntriesCollection: () => p.oneToMany(VacayEntries).mappedBy('user'), + vacayPlanMembersCollection: () => p.oneToMany(VacayPlanMembers).mappedBy('user'), + vacayPlansCollection: () => p.oneToMany(VacayPlans).mappedBy('owner'), + vacaySharesCollection: () => p.oneToMany(VacayShares).mappedBy('owner'), + vacaySharesCollection1: () => p.oneToMany(VacayShares).mappedBy('user'), + vacayUserColorsCollection: () => p.oneToMany(VacayUserColors).mappedBy('user'), + vacayUserSettings: () => p.oneToOne(VacayUserSettings).ref().mappedBy('user'), + vacayUserYearsCollection: () => p.oneToMany(VacayUserYears).mappedBy('user'), + visitedCountriesCollection: () => p.oneToMany(VisitedCountries).mappedBy('user'), + visitedRegionsCollection: () => p.oneToMany(VisitedRegions).mappedBy('user'), + webauthnChallengesCollection: () => p.oneToMany(WebauthnChallenges).mappedBy('user'), + webauthnCredentialsCollection: () => p.oneToMany(WebauthnCredentials).mappedBy('user'), + }, +}); diff --git a/server/src/db/entities/VacayCompanyHolidays.ts b/server/src/db/entities/VacayCompanyHolidays.ts new file mode 100644 index 000000000..582ce876d --- /dev/null +++ b/server/src/db/entities/VacayCompanyHolidays.ts @@ -0,0 +1,22 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayCompanyHolidays { + id?: number | null; + plan!: Ref; + date!: string; + note?: string | null = ''; +} + +export class VacayCompanyHolidaysRepository extends EntityRepository {} + +export const VacayCompanyHolidaysSchema = defineEntity({ + class: VacayCompanyHolidays, + repository: () => VacayCompanyHolidaysRepository, + properties: { + id: p.integer().primary().autoincrement(), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + date: p.text(), + note: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/VacayEntries.ts b/server/src/db/entities/VacayEntries.ts new file mode 100644 index 000000000..81112853a --- /dev/null +++ b/server/src/db/entities/VacayEntries.ts @@ -0,0 +1,29 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayEntries { + id?: number | null; + plan!: Ref; + user!: Ref; + date!: string; + note?: string | null = ''; + fraction!: number & Opt; + kind: string & Opt = 'vacation'; +} + +export class VacayEntriesRepository extends EntityRepository {} + +export const VacayEntriesSchema = defineEntity({ + class: VacayEntries, + repository: () => VacayEntriesRepository, + properties: { + id: p.integer().primary().autoincrement(), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + date: p.text(), + note: p.text().nullable(), + fraction: p.double().default(1), + kind: p.text(), + }, +}); diff --git a/server/src/db/entities/VacayHolidayCalendars.ts b/server/src/db/entities/VacayHolidayCalendars.ts new file mode 100644 index 000000000..7be95b5ae --- /dev/null +++ b/server/src/db/entities/VacayHolidayCalendars.ts @@ -0,0 +1,28 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayHolidayCalendars { + id?: number | null; + plan!: Ref; + type: string & Opt = 'public_holiday'; + region!: string; + label?: string | null; + color: string & Opt = '#fecaca'; + sortOrder: number & Opt = 0; +} + +export class VacayHolidayCalendarsRepository extends EntityRepository {} + +export const VacayHolidayCalendarsSchema = defineEntity({ + class: VacayHolidayCalendars, + repository: () => VacayHolidayCalendarsRepository, + properties: { + id: p.integer().primary().autoincrement(), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + type: p.text(), + region: p.text(), + label: p.text().nullable(), + color: p.text(), + sortOrder: p.integer(), + }, +}); diff --git a/server/src/db/entities/VacayPlanMembers.ts b/server/src/db/entities/VacayPlanMembers.ts new file mode 100644 index 000000000..e020ac177 --- /dev/null +++ b/server/src/db/entities/VacayPlanMembers.ts @@ -0,0 +1,25 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayPlanMembers { + id?: number | null; + plan!: Ref; + user!: Ref; + status?: string | null = 'pending'; + createdAt?: Date | null; +} + +export class VacayPlanMembersRepository extends EntityRepository {} + +export const VacayPlanMembersSchema = defineEntity({ + class: VacayPlanMembers, + repository: () => VacayPlanMembersRepository, + properties: { + id: p.integer().primary().autoincrement(), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + status: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/VacayPlans.ts b/server/src/db/entities/VacayPlans.ts new file mode 100644 index 000000000..a1b116671 --- /dev/null +++ b/server/src/db/entities/VacayPlans.ts @@ -0,0 +1,57 @@ +import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; +import { VacayCompanyHolidays } from './VacayCompanyHolidays.js'; +import { VacayEntries } from './VacayEntries.js'; +import { VacayHolidayCalendars } from './VacayHolidayCalendars.js'; +import { VacayPlanMembers } from './VacayPlanMembers.js'; +import { VacayUserColors } from './VacayUserColors.js'; +import { VacayUserYears } from './VacayUserYears.js'; +import { VacayYears } from './VacayYears.js'; + +export class VacayPlans { + id?: number | null; + owner!: Ref; + blockWeekends?: number | null = 1; + holidaysEnabled?: number | null = 0; + holidaysRegion?: string | null = ''; + schoolHolidaysEnabled?: number | null = 0; + companyHolidaysEnabled?: number | null = 1; + carryOverEnabled?: number | null = 1; + createdAt?: Date | null; + weekendDays?: string | null = '0,6'; + weekStart: number & Opt = 1; + vacayCompanyHolidaysCollection = new Collection(this); + vacayEntriesCollection = new Collection(this); + vacayHolidayCalendarsCollection = new Collection(this); + vacayPlanMembersCollection = new Collection(this); + vacayUserColorsCollection = new Collection(this); + vacayUserYearsCollection = new Collection(this); + vacayYearsCollection = new Collection(this); +} + +export class VacayPlansRepository extends EntityRepository {} + +export const VacayPlansSchema = defineEntity({ + class: VacayPlans, + repository: () => VacayPlansRepository, + properties: { + id: p.integer().primary().autoincrement(), + owner: () => p.manyToOne(Users).ref().deleteRule('cascade'), + blockWeekends: p.integer().nullable(), + holidaysEnabled: p.integer().nullable(), + holidaysRegion: p.text().nullable(), + schoolHolidaysEnabled: p.integer().nullable(), + companyHolidaysEnabled: p.integer().nullable(), + carryOverEnabled: p.integer().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + weekendDays: p.text().nullable(), + weekStart: p.integer(), + vacayCompanyHolidaysCollection: () => p.oneToMany(VacayCompanyHolidays).mappedBy('plan'), + vacayEntriesCollection: () => p.oneToMany(VacayEntries).mappedBy('plan'), + vacayHolidayCalendarsCollection: () => p.oneToMany(VacayHolidayCalendars).mappedBy('plan'), + vacayPlanMembersCollection: () => p.oneToMany(VacayPlanMembers).mappedBy('plan'), + vacayUserColorsCollection: () => p.oneToMany(VacayUserColors).mappedBy('plan'), + vacayUserYearsCollection: () => p.oneToMany(VacayUserYears).mappedBy('plan'), + vacayYearsCollection: () => p.oneToMany(VacayYears).mappedBy('plan'), + }, +}); diff --git a/server/src/db/entities/VacayShares.ts b/server/src/db/entities/VacayShares.ts new file mode 100644 index 000000000..66960b71a --- /dev/null +++ b/server/src/db/entities/VacayShares.ts @@ -0,0 +1,24 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class VacayShares { + id?: number | null; + owner!: Ref; + user!: Ref; + hidden: number & Opt = 0; + createdAt?: Date | null; +} + +export class VacaySharesRepository extends EntityRepository {} + +export const VacaySharesSchema = defineEntity({ + class: VacayShares, + repository: () => VacaySharesRepository, + properties: { + id: p.integer().primary().autoincrement(), + owner: () => p.manyToOne(Users).ref().deleteRule('cascade'), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_vacay_shares_user'), + hidden: p.integer(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/VacayUserColors.ts b/server/src/db/entities/VacayUserColors.ts new file mode 100644 index 000000000..bd50e2401 --- /dev/null +++ b/server/src/db/entities/VacayUserColors.ts @@ -0,0 +1,23 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayUserColors { + id?: number | null; + user!: Ref; + plan!: Ref; + color?: string | null = '#6366f1'; +} + +export class VacayUserColorsRepository extends EntityRepository {} + +export const VacayUserColorsSchema = defineEntity({ + class: VacayUserColors, + repository: () => VacayUserColorsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + color: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/VacayUserSettings.ts b/server/src/db/entities/VacayUserSettings.ts new file mode 100644 index 000000000..ceb38d3a7 --- /dev/null +++ b/server/src/db/entities/VacayUserSettings.ts @@ -0,0 +1,25 @@ +import { type Opt, PrimaryKeyProp, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class VacayUserSettings { + [PrimaryKeyProp]?: 'user'; + user?: Ref | null; + yearType: string & Opt = 'calendar'; + yearStartMonth: number & Opt = 1; + yearStartDay: number & Opt = 1; + hireDate?: string | null; +} + +export class VacayUserSettingsRepository extends EntityRepository {} + +export const VacayUserSettingsSchema = defineEntity({ + class: VacayUserSettings, + repository: () => VacayUserSettingsRepository, + properties: { + user: () => p.oneToOne(Users).primary().ref().nullable(), + yearType: p.text(), + yearStartMonth: p.integer(), + yearStartDay: p.integer(), + hireDate: p.text().nullable(), + }, +}); diff --git a/server/src/db/entities/VacayUserYears.ts b/server/src/db/entities/VacayUserYears.ts new file mode 100644 index 000000000..9065bf20b --- /dev/null +++ b/server/src/db/entities/VacayUserYears.ts @@ -0,0 +1,27 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayUserYears { + id?: number | null; + user!: Ref; + plan!: Ref; + year!: number; + vacationDays?: number | null = 30; + carriedOver?: number | null = 0; +} + +export class VacayUserYearsRepository extends EntityRepository {} + +export const VacayUserYearsSchema = defineEntity({ + class: VacayUserYears, + repository: () => VacayUserYearsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + year: p.integer(), + vacationDays: p.integer().nullable(), + carriedOver: p.integer().nullable(), + }, +}); diff --git a/server/src/db/entities/VacayYears.ts b/server/src/db/entities/VacayYears.ts new file mode 100644 index 000000000..743c38f57 --- /dev/null +++ b/server/src/db/entities/VacayYears.ts @@ -0,0 +1,20 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { VacayPlans } from './VacayPlans.js'; + +export class VacayYears { + id?: number | null; + plan!: Ref; + year!: number; +} + +export class VacayYearsRepository extends EntityRepository {} + +export const VacayYearsSchema = defineEntity({ + class: VacayYears, + repository: () => VacayYearsRepository, + properties: { + id: p.integer().primary().autoincrement(), + plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade'), + year: p.integer(), + }, +}); diff --git a/server/src/db/entities/VisitedCountries.ts b/server/src/db/entities/VisitedCountries.ts new file mode 100644 index 000000000..234cd1e41 --- /dev/null +++ b/server/src/db/entities/VisitedCountries.ts @@ -0,0 +1,24 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class VisitedCountries { + id?: number | null; + user!: Ref; + countryCode!: string; + createdAt?: Date | null; + source: string & Opt = 'manual'; +} + +export class VisitedCountriesRepository extends EntityRepository {} + +export const VisitedCountriesSchema = defineEntity({ + class: VisitedCountries, + repository: () => VisitedCountriesRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + countryCode: p.text(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + source: p.text(), + }, +}); diff --git a/server/src/db/entities/VisitedRegions.ts b/server/src/db/entities/VisitedRegions.ts new file mode 100644 index 000000000..21cdab1c7 --- /dev/null +++ b/server/src/db/entities/VisitedRegions.ts @@ -0,0 +1,26 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class VisitedRegions { + id?: number | null; + user!: Ref; + regionCode!: string; + regionName!: string; + countryCode!: string; + createdAt?: Date | null; +} + +export class VisitedRegionsRepository extends EntityRepository {} + +export const VisitedRegionsSchema = defineEntity({ + class: VisitedRegions, + repository: () => VisitedRegionsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade'), + regionCode: p.text(), + regionName: p.text(), + countryCode: p.text().index('idx_visited_regions_country'), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/WebauthnChallenges.ts b/server/src/db/entities/WebauthnChallenges.ts new file mode 100644 index 000000000..88290c253 --- /dev/null +++ b/server/src/db/entities/WebauthnChallenges.ts @@ -0,0 +1,26 @@ +import { type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class WebauthnChallenges { + id?: number | null; + challenge!: string; + user?: Ref | null; + type!: string; + expiresAt!: number; + createdAt?: Date | null; +} + +export class WebauthnChallengesRepository extends EntityRepository {} + +export const WebauthnChallengesSchema = defineEntity({ + class: WebauthnChallenges, + repository: () => WebauthnChallengesRepository, + properties: { + id: p.integer().primary().autoincrement(), + challenge: p.text(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').nullable(), + type: p.text(), + expiresAt: p.integer().index('idx_webauthn_challenges_expires'), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + }, +}); diff --git a/server/src/db/entities/WebauthnCredentials.ts b/server/src/db/entities/WebauthnCredentials.ts new file mode 100644 index 000000000..cb1ab4f87 --- /dev/null +++ b/server/src/db/entities/WebauthnCredentials.ts @@ -0,0 +1,38 @@ +import { type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core'; +import { Users } from './Users.js'; + +export class WebauthnCredentials { + id?: number | null; + user!: Ref; + credentialId!: string; + publicKey!: Buffer; + counter: number & Opt = 0; + transports?: string | null; + deviceType?: string | null; + backedUp: number & Opt = 0; + name?: string | null; + aaguid?: string | null; + createdAt?: Date | null; + lastUsedAt?: Date | null; +} + +export class WebauthnCredentialsRepository extends EntityRepository {} + +export const WebauthnCredentialsSchema = defineEntity({ + class: WebauthnCredentials, + repository: () => WebauthnCredentialsRepository, + properties: { + id: p.integer().primary().autoincrement(), + user: () => p.manyToOne(Users).ref().deleteRule('cascade').index('idx_webauthn_credentials_user'), + credentialId: p.text(), + publicKey: p.blob(), + counter: p.integer(), + transports: p.text().nullable(), + deviceType: p.text().nullable(), + backedUp: p.integer(), + name: p.text().nullable(), + aaguid: p.text().nullable(), + createdAt: p.datetime().nullable().onCreate(() => new Date()), + lastUsedAt: p.datetime().nullable(), + }, +});