feat: Produktpflege mit Bildupload + Beschreibung + Aktiv-Status
Backend (routes/artikel.js): - 3 neue Spalten via Auto-Migration (bootstrap.js): - bild_url VARCHAR(500) - beschreibung TEXT - aktiv TINYINT(1) DEFAULT 1 - POST/PUT/DELETE Routes jetzt unter requireRole(admin) - GET unterstuetzt ?all=1 fuer inaktive Produkte (Produktpflege-Ansicht) - POST /artikel/:id/bild und DELETE /artikel/:id/bild fuer Bildverwaltung - DELETE faengt FK-Constraint ab (Hinweis: stattdessen inaktiv setzen) Frontend: - Neue Komponente Produkte.jsx als Kartenraster - Bildupload, Beschreibung, Pfandbetrag, Aktiv-Toggle, Edit/Loeschen - Inaktive werden ausgegraut dargestellt - TopNav: neuer Admin-Menupunkt Produkte (FaTags Icon) - Dashboard.jsx: Route eingebaut - client.js: api.getArtikel(true) fuer inaktive, uploadArtikelBild, deleteArtikelBild
This commit is contained in:
39
backend/scripts/bootstrap.js
vendored
39
backend/scripts/bootstrap.js
vendored
@@ -1,18 +1,33 @@
|
||||
import bcrypt from 'bcrypt';
|
||||
import pool from '../config/database.js';
|
||||
|
||||
const EXPIRY_COLS = ['notified_7d_at', 'notified_1d_at', 'notified_expired_at'];
|
||||
// Spaltenname -> SQL-Definition
|
||||
const COLS_TO_ADD = {
|
||||
tenants: {
|
||||
notified_7d_at: 'TIMESTAMP NULL',
|
||||
notified_1d_at: 'TIMESTAMP NULL',
|
||||
notified_expired_at: 'TIMESTAMP NULL',
|
||||
},
|
||||
artikel: {
|
||||
bild_url: 'VARCHAR(500) NULL',
|
||||
beschreibung: 'TEXT NULL',
|
||||
aktiv: 'TINYINT(1) NOT NULL DEFAULT 1',
|
||||
},
|
||||
};
|
||||
|
||||
async function ensureExpiryColumns() {
|
||||
const [cols] = await pool.query(
|
||||
`SELECT COLUMN_NAME FROM information_schema.columns
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tenants'`
|
||||
);
|
||||
const have = new Set(cols.map(c => c.COLUMN_NAME));
|
||||
for (const col of EXPIRY_COLS) {
|
||||
if (!have.has(col)) {
|
||||
await pool.query(`ALTER TABLE tenants ADD COLUMN ${col} TIMESTAMP NULL`);
|
||||
console.log('[bootstrap] tenants ALTER ADD', col);
|
||||
async function ensureColumns() {
|
||||
for (const [table, cols] of Object.entries(COLS_TO_ADD)) {
|
||||
const [existing] = await pool.query(
|
||||
`SELECT COLUMN_NAME FROM information_schema.columns
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`,
|
||||
[table]
|
||||
);
|
||||
const have = new Set(existing.map(c => c.COLUMN_NAME));
|
||||
for (const [col, def] of Object.entries(cols)) {
|
||||
if (!have.has(col)) {
|
||||
await pool.query(`ALTER TABLE ${table} ADD COLUMN ${col} ${def}`);
|
||||
console.log(`[bootstrap] ${table} ALTER ADD ${col}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +40,7 @@ export async function bootstrapSuperAdmin() {
|
||||
}
|
||||
|
||||
// Migrations
|
||||
try { await ensureExpiryColumns(); }
|
||||
try { await ensureColumns(); }
|
||||
catch (e) { console.error('[bootstrap] Migration-Fehler:', e.message); }
|
||||
|
||||
const email = process.env.SUPERADMIN_EMAIL;
|
||||
|
||||
Reference in New Issue
Block a user