import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { ProposalQuota } from '@task-stream/api/tracker/application'; /** The proposal quota, as the HTTP answer: 429 once it is used up. */ @Injectable() export class ProposalLimiter { constructor(private readonly quota: ProposalQuota) {} async take(address: string): Promise { if (!(await this.quota.take(address))) throw new HttpException( 'Too many proposals from here; try again in a few minutes', HttpStatus.TOO_MANY_REQUESTS, ); } }