mercredi 29 août 2018

Can we use await and same functions for promises?

So i have request coming in based that i am building this.request array so i can make calls to urls and request.body pushed into it , In below code if i am trying to use RequestResponseHandler.processRequest for both promises but its always going into spec when i call same function processRequest for other promise , How can i make sure if processRequest is called for spec ignore that if condition and go to PTM

request

{ lineOfBusiness: ["spec","PTM"] , body: data }

handler.ts

    export class RequestResponseHandler {
        public static processRequest(data: any, url: string): Promise < any > {
            const reqObject: IRequestURL = {}
            as IRequestURL;
            const lob = data.header.lineOfBusiness;
            if (lob === "spec") {
                const specUrl = urlConfig + url;
                reqObject.url = specUrl;
                reqObject.body = data;
            }
            if (lob === "PTM") {
                const ptmUrl = urlConfig + url;
                reqObject.url = ptmUrl;
                reqObject.body = data;
            }
        }
    }

controllet.ts

 const bRetSpec: boolean = await this.specBalanceRequest(request);
        const bRetPtm: boolean = await this.ptmBalanceRequest(request);

    private async specBalanceRequest(@Body() request: ExpressRequest): Promise < boolean > {
        const specUrl = "/payments";
        const reqObject = await RequestResponseHandler.processRequest(request.body, specialtyUrl);
        this._request.push(reqObject);
        return Promise.resolve(true);
    }

    private async ptmBalanceRequest(@Body() request: any): Promise < boolean > {
        const careURL = "/Order";
        const reqObject = await RequestResponseHandler.processRequest(request.body, caremarkURL);
        this._request.push(reqObject);
        return Promise.resolve(true);
    }

Aucun commentaire:

Enregistrer un commentaire