/** * @author Olsi Rrjolli */ import { IAwsRequestEvent } from '../types/index'; import ControllerRegistry from '../ControllerRegistry'; import MethodInformation from '../models/MethodInformation'; /** * Execute the Book Store method which will needed * @param awsRequestEvent * The awsRequestEvent (httpMethod, resource...) * @throws MethodExecuteError * If the method can't execute */ export const execute = (awsRequestEvent: IAwsRequestEvent): Promise => { let methodInformation: MethodInformation; return Promise.resolve().then(() => { methodInformation = ControllerRegistry.controllerScan(awsRequestEvent); return Reflect.apply(methodInformation.toCallMethod, undefined, methodInformation.args); }).catch((error) => { if (methodInformation) { console.trace('Execution error for selected method:', methodInformation.toCallMethod.name, error); } return Promise.reject(error); }); };