config.shop (SHOP_ENABLED, SHOP_PILOT_EMAILS, SHOP_UPLOAD_DIR, STRIPE_CONNECT_WEBHOOK_SECRET), config.shopSetup (299 € einmalig), Collection-IDs shopConfig/shopProducts/shopOrders/shopWiderrufe, services/shop/schalter.js, Katalogschluessel shopSetup in stripeBilling und stripe-products.mjs, services/shop/schema.js, scripts/shop-setup.mjs (--check), schemaKeys fuer die Test-Mocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
2.0 KiB
JavaScript
32 lines
2.0 KiB
JavaScript
import { readFileSync } from 'node:fs'
|
|
import { TERMINE_COLLECTIONS } from '../../server/services/termine/schema.js'
|
|
import { SHOP_COLLECTIONS } from '../../server/services/shop/schema.js'
|
|
import { FEATURE_CONSENT_ATTRIBUTES, PORTAL_FEATURE_ATTRIBUTES } from '../../scripts/feature-setup.mjs'
|
|
|
|
// Setup-Skripte, die Collections in Appwrite anlegen (Blockformat: 'id', ... \n ],)
|
|
const SETUP_SCRIPTS = ['setup-abo-collections.mjs', 'setup-finanzen.mjs']
|
|
|
|
/**
|
|
* Attribut-Schlüssel einer Collection, wie sie scripts/setup-abo-collections.mjs bzw.
|
|
* scripts/setup-finanzen.mjs in Appwrite anlegen. Tests geben sie dem Appwrite-Nachbau als Schema:
|
|
* Schreibt der Code ein Feld, das das Setup-Skript nicht anlegt, scheitert der Test wie Appwrite in
|
|
* Produktion. Die Termine-Collections kommen aus server/services/termine/schema.js (scripts/termine-setup.mjs),
|
|
* die Shop-Collections aus server/services/shop/schema.js (scripts/shop-setup.mjs);
|
|
* portalFeatures bekommt zusaetzlich die Attribute aus scripts/feature-setup.mjs (PORTAL_FEATURE_ATTRIBUTES);
|
|
* featureConsents (Zustimmungsnachweis) steht ganz dort (FEATURE_CONSENT_ATTRIBUTES).
|
|
*/
|
|
export function schemaKeys(collection) {
|
|
if (Object.hasOwn(TERMINE_COLLECTIONS, collection)) return TERMINE_COLLECTIONS[collection].attributes.map((a) => a.key)
|
|
if (Object.hasOwn(SHOP_COLLECTIONS, collection)) return SHOP_COLLECTIONS[collection].attributes.map((a) => a.key)
|
|
if (collection === 'featureConsents') return FEATURE_CONSENT_ATTRIBUTES.map((a) => a.key)
|
|
for (const script of SETUP_SCRIPTS) {
|
|
const src = readFileSync(new URL(`../../scripts/${script}`, import.meta.url), 'utf8')
|
|
const start = src.indexOf(`'${collection}',`)
|
|
if (start < 0) continue
|
|
const block = src.slice(start, src.indexOf('\n ],', start))
|
|
const keys = [...block.matchAll(/key: '(\w+)'/g)].map((m) => m[1])
|
|
return collection === 'portalFeatures' ? [...keys, ...PORTAL_FEATURE_ATTRIBUTES.map((a) => a.key)] : keys
|
|
}
|
|
throw new Error(`Collection ${collection} fehlt im Setup-Skript`)
|
|
}
|