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) {
|
||||||
this.routerMap.add(typedRouterArg);
|
const routerExists = this.routerMap.findSync(routerArg => routerArg === typedRouterArg)
|
||||||
typedRouterArg.setUpstreamTypedRouter(this);
|
if (!routerExists) {
|
||||||
}
|
this.routerMap.add(typedRouterArg);
|
||||||
|
typedRouterArg.addTypedRouter(this);
|
||||||
public setUpstreamTypedRouter(typedRouterArg: TypedRouter) {
|
}
|
||||||
this.upstreamTypedRouter = typedRouterArg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public checkForTypedHandler(methodArg: string): boolean {
|
public checkForTypedHandler(methodArg: string): boolean {
|
||||||
@ -64,24 +60,22 @@ 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.handlerMap.findSync((handler) => {
|
||||||
typedHandler = this.upstreamTypedRouter.getTypedHandlerForMethod(methodArg);
|
return handler.method === methodArg;
|
||||||
} else {
|
});
|
||||||
typedHandler = this.handlerMap.findSync((handler) => {
|
|
||||||
return handler.method === methodArg;
|
if (!typedHandler) {
|
||||||
|
this.routerMap.getArray().forEach((typedRouterArg) => {
|
||||||
|
if (!typedHandler && !checkedRouters.includes(typedRouterArg)) {
|
||||||
|
typedHandler = typedRouterArg.getTypedHandlerForMethod(methodArg, checkedRouters);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!typedHandler) {
|
|
||||||
this.routerMap.getArray().forEach((typedRouter) => {
|
|
||||||
if (!typedHandler) {
|
|
||||||
typedHandler = typedRouter.getTypedHandlerForMethod(methodArg, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return typedHandler;
|
return typedHandler;
|
||||||
|
Loading…
Reference in New Issue
Block a user