[FIX] fix(backend): Resolve all TypeScript errors for clean build
- Added missing decorators: roles.decorator.ts, roles.guard.ts - Added tenant decorators: current-tenant.decorator.ts, tenant-id.decorator.ts - Fixed duplicate exports in commissions/services/index.ts - Fixed duplicate exports in sales/services/index.ts - Fixed TenantStatus type in superadmin DTOs (string -> enum) - Fixed status array type in superadmin.service.ts - Fixed test file to use valid status value Backend now builds successfully with 0 TypeScript errors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
99ec74d9f8
commit
72bbc1af23
@ -0,0 +1,4 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const ROLES_KEY = 'roles';
|
||||
export const Roles = (...roles: string[]) => SetMetadata(ROLES_KEY, roles);
|
||||
29
apps/backend/src/modules/auth/guards/roles.guard.ts
Normal file
29
apps/backend/src/modules/auth/guards/roles.guard.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
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<string[]>(ROLES_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
|
||||
if (!requiredRoles) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { user } = context.switchToHttp().getRequest();
|
||||
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if user has any of the required roles
|
||||
const userRoles = user.roles || [];
|
||||
return requiredRoles.some((role) => userRoles.includes(role));
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,12 @@
|
||||
export * from './schemes.service';
|
||||
export * from './assignments.service';
|
||||
export * from './entries.service';
|
||||
export * from './periods.service';
|
||||
export * from './commissions-dashboard.service';
|
||||
// Export pagination types only from schemes.service to avoid duplicates
|
||||
export {
|
||||
SchemesService,
|
||||
PaginatedResult,
|
||||
PaginationOptions
|
||||
} from './schemes.service';
|
||||
|
||||
// Export other services without pagination types (they re-declare the same interfaces)
|
||||
export { AssignmentsService } from './assignments.service';
|
||||
export { EntriesService } from './entries.service';
|
||||
export { PeriodsService } from './periods.service';
|
||||
export { CommissionsDashboardService } from './commissions-dashboard.service';
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
export * from './leads.service';
|
||||
export * from './opportunities.service';
|
||||
export * from './pipeline.service';
|
||||
export * from './activities.service';
|
||||
export * from './sales-dashboard.service';
|
||||
// Export pagination types only from leads.service to avoid duplicates
|
||||
export {
|
||||
LeadsService,
|
||||
LeadFilters,
|
||||
PaginatedResult,
|
||||
PaginationOptions
|
||||
} from './leads.service';
|
||||
|
||||
// Export other services without pagination types (they re-declare the same interfaces)
|
||||
export { OpportunitiesService, OpportunityFilters } from './opportunities.service';
|
||||
export { PipelineService } from './pipeline.service';
|
||||
export { ActivitiesService, ActivityFilters } from './activities.service';
|
||||
export { SalesDashboardService } from './sales-dashboard.service';
|
||||
|
||||
@ -180,7 +180,7 @@ describe('SuperadminService', () => {
|
||||
name: 'New Company',
|
||||
slug: 'new-company',
|
||||
domain: 'new.example.com',
|
||||
status: 'trial',
|
||||
status: 'pending' as const,
|
||||
};
|
||||
|
||||
it('should create a new tenant', async () => {
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import { IsString, IsOptional, IsEnum, IsNumber, Min, Max, IsUUID } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
// Type that matches Tenant entity status enum
|
||||
export type TenantStatus = 'pending' | 'active' | 'suspended' | 'cancelled';
|
||||
|
||||
export class CreateTenantDto {
|
||||
@ApiProperty({ description: 'Tenant name' })
|
||||
@IsString()
|
||||
@ -25,10 +28,10 @@ export class CreateTenantDto {
|
||||
@IsOptional()
|
||||
plan_id?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Initial status', enum: ['active', 'trial', 'suspended'] })
|
||||
@IsEnum(['active', 'trial', 'suspended'])
|
||||
@ApiPropertyOptional({ description: 'Initial status', enum: ['pending', 'active', 'suspended', 'cancelled'] })
|
||||
@IsEnum(['pending', 'active', 'suspended', 'cancelled'])
|
||||
@IsOptional()
|
||||
status?: string;
|
||||
status?: TenantStatus;
|
||||
}
|
||||
|
||||
export class UpdateTenantDto {
|
||||
@ -62,9 +65,9 @@ export class UpdateTenantDto {
|
||||
}
|
||||
|
||||
export class UpdateTenantStatusDto {
|
||||
@ApiProperty({ description: 'New status', enum: ['active', 'suspended', 'trial', 'canceled'] })
|
||||
@IsEnum(['active', 'suspended', 'trial', 'canceled'])
|
||||
status: string;
|
||||
@ApiProperty({ description: 'New status', enum: ['pending', 'active', 'suspended', 'cancelled'] })
|
||||
@IsEnum(['pending', 'active', 'suspended', 'cancelled'])
|
||||
status: TenantStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Reason for status change' })
|
||||
@IsString()
|
||||
@ -91,10 +94,10 @@ export class ListTenantsQueryDto {
|
||||
@IsOptional()
|
||||
search?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Filter by status', enum: ['active', 'suspended', 'trial', 'canceled'] })
|
||||
@IsEnum(['active', 'suspended', 'trial', 'canceled'])
|
||||
@ApiPropertyOptional({ description: 'Filter by status', enum: ['pending', 'active', 'suspended', 'cancelled'] })
|
||||
@IsEnum(['pending', 'active', 'suspended', 'cancelled'])
|
||||
@IsOptional()
|
||||
status?: string;
|
||||
status?: TenantStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Sort by field', enum: ['name', 'created_at', 'status'] })
|
||||
@IsString()
|
||||
|
||||
@ -347,7 +347,7 @@ export class SuperadminService {
|
||||
}
|
||||
|
||||
async getStatusDistribution(): Promise<{ status: string; count: number; percentage: number }[]> {
|
||||
const statuses = ['active', 'pending', 'suspended', 'cancelled'];
|
||||
const statuses: Array<'active' | 'pending' | 'suspended' | 'cancelled'> = ['active', 'pending', 'suspended', 'cancelled'];
|
||||
const total = await this.tenantRepository.count();
|
||||
|
||||
const result = await Promise.all(
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
// Re-export from auth module for backwards compatibility
|
||||
export { CurrentTenant } from '../../auth/decorators/tenant.decorator';
|
||||
@ -0,0 +1,2 @@
|
||||
// Re-export CurrentTenant as TenantId for backwards compatibility
|
||||
export { CurrentTenant as TenantId } from '../../auth/decorators/tenant.decorator';
|
||||
Loading…
Reference in New Issue
Block a user