Skip to content

Commit

Permalink
feat: expose notifications api
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Jul 30, 2024
1 parent f244bc8 commit ce1dd8e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/api/src/app/routes/accounts/_account/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof routeSchema>;

type GetNotificationsSchema = RouteSchema;

const accounts: FastifyPluginAsync = async (fastify): Promise<void> => {
// 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;

0 comments on commit ce1dd8e

Please sign in to comment.