'use strict'; /* POST /reports/:id/read (and /reports/read-all). Per-user read flag; the report itself is shared. */ const { GameError } = require('../errors'); module.exports = function markReportRead(ctx, { userId, reportId, all }) { const { db, now } = ctx; if (all) { const r = db.run('UPDATE report_recipients SET read_at = ? WHERE user_id = ? AND read_at IS NULL', now, userId); return { marked: Number(r.changes) }; } const r = db.run('UPDATE report_recipients SET read_at = COALESCE(read_at, ?) WHERE report_id = ? AND user_id = ?', now, reportId, userId); if (!r.changes) throw new GameError('not_found', { what: 'report' }); return { marked: 1 }; };