Files
task-stream/libs/api/tracker/presenters/src/lib/http/proposal-limiter.ts
Josep Piguillem 1383e15f3f fix(api): the API failed to start after moving the proposal limit to Redis
ProposalLimiter, in the presenters, asked for the RateLimitStore port,
which only the application layer sees, so Nest could not build it and
the container never became healthy. The count now lives in an
application service, ProposalQuota; the presenter only answers 429.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 21:01:38 +02:00

17 lines
558 B
TypeScript

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<void> {
if (!(await this.quota.take(address)))
throw new HttpException(
'Too many proposals from here; try again in a few minutes',
HttpStatus.TOO_MANY_REQUESTS,
);
}
}