我有两个将基于请求的调用,它可能是单个调用,也可能是两个api调用,所以我在下面的代码中实现了不确定那是否是使用promise.all的正确方法,也想抛出错误回到用户,以防任何诺言失败。
execute
函数从路由执行。
如果有更好的实施方法,我将感谢您的反馈。
main.ts
public async execute(@Request() request: express.Request): Promise<[any] | any> {
if (request.body.lob === "credit") {
return this.getCardDetails(request);
}
if (request.body.lob === "individual") {
return this.getAccountDetails(request);
}
return Promise.all([this.getCardDetails(request), this.getAccountDetails(request)]);
}
@Post('getAccountDetails')
private async getAccountDetails(@Body() request: any): Promise<any> {
// process retrieveData Call and get response
}
@Post('getCardDetails')
private async getCardDetails(@Body() request: any): Promise<any> {
// process cardDetails Call and get response
}