This commit is contained in:
Joris Bertomeu
2024-11-19 12:01:15 +01:00
commit dfb0846b79
40 changed files with 16403 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
export class AdminController {
constructor(db) {
this.db = db;
}
async getSettings(req, res, next) {
try {
const data = await this.db.get('settings');
res.json(data?.[0] || {});
} catch(e) {
next(e);
}
}
async updateSettings(req, res, next) {
try {
await this.db.update('settings', req.params.id, req.body);
res.json(req.body);
} catch(e) {
next(e);
}
}
async getWidgets(req, res, next) {
try {
const data = await this.db.get('widgets');
res.json(
data.filter(item => item.settingsId === req.params.settingsId) || []
);
} catch(e) {
next(e);
}
}
async updateWidgets(req, res, next) {
try {
const { settingsId } = req.params;
const updates = req.body;
for (const widget of updates) {
if (!widget.id) {
await this.db.add('widgets', { ...widget, settingsId });
} else {
await this.db.update('widgets', widget.id, widget);
}
}
res.json(updates);
} catch(e) {
next(e);
}
}
}