84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import {
|
|
Organization,
|
|
OrganizationAddress,
|
|
OrganizationDocument,
|
|
} from '../../domain/entities/organization.entity';
|
|
import {
|
|
OrganizationResponseDto,
|
|
OrganizationDocumentDto,
|
|
AddressDto,
|
|
} from '../dto/organization.dto';
|
|
|
|
/**
|
|
* Organization Mapper
|
|
*
|
|
* Maps between Organization domain entities and DTOs
|
|
*/
|
|
export class OrganizationMapper {
|
|
/**
|
|
* Convert Organization entity to DTO
|
|
*/
|
|
static toDto(organization: Organization): OrganizationResponseDto {
|
|
return {
|
|
id: organization.id,
|
|
name: organization.name,
|
|
type: organization.type,
|
|
scac: organization.scac,
|
|
address: this.mapAddressToDto(organization.address),
|
|
logoUrl: organization.logoUrl,
|
|
documents: organization.documents.map(doc => this.mapDocumentToDto(doc)),
|
|
isActive: organization.isActive,
|
|
createdAt: organization.createdAt,
|
|
updatedAt: organization.updatedAt,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Convert array of Organization entities to DTOs
|
|
*/
|
|
static toDtoArray(organizations: Organization[]): OrganizationResponseDto[] {
|
|
return organizations.map(org => this.toDto(org));
|
|
}
|
|
|
|
/**
|
|
* Map Address entity to DTO
|
|
*/
|
|
private static mapAddressToDto(address: OrganizationAddress): AddressDto {
|
|
return {
|
|
street: address.street,
|
|
city: address.city,
|
|
state: address.state,
|
|
postalCode: address.postalCode,
|
|
country: address.country,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Map Document entity to DTO
|
|
*/
|
|
private static mapDocumentToDto(
|
|
document: OrganizationDocument,
|
|
): OrganizationDocumentDto {
|
|
return {
|
|
id: document.id,
|
|
type: document.type,
|
|
name: document.name,
|
|
url: document.url,
|
|
uploadedAt: document.uploadedAt,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Map DTO Address to domain Address
|
|
*/
|
|
static mapDtoToAddress(dto: AddressDto): OrganizationAddress {
|
|
return {
|
|
street: dto.street,
|
|
city: dto.city,
|
|
state: dto.state,
|
|
postalCode: dto.postalCode,
|
|
country: dto.country,
|
|
};
|
|
}
|
|
}
|