Skip to content

Commit

Permalink
Remove duplication of paths and handler configuration #3334
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 18, 2024
1 parent 1fd4b82 commit f857a0b
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/http/api/configure-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,32 @@ export const configureRoutes = (
dependencies: DependenciesForCommands & DependenciesForViews,
expectedToken: string,
): void => {
router.get('/api/lists/owned-by/:ownerId', routeForNonHtmlView(ownedBy(dependencies)));

router.get('/api/status', routeForNonHtmlView(applicationStatus(dependencies)));

router.get('/api/groups', routeForNonHtmlView(groups(dependencies)));
const getEndpointsConfig = [
{
endpoint: 'lists/owned-by/:ownerId',
handler: ownedBy,
},
{
endpoint: 'status',
handler: applicationStatus,
},
{
endpoint: 'groups',
handler: groups,
},
];
pipe(
getEndpointsConfig,
RA.map((route) => ({
...route,
endpoint: `/api/${route.endpoint}`,
})),
RA.map((route) => router.get(route.endpoint, routeForNonHtmlView(route.handler(dependencies)))),
);

const configurePostMiddleware = createConfigurePostMiddleware(dependencies, expectedToken);

const config = [{
const postEndpointsConfig = [{
endpoint: 'add-article-to-list',
handler: configurePostMiddleware(addArticleToListCommandCodec, listResource.addArticle),
},
Expand Down Expand Up @@ -102,7 +119,7 @@ export const configureRoutes = (
},
];
pipe(
config,
postEndpointsConfig,
RA.map((route) => ({
...route,
endpoint: `/api/${route.endpoint}`,
Expand Down

0 comments on commit f857a0b

Please sign in to comment.