UNPKG

@opengis/fastify-table

Version:

core-plugins

23 lines (22 loc) 878 B
import pgClients from "../../../plugins/pg/pgClients.js"; import dataInsert from "../../../plugins/crud/funcs/dataInsert.js"; export default async function addUserNotification(req, reply) { const { pg = pgClients.client, body, user, } = req; if (!user?.uid) { return reply.status(401).send({ error: "unauthorized", code: 401 }); } // who (user id) and what of (message) to notify const missingKey = ["addressee_id", "body"].find((key) => !body[key]); if (missingKey) { return reply .status(400) .send({ error: `not enough body params: ${missingKey}`, code: 400 }); } const result = await dataInsert({ pg, table: "crm.notifications", data: { ...body, author_id: user.uid }, uid: user.uid, }).then((el) => el.rows?.[0] || {}); return reply.status(200).send(result); }