Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
require('dotenv').config();
|
|
const DIRECTUS_URL = process.env.DIRECTUS_URL || 'https://cms.dk0.dev';
|
|
const DIRECTUS_TOKEN = process.env.DIRECTUS_STATIC_TOKEN;
|
|
|
|
async function api(endpoint, method = 'GET', body = null) {
|
|
const url = `${DIRECTUS_URL}/${endpoint}`;
|
|
const options = {
|
|
method,
|
|
headers: { 'Authorization': `Bearer ${DIRECTUS_TOKEN}`, 'Content-Type': 'application/json' }
|
|
};
|
|
if (body) options.body = JSON.stringify(body);
|
|
const response = await fetch(url, options);
|
|
const data = await response.json();
|
|
return { ok: response.ok, data };
|
|
}
|
|
|
|
async function makeEditable() {
|
|
console.log('🔓 Mache "Book Reviews" editierbar...');
|
|
|
|
// 1. Prüfen ob ID Feld existiert, sonst anlegen
|
|
console.log('1. Erstelle ID-Primärschlüssel...');
|
|
await api('fields/book_reviews', 'POST', {
|
|
field: 'id',
|
|
type: 'integer',
|
|
schema: {
|
|
is_primary_key: true,
|
|
has_auto_increment: true
|
|
},
|
|
meta: {
|
|
hidden: true // Im Formular verstecken, da automatisch
|
|
}
|
|
});
|
|
|
|
// 2. Sicherstellen, dass alle Felder eine Interface-Zuweisung haben (wichtig für die Eingabe)
|
|
console.log('2. Konfiguriere Eingabe-Interfaces...');
|
|
const fieldUpdates = [
|
|
{ field: 'book_title', interface: 'input' },
|
|
{ field: 'book_author', interface: 'input' },
|
|
{ field: 'rating', interface: 'rating' },
|
|
{ field: 'status', interface: 'select-dropdown' },
|
|
{ field: 'finished_at', interface: 'datetime' }
|
|
];
|
|
|
|
for (const f of fieldUpdates) {
|
|
await api(`fields/book_reviews/${f.field}`, 'PATCH', {
|
|
meta: { interface: f.interface, readonly: false }
|
|
});
|
|
}
|
|
|
|
console.log('✅ Fertig! Bitte lade Directus neu.');
|
|
console.log('Solltest du immer noch nicht editieren können, musst du eventuell die Collection löschen und neu anlegen lassen, da die Datenbank-Struktur (ID) manchmal nicht nachträglich über die API geändert werden kann.');
|
|
}
|
|
|
|
makeEditable().catch(console.error);
|