HB_DB_DRIVER=mongo|postgres, versionierte Migrationen beim Start, Mongo-Backend ruft unverändert die Upstream-Modelle. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import { notificationToRow, rowToNotification } from './rows.js';
|
|
|
|
// NotificationRepository (PostgreSQL). Fehler haben wie im Upstream-Modell die Form { message }.
|
|
export const createNotificationRepository = (db)=>({
|
|
async list() {
|
|
return (await db.selectFrom('notifications').selectAll().orderBy('created_at').orderBy('id').execute()).map(rowToNotification);
|
|
},
|
|
async create(data) {
|
|
if(!data.dismissKey) throw { message: 'Dismiss key is required!' };
|
|
try {
|
|
const row = await db.insertInto('notifications').values(notificationToRow(data)).returningAll().executeTakeFirstOrThrow();
|
|
return rowToNotification(row);
|
|
} catch (err) {
|
|
throw { message: err.message || 'Error saving notification' };
|
|
}
|
|
},
|
|
async deleteByDismissKey(dismissKey) {
|
|
if(!dismissKey) throw { message: 'Dismiss key is required!' };
|
|
let row;
|
|
try {
|
|
row = await db.deleteFrom('notifications').where('dismiss_key', '=', dismissKey).returningAll().executeTakeFirst();
|
|
} catch (err) {
|
|
throw { message: err.message || 'Error deleting notification' };
|
|
}
|
|
if(!row) throw { message: 'Notification not found' };
|
|
return rowToNotification(row);
|
|
}
|
|
});
|