feat: implement AI categorization for products and add premium access guard

This commit is contained in:
Nils-Johan Gynther
2026-04-21 13:55:12 +02:00
parent 83722123d2
commit 864c84d2e5
5 changed files with 73 additions and 40 deletions
@@ -0,0 +1,18 @@
import { CanActivate, ExecutionContext, ForbiddenException, Injectable } from '@nestjs/common';
/**
* Tillåter åtkomst om användaren är admin eller har isPremium = true.
* Används som alternativ till @Roles('admin') där premium-användare ska ha samma rättighet.
*/
@Injectable()
export class PremiumOrAdminGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const { user } = context.switchToHttp().getRequest();
if (user?.role === 'admin' || user?.isPremium === true) {
return true;
}
throw new ForbiddenException('Denna funktion kräver premiumkonto eller admin-behörighet.');
}
}