refactor: add cleanup for expired subscriptions

This commit is contained in:
zhom
2026-03-02 18:49:47 +04:00
parent 3cb68c53ad
commit 23d25928fc
13 changed files with 247 additions and 17 deletions
@@ -0,0 +1,38 @@
import {
Body,
Controller,
Headers,
HttpCode,
Post,
UnauthorizedException,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { SyncService } from "./sync.service.js";
@Controller("v1/internal")
export class InternalController {
private readonly internalKey: string | undefined;
constructor(
private readonly syncService: SyncService,
private readonly configService: ConfigService,
) {
this.internalKey = this.configService.get<string>("INTERNAL_KEY");
}
@Post("cleanup-excess-profiles")
@HttpCode(200)
async cleanupExcessProfiles(
@Headers("x-internal-key") key: string,
@Body() body: { userId: string; maxProfiles: number },
) {
if (!this.internalKey || key !== this.internalKey) {
throw new UnauthorizedException("Invalid internal key");
}
return this.syncService.cleanupExcessProfiles(
body.userId,
body.maxProfiles,
);
}
}