Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose notifications api #33

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CACHE_CONTROL_HEADER,
getCacheControlHeaderValue,
} from '../../../../../utils/cache';
import { deprecate } from 'util';

const CACHE_SECONDS = 120;

Expand All @@ -31,6 +30,7 @@ const routeSchema = {
},
},
} as const satisfies JSONSchema;

const successSchema = {
type: 'object',
required: ['slippageBps'],
Expand Down
42 changes: 42 additions & 0 deletions apps/api/src/app/routes/accounts/_account/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
NotificationModel,
getNotificationsByAccount,
} 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',
required: ['account'],
properties: {
account: {
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;

const accounts: FastifyPluginAsync = async (fastify): Promise<void> => {
// GET /accounts/:account/notifications
fastify.get<{
Params: GetNotificationsSchema;
Reply: NotificationModel[];
}>(
'/notifications',
{ schema: { params: routeSchema } },
async function (request, reply) {
const account = request.params.account;
const notifications = await getNotificationsByAccount({ account });
reply.send(notifications);
}
);
};

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
Loading