Files
homebrewery-oidc/server/storage/postgres/notifications.js
dev-bot BotandClaude Sonnet 5.5 a55c403527 feat(storage): Repository-Schicht für Brews/Notifications, PostgreSQL-18-Backend (Kysely) und Contract-Suite
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>
2026-11-25 10:16:55 +00:00

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);
}
});