【发布时间】:2020-12-22 10:06:33
【问题描述】:
我有这个控制器:
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
}
还有服务:
const subscription = {
id: subscriptionId,
status: 'pass',
cancelledAt: null,
}
return await this.subscriptionRepository.update(
subscriptionId,
subscription
)
更新总是返回具有“影响”属性的对象。如我所见,如果它使受影响的更新值为 1,并且如果我发送不存在的订阅,则影响为 0。
因此在我的控制器中我有这个:
if (reinstatedSubscription.affected === 0) {
throw new NotFoundException('Subscription not found')
}
它确实有效,但这是唯一的方法吗? 另外,我怎样才能不返回任何内容响应?
【问题讨论】: