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 May 17, 2024
1 parent 5d12914 commit 0344b93
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 0344b93

Please sign in to comment.