UNPKG

@tsed/schema

Version:
33 lines (32 loc) 1.33 kB
import { JsonOperationRoute } from "../domain/JsonOperationRoute.js"; import { concatPath } from "./concatPath.js"; import { getJsonEntityStore } from "./getJsonEntityStore.js"; import { getOperationsStores } from "./getOperationsStores.js"; export function getOperationsRoutes(token, options = {}) { const store = token.isStore ? token : getJsonEntityStore(token); const basePath = concatPath(options.basePath, store.path); let operationsRoutes = []; if (options.withChildren) { const children = store.get("childrenControllers", []); operationsRoutes = children.reduce((operationsRoutes, token) => { return operationsRoutes.concat(getOperationsRoutes(token, { ...options, basePath })); }, operationsRoutes); } return [...getOperationsStores(token).values()].reduce((routes, endpoint) => { const { operation } = endpoint; if (operation) { operation.getAllowedOperationPath(options.allowedVerbs).forEach((operationPath) => { routes.push(new JsonOperationRoute({ basePath, token, endpoint, operationPath })); }); } return routes; }, operationsRoutes); }