I have this controller:
async reinstate(@Param() getSubscriptionDto: GetSubscriptionDto) {
const reinstatedSubscription = await this.subscriptionsService.reinstateById(
getSubscriptionDto.id
)
if (reinstatedSubscription.affected === 0) {
throw new NotFoundException('Subscription not found')
}
return 204
}
And the service:
const subscription = {
id: subscriptionId,
status: 'pass',
cancelledAt: null,
}
return await this.subscriptionRepository.update(
subscriptionId,
subscription
)
The update always returns object, which has "affected" property. As I have seen, if it makes an update value of affected is 1, and if I send non existing subscription, affected is 0.
Thus in my controller I have this:
if (reinstatedSubscription.affected === 0) {
throw new NotFoundException('Subscription not found')
}
It does work, but is this the only way of doing it? And additionally, how can I return no content response?