This commit is contained in:
keyhan
2026-04-05 15:22:01 +03:30
commit 33be1649c4
82 changed files with 23956 additions and 0 deletions
@@ -0,0 +1,5 @@
import { SetMetadata } from '@nestjs/common';
import { UserRole } from '../enums';
export const ROLES_KEY = 'roles';
export const Roles = (...roles: UserRole[]) => SetMetadata(ROLES_KEY, roles);
+41
View File
@@ -0,0 +1,41 @@
// Shared enums used across the platform
export enum UserRole {
USER = 'user',
ADMIN = 'admin',
}
export enum AppRuntime {
NODEJS = 'nodejs',
LARAVEL = 'laravel',
}
export enum DatabaseType {
MYSQL = 'mysql',
POSTGRESQL = 'postgresql',
NONE = 'none',
}
export enum DeploymentStatus {
PENDING = 'pending',
BUILDING = 'building',
BUILD_FAILED = 'build_failed',
DEPLOYING = 'deploying',
RUNNING = 'running',
FAILED = 'failed',
STOPPED = 'stopped',
DELETING = 'deleting',
}
export enum ClusterStatus {
ACTIVE = 'active',
INACTIVE = 'inactive',
MAINTENANCE = 'maintenance',
}
export enum BuildStatus {
QUEUED = 'queued',
IN_PROGRESS = 'in_progress',
SUCCESS = 'success',
FAILED = 'failed',
}
+23
View File
@@ -0,0 +1,23 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { UserRole } from '../enums';
import { ROLES_KEY } from '../decorators/roles.decorator';
@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.getAllAndOverride<UserRole[]>(ROLES_KEY, [
context.getHandler(),
context.getClass(),
]);
if (!requiredRoles) {
return true;
}
const { user } = context.switchToHttp().getRequest();
return requiredRoles.some((role) => user.role === role);
}
}