I have a Quota service with the following method:
async decrementWithQuota(user: IUser) {
if (!user) {
throw new UnauthorizedException();
}
const today = new Date();
const updateResult = await this.quotaRepository.decrement(
{
user,
year: today.getFullYear(),
month: today.getMonth(),
day: today.getDate(),
limit: MoreThan(0)
},
'limit',
1
);
if (updateResult.affected === 1) {
return updateResult;
}
if (updateResult.affected === 0) {
throw new ForbiddenException('Exceeded todays quota');
}
throw new ConflictException(
'too many quotas being affected by single increment.'
);
}
should i use a guard, a pipe or an interceptor to call this method on requests with quota? While I am pretty comfortable playing around with Nest, these kind of decisions seem to confuse me. I also want an user to be passed to the method (which I absolutely can do with a Pipe in my @User decorator), but i want your input