[FIX] fix(backend): Resolve all TypeScript errors for clean build
Some checks are pending
CI / Backend CI (push) Waiting to run
CI / Frontend CI (push) Waiting to run
CI / Security Scan (push) Waiting to run
CI / CI Summary (push) Blocked by required conditions

- 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:
Adrian Flores Cortes 2026-01-25 02:24:24 -06:00
parent 99ec74d9f8
commit 72bbc1af23
9 changed files with 76 additions and 21 deletions

View File

@ -0,0 +1,4 @@
import { SetMetadata } from '@nestjs/common';
export const ROLES_KEY = 'roles';
export const Roles = (...roles: string[]) => SetMetadata(ROLES_KEY, roles);

View 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));
}
}

View File

@ -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';

View File

@ -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';

View File

@ -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 () => {

View File

@ -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()

View File

@ -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(

View File

@ -0,0 +1,2 @@
// Re-export from auth module for backwards compatibility
export { CurrentTenant } from '../../auth/decorators/tenant.decorator';

View File

@ -0,0 +1,2 @@
// Re-export CurrentTenant as TenantId for backwards compatibility
export { CurrentTenant as TenantId } from '../../auth/decorators/tenant.decorator';