Handled missing Offer when reading

no-issue

When attempting to read a non-existent offer we were running into issues
with calling toJSON() on `null`. This updates the handling to explicitly
return null - so that the controller can correctly throw a NotFoundError
This commit is contained in:
Fabien O'Carroll 2021-10-22 14:13:04 +02:00
parent b6234d6e96
commit 49f325dde4
2 changed files with 8 additions and 0 deletions

View File

@ -134,6 +134,10 @@ class OfferRepository {
withRelated: ['product']
});
if (!model) {
return null;
}
return this.mapToOffer(model, options);
}

View File

@ -27,6 +27,10 @@ class OffersAPI {
const offer = await this.repository.getById(data.id, options);
if (!offer) {
return null;
}
return OfferMapper.toDTO(offer);
});
}