enhance company approval workflow and TIN validation; add pending approval handling in booking and onboarding forms

This commit is contained in:
Marshal
2026-06-23 08:37:15 +00:00
parent 1d77f377f3
commit 6fd1b68389
13 changed files with 276 additions and 59 deletions

View File

@@ -11,6 +11,7 @@ import { Freight, SchedulingStatus } from '@edr/types';
// import { CustomersService } from '../customers/customers.service';
import { CompaniesService } from '../companies/companies.service';
import { ProfileType } from '../companies/entities/company-profile.entity';
import { CompanyStatus } from '../companies/entities/company.entity';
import { TrainSchedulingService } from '../train-scheduling/train-scheduling.service';
import { eatDay } from '../train-scheduling/batch-window.util';
import { FilesService } from '../files/files.service';
@@ -287,6 +288,12 @@ export class BookingsService {
);
}
const { company } = await this.companiesService.getCompanyInfoByUserId(userId);
// A customer can only book once their company has been approved.
if (company.status !== CompanyStatus.Active) {
throw new ForbiddenException(
"Your company is awaiting approval — you can't create bookings yet.",
);
}
companyId = company.id;
}

View File

@@ -844,8 +844,9 @@ export class CompaniesService {
onboardingCompleted: true,
onboardingStep: "done",
});
// Awaiting backoffice approval — stays Pending until an admin activates it.
await this.companiesRepo.update(companyId, {
status: CompanyStatus.Active,
status: CompanyStatus.Pending,
});
return this.getCompanyInfoByUserId(userId);
}

View File

@@ -18,7 +18,9 @@ export class CreateCompanyDto {
@IsString()
@IsNotEmpty()
@Length(10, 10)
@Matches(/^\d+$/, { message: 'TIN must contain only digits' })
@Matches(/^00\d{8}$/, {
message: 'TIN must be 10 digits starting with 00',
})
tin!: string;
@IsOptional()

View File

@@ -35,7 +35,9 @@ export class UpdateProfileDto {
@IsOptional()
@IsString()
@Length(10, 10)
@Matches(/^\d+$/, { message: 'TIN must contain only digits' })
@Matches(/^00\d{8}$/, {
message: 'TIN must be 10 digits starting with 00',
})
tin?: string;
@IsOptional()