From d53e5c75722e3d8aae5dae6594687f0e759466f8 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Fri, 17 May 2024 16:08:06 +0100 Subject: [PATCH 1/4] 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; From 214cc036601d43f10e6eb580c21244152cda8ff8 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Tue, 30 Jul 2024 18:28:34 +0100 Subject: [PATCH 2/4] Expose notifications --- .../index.ts => notifications.ts} | 18 ++++++++++++------ libs/cms-api/src/index.ts | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) rename apps/api/src/app/routes/accounts/_account/{notifications/index.ts => notifications.ts} (67%) diff --git a/apps/api/src/app/routes/accounts/_account/notifications/index.ts b/apps/api/src/app/routes/accounts/_account/notifications.ts similarity index 67% rename from apps/api/src/app/routes/accounts/_account/notifications/index.ts rename to apps/api/src/app/routes/accounts/_account/notifications.ts index 8e0304b..cfaba41 100644 --- a/apps/api/src/app/routes/accounts/_account/notifications/index.ts +++ b/apps/api/src/app/routes/accounts/_account/notifications.ts @@ -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', @@ -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; type GetNotificationsSchema = RouteSchema; @@ -25,12 +28,15 @@ const accounts: FastifyPluginAsync = async (fastify): Promise => { 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; diff --git a/libs/cms-api/src/index.ts b/libs/cms-api/src/index.ts index 484375c..58dac1e 100644 --- a/libs/cms-api/src/index.ts +++ b/libs/cms-api/src/index.ts @@ -67,7 +67,7 @@ export async function getNotificationsByAccount({ throw error; } - return data.data; + return data; } export async function getAllNotifications(): Promise { From dca4b03df766d0ab520364c299092cec4d014cc8 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Tue, 30 Jul 2024 18:28:53 +0100 Subject: [PATCH 3/4] Remove unused import --- .../__baseTokenAddress-__quoteTokenAddress/slippageTolerance.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/app/routes/__chainId/markets/__baseTokenAddress-__quoteTokenAddress/slippageTolerance.ts b/apps/api/src/app/routes/__chainId/markets/__baseTokenAddress-__quoteTokenAddress/slippageTolerance.ts index e990d06..4cb08db 100644 --- a/apps/api/src/app/routes/__chainId/markets/__baseTokenAddress-__quoteTokenAddress/slippageTolerance.ts +++ b/apps/api/src/app/routes/__chainId/markets/__baseTokenAddress-__quoteTokenAddress/slippageTolerance.ts @@ -7,7 +7,6 @@ import { CACHE_CONTROL_HEADER, getCacheControlHeaderValue, } from '../../../../../utils/cache'; -import { deprecate } from 'util'; const CACHE_SECONDS = 120; @@ -31,6 +30,7 @@ const routeSchema = { }, }, } as const satisfies JSONSchema; + const successSchema = { type: 'object', required: ['slippageBps'], From 8458d79d6ca747fd05b58c9748a120fe7f505f9e Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Wed, 31 Jul 2024 16:07:47 +0100 Subject: [PATCH 4/4] Remove test --- apps/api/src/app/routes/accounts/_account/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/app/routes/accounts/_account/notifications.ts b/apps/api/src/app/routes/accounts/_account/notifications.ts index cfaba41..80be43c 100644 --- a/apps/api/src/app/routes/accounts/_account/notifications.ts +++ b/apps/api/src/app/routes/accounts/_account/notifications.ts @@ -34,7 +34,7 @@ const accounts: FastifyPluginAsync = async (fastify): Promise => { async function (request, reply) { const account = request.params.account; const notifications = await getNotificationsByAccount({ account }); - reply.send([]); + reply.send(notifications); } ); };