From ce1dd8e4fa5a77e83d90c6040a7f0d280ca71245 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Fri, 17 May 2024 16:08:06 +0100 Subject: [PATCH] feat: expose notifications api --- .../accounts/_account/notifications/index.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 apps/api/src/app/routes/accounts/_account/notifications/index.ts diff --git a/apps/api/src/app/routes/accounts/_account/notifications/index.ts b/apps/api/src/app/routes/accounts/_account/notifications/index.ts new file mode 100644 index 0000000..8e0304b --- /dev/null +++ b/apps/api/src/app/routes/accounts/_account/notifications/index.ts @@ -0,0 +1,36 @@ +import { + NotificationModel, + getNotificationsByAccount, +} from '@cowprotocol/cms-api'; +import { FastifyPluginAsync } from 'fastify'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; + +const routeSchema = { + type: 'object', + required: ['account'], + properties: { + account: { + title: 'account', + description: 'Account of the user', + type: 'string', + }, + }, +} as const satisfies JSONSchema; +type RouteSchema = FromSchema; + +type GetNotificationsSchema = RouteSchema; + +const accounts: FastifyPluginAsync = async (fastify): Promise => { + // GET /accounts/:account/notifications + fastify.get<{ + Params: GetNotificationsSchema; + Reply: NotificationModel[]; + }>('/', { schema: { params: routeSchema } }, async function (request, reply) { + const account = request.params.account; + const notifications = await getNotificationsByAccount({ account }); + reply.status(200).send(notifications); + return reply.send(notifications); + }); +}; + +export default accounts;