0

I am working to translate the following example code to a functional approach:

let [state, cities] = await Promise.all([States.find({name: name}).limit(1).exec(), Cities({stateName: name}).exec()]);
state = convertToAnObject(state);

if (state && await state.hasRequiredPopulation()) {
    return cities;
} else {
    throw new NotFoundError("There are no cities for " + name + " that match the necessary requirements.");
}

I am having trouble seeing how this should be translated to a pipeline, etc. accounting for the Promise.all, control structure (if-then-else) and error handling. Granted, it seems as if I would use encaseP for the Promise.all but it gets confusing after that.

Can someone provide a fluture translation example for this case?

4

0 回答 0