UNPKG

@opengis/fastify-table

Version:

core-plugins

18 lines (17 loc) 745 B
import pgClients from "../../../plugins/pg/pgClients.js"; export default async function readNotifications(req, reply) { const { pg = pgClients.client, params, user, } = req; if (!user?.uid) { return reply.status(401).send({ error: "unauthorized", code: 401 }); } const ids = pg && pg.pk?.["crm.notifications"] ? await pg .query(`update crm.notifications set read=true where read is not true and addressee_id=$1 and ${params.id ? "notification_id=$2" : "1=1"} returning notification_id`, [user.uid, params?.id].filter(Boolean)) .then((el) => el.rows?.map((row) => row.notification_id) || []) : []; return reply.status(200).send({ ids, read: ids.length }); }