fix(core): update
This commit is contained in:
parent
57177074d0
commit
90c616ca41
@ -9,10 +9,7 @@ import { TypedRequest } from './typedrequest.classes.typedrequest';
|
|||||||
* This is thought for reusing the same url endpoint for different methods
|
* This is thought for reusing the same url endpoint for different methods
|
||||||
*/
|
*/
|
||||||
export class TypedRouter {
|
export class TypedRouter {
|
||||||
public upstreamTypedRouter: TypedRouter;
|
|
||||||
|
|
||||||
public routerMap = new plugins.lik.ObjectMap<TypedRouter>();
|
public routerMap = new plugins.lik.ObjectMap<TypedRouter>();
|
||||||
|
|
||||||
public handlerMap = new plugins.lik.ObjectMap<
|
public handlerMap = new plugins.lik.ObjectMap<
|
||||||
TypedHandler<any & plugins.typedRequestInterfaces.ITypedRequest>
|
TypedHandler<any & plugins.typedRequestInterfaces.ITypedRequest>
|
||||||
>();
|
>();
|
||||||
@ -45,12 +42,11 @@ export class TypedRouter {
|
|||||||
* @param typedRequest
|
* @param typedRequest
|
||||||
*/
|
*/
|
||||||
public addTypedRouter(typedRouterArg: TypedRouter) {
|
public addTypedRouter(typedRouterArg: TypedRouter) {
|
||||||
|
const routerExists = this.routerMap.findSync(routerArg => routerArg === typedRouterArg)
|
||||||
|
if (!routerExists) {
|
||||||
this.routerMap.add(typedRouterArg);
|
this.routerMap.add(typedRouterArg);
|
||||||
typedRouterArg.setUpstreamTypedRouter(this);
|
typedRouterArg.addTypedRouter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setUpstreamTypedRouter(typedRouterArg: TypedRouter) {
|
|
||||||
this.upstreamTypedRouter = typedRouterArg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public checkForTypedHandler(methodArg: string): boolean {
|
public checkForTypedHandler(methodArg: string): boolean {
|
||||||
@ -64,25 +60,23 @@ export class TypedRouter {
|
|||||||
*/
|
*/
|
||||||
public getTypedHandlerForMethod(
|
public getTypedHandlerForMethod(
|
||||||
methodArg: string,
|
methodArg: string,
|
||||||
checkUpstreamRouter = true
|
checkedRouters: TypedRouter[] = []
|
||||||
): TypedHandler<any> {
|
): TypedHandler<any> {
|
||||||
|
checkedRouters.push(this);
|
||||||
|
|
||||||
let typedHandler: TypedHandler<any>;
|
let typedHandler: TypedHandler<any>;
|
||||||
|
|
||||||
if (this.upstreamTypedRouter && checkUpstreamRouter) {
|
|
||||||
typedHandler = this.upstreamTypedRouter.getTypedHandlerForMethod(methodArg);
|
|
||||||
} else {
|
|
||||||
typedHandler = this.handlerMap.findSync((handler) => {
|
typedHandler = this.handlerMap.findSync((handler) => {
|
||||||
return handler.method === methodArg;
|
return handler.method === methodArg;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!typedHandler) {
|
if (!typedHandler) {
|
||||||
this.routerMap.getArray().forEach((typedRouter) => {
|
this.routerMap.getArray().forEach((typedRouterArg) => {
|
||||||
if (!typedHandler) {
|
if (!typedHandler && !checkedRouters.includes(typedRouterArg)) {
|
||||||
typedHandler = typedRouter.getTypedHandlerForMethod(methodArg, false);
|
typedHandler = typedRouterArg.getTypedHandlerForMethod(methodArg, checkedRouters);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return typedHandler;
|
return typedHandler;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user