Merge pull request #247 from Tria-plc/freight/fix/api

fix
This commit is contained in:
Nathnael Wondisha
2026-06-23 10:04:28 +03:00
committed by GitHub

View File

@@ -116,7 +116,7 @@ export class CompaniesService {
jobTitle: dto.jobTitle ?? null,
isPrimaryContact: dto.isPrimaryContact ?? true,
activeProfileType,
onboardingStep: 'company',
onboardingStep: "company",
});
// Persist the operational role(s) chosen during onboarding. Types are
@@ -158,6 +158,8 @@ export class CompaniesService {
async getCompanyStats(): Promise<CompanyStatsResponseDto> {
return this.companiesRepo.getStats();
}
/**
* Begin onboarding: create a DRAFT company + the user's external profile + the
* chosen operational role(s) up front, so every subsequent wizard step can
@@ -263,7 +265,10 @@ export class CompaniesService {
private async generateDraftTin(): Promise<string> {
for (let i = 0; i < 10; i++) {
const candidate =
"D" + Math.floor(Math.random() * 1_000_000_000).toString().padStart(9, "0");
"D" +
Math.floor(Math.random() * 1_000_000_000)
.toString()
.padStart(9, "0");
if (!(await this.companiesRepo.existsByTin(candidate))) return candidate;
}
// Extremely unlikely; fall back to a timestamp-derived value.
@@ -293,8 +298,9 @@ export class CompaniesService {
`Company for profile ${profile.id} not found`,
);
company.companyProfiles =
await this.companyProfilesRepo.findByCompanyId(company.id);
company.companyProfiles = await this.companyProfilesRepo.findByCompanyId(
company.id,
);
return { profile, company };
}
@@ -325,9 +331,9 @@ export class CompaniesService {
// one resolves; otherwise aggregate across the whole company.
const companyProfileId = profile?.activeProfileType
? ((await this.companyProfilesRepo.findByType(
companyId,
profile.activeProfileType,
)) ?? null)
companyId,
profile.activeProfileType,
)) ?? null)
: null;
const scope = companyProfileId
? { companyProfileId: companyProfileId.id }
@@ -540,18 +546,12 @@ export class CompaniesService {
companyUpdates.renewedFrom = dto.renewedFrom;
if (dto.renewalDate !== undefined)
companyUpdates.renewalDate = dto.renewalDate;
if (dto.renewedTo !== undefined)
companyUpdates.renewedTo = dto.renewedTo;
if (dto.region !== undefined)
companyUpdates.region = dto.region;
if (dto.zone !== undefined)
companyUpdates.zone = dto.zone;
if (dto.woreda !== undefined)
companyUpdates.woreda = dto.woreda;
if (dto.kebele !== undefined)
companyUpdates.kebele = dto.kebele;
if (dto.houseNo !== undefined)
companyUpdates.houseNo = dto.houseNo;
if (dto.renewedTo !== undefined) companyUpdates.renewedTo = dto.renewedTo;
if (dto.region !== undefined) companyUpdates.region = dto.region;
if (dto.zone !== undefined) companyUpdates.zone = dto.zone;
if (dto.woreda !== undefined) companyUpdates.woreda = dto.woreda;
if (dto.kebele !== undefined) companyUpdates.kebele = dto.kebele;
if (dto.houseNo !== undefined) companyUpdates.houseNo = dto.houseNo;
if (dto.etradePhone !== undefined)
companyUpdates.etradePhone = normalizeE164(dto.etradePhone);
@@ -617,7 +617,10 @@ export class CompaniesService {
profileId: string,
status: ProfileStatus,
): Promise<CompanyProfile> {
const updated = await this.companyProfilesRepo.updateStatus(profileId, status);
const updated = await this.companyProfilesRepo.updateStatus(
profileId,
status,
);
if (!updated)
throw new NotFoundException(`Company profile ${profileId} not found`);
return updated;
@@ -923,9 +926,9 @@ export class CompaniesService {
if (profiles.length === 0) return null;
const naturalType =
tradeDirection === 'IMPORT'
tradeDirection === "IMPORT"
? ProfileType.importer
: tradeDirection === 'EXPORT'
: tradeDirection === "EXPORT"
? ProfileType.exporter
: null;