Skip to content

Commit

Permalink
Expose notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Aug 2, 2024
1 parent d53e5c7 commit 214cc03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@cowprotocol/cms-api';
import { FastifyPluginAsync } from 'fastify';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { ETHEREUM_ADDRESS_PATTERN } from '../../../schemas';

const routeSchema = {
type: 'object',
Expand All @@ -13,9 +14,11 @@ const routeSchema = {
title: 'account',
description: 'Account of the user',
type: 'string',
pattern: ETHEREUM_ADDRESS_PATTERN,
},
},
} as const satisfies JSONSchema;

type RouteSchema = FromSchema<typeof routeSchema>;

type GetNotificationsSchema = RouteSchema;
Expand All @@ -25,12 +28,15 @@ const accounts: FastifyPluginAsync = async (fastify): Promise<void> => {
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);
});
}>(
'/notifications',
{ schema: { params: routeSchema } },
async function (request, reply) {
const account = request.params.account;
const notifications = await getNotificationsByAccount({ account });
reply.send([]);
}
);
};

export default accounts;
2 changes: 1 addition & 1 deletion libs/cms-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function getNotificationsByAccount({
throw error;
}

return data.data;
return data;
}

export async function getAllNotifications(): Promise<CmsNotification[]> {
Expand Down

0 comments on commit 214cc03

Please sign in to comment.