forked from dilan-dio4/Keagate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivePayments.ts
33 lines (30 loc) · 1.34 KB
/
activePayments.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Static, Type } from '@sinclair/typebox';
import { FastifyInstance, RouteShorthandOptions } from 'fastify';
import { MongoPayment, ForRequest } from '../types';
import auth from '../middlewares/auth';
import context from '../context';
import { MongoTypeForRequest, cleanDetails, AdminRouteHeaders } from './types';
const ActivePaymentsResponse = Type.Array(MongoTypeForRequest, { description: 'Successful response of array of all active payments' });
const opts: RouteShorthandOptions = {
schema: {
response: {
200: ActivePaymentsResponse,
},
headers: AdminRouteHeaders,
tags: ['Payment'],
description: 'Fetch an array of all active payments. Payments that have been completed or expired will not appear here.',
summary: 'Fetch an array of all active payments',
security: [
{
ApiKey: [],
},
],
},
preHandler: auth,
};
export default async function createActivePaymentsRoute(server: FastifyInstance) {
server.get<{ Reply: Static<typeof ActivePaymentsResponse> }>('/activePayments', opts, async (request, reply) => {
const cleanedTransactions: ForRequest<MongoPayment>[] = Object.values(context.activePayments).map((ele) => cleanDetails(ele.getDetails()));
reply.status(200).send(cleanedTransactions);
});
}