UNPKG

@opengis/admin

Version:

This project Softpro Admin

19 lines (13 loc) 584 B
export default async function readNotifications({ pg, params = {}, query = {}, user = {}, }, reply) { const { uid } = user || {}; if (!uid) { return reply.status(401).send('access restricted: user '); } const q = `update crm.notifications set read=true where read is not true and ${params?.id ? 'notification_id=$2' : '1=1'} and addressee_id=$1`; if (query.sql) return q; const { rowCount = 0 } = await pg.query(q, [uid, params?.id].filter((el) => el)); return reply.status(200).send(`${rowCount} unread notifications marked as read`); }