-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
apps/api/src/app/routes/accounts/_account/notifications/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |