diff --git a/ExpressAPI/src/middlewares/ParamsCallbackManager.ts b/ExpressAPI/src/middlewares/ParamsCallbackManager.ts index 0c5f6b19720296cd8fc35d838c15849ec53e7b73..7626cde6992de4b765145a57eb3069cf93b3c249 100644 --- a/ExpressAPI/src/middlewares/ParamsCallbackManager.ts +++ b/ExpressAPI/src/middlewares/ParamsCallbackManager.ts @@ -2,6 +2,7 @@ import { Express } from 'express-serve-static-core'; import ApiRequest from '../models/ApiRequest'; import express from 'express'; import { StatusCodes } from 'http-status-codes'; +import EnonceManager from '../managers/EnonceManager'; class ParamsCallbackManager { @@ -18,8 +19,8 @@ class ParamsCallbackManager { } protected listenParam(paramName: string, backend: Express, context: any, functionName: string, indexName: string) { - backend.param(paramName, (req: ApiRequest, res: express.Response, next: express.NextFunction, id: number | string) => { - (context[functionName] as (id: number | Array<number>) => Promise<any>)(typeof id === 'string' ? JSON.parse(id) as Array<number> : id).then(result => { + backend.param(paramName, (req: ApiRequest, res: express.Response, next: express.NextFunction, id: string | number) => { + (context[functionName] as (id: string | number) => Promise<any>)(id).then(result => { if ( result ) { this.initBoundParams(req); (req.boundParams as any)[indexName] = result; @@ -34,11 +35,14 @@ class ParamsCallbackManager { initBoundParams(req: ApiRequest) { if ( !req.boundParams ) { - req.boundParams = {}; + req.boundParams = { + enonce: null + }; } } register(backend: Express) { + this.listenParam('enonceNameOrUrl', backend, EnonceManager, 'get', 'enonce'); } } diff --git a/ExpressAPI/src/models/ApiRequest.ts b/ExpressAPI/src/models/ApiRequest.ts index 5b0d0888bc81da7d48cdd206fc034ea2cf8e1032..a0a3238578ca63775ef9f40e6ce6591f5077ee1f 100644 --- a/ExpressAPI/src/models/ApiRequest.ts +++ b/ExpressAPI/src/models/ApiRequest.ts @@ -1,9 +1,12 @@ import express from 'express'; import Session from '../controllers/Session'; +import Enonce from './Enonce'; type ApiRequest = express.Request & { - session: Session, boundParams: {} + session: Session, boundParams: { + enonce: Enonce + } }