Files
sendico/frontend/pshared/lib/data/mapper/recipient/recipient.dart
Stephan D bf85ca062c
All checks were successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
restucturization of recipients payment methods
2025-12-04 14:42:25 +01:00

86 lines
2.5 KiB
Dart

import 'package:pshared/data/dto/recipient/recipient.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/organization/bound.dart';
import 'package:pshared/models/permissions/bound.dart';
import 'package:pshared/models/recipient/recipient_model.dart';
import 'package:pshared/models/recipient/status.dart';
import 'package:pshared/models/recipient/type.dart';
import 'package:pshared/models/storable.dart';
extension RecipientModelMapper on RecipientModel {
RecipientDTO toDTO() => RecipientDTO(
id: storable.id,
createdAt: storable.createdAt,
updatedAt: storable.updatedAt,
permissionRef: permissionBound.permissionRef,
organizationRef: permissionBound.organizationRef,
name: name,
description: description,
email: email,
avatarUrl: avatarUrl,
status: _recipientStatusToValue(status),
type: _recipientTypeToValue(type),
isArchived: isArchived,
);
}
extension RecipientDTOMapper on RecipientDTO {
RecipientModel toDomain() => RecipientModel(
storable: newStorable(id: id, createdAt: createdAt, updatedAt: updatedAt),
permissionBound: newPermissionBound(
organizationBound: newOrganizationBound(organizationRef: organizationRef),
permissionRef: permissionRef,
),
describable: newDescribable(name: name, description: description),
email: email,
avatarUrl: avatarUrl,
status: _recipientStatusFromValue(status),
type: _recipientTypeFromValue(type),
isArchived: isArchived,
);
}
RecipientStatus _recipientStatusFromValue(String value) {
switch (value) {
case 'ready':
return RecipientStatus.ready;
case 'registered':
return RecipientStatus.registered;
case 'notRegistered':
return RecipientStatus.notRegistered;
default:
return RecipientStatus.ready;
}
}
String _recipientStatusToValue(RecipientStatus status) {
switch (status) {
case RecipientStatus.ready:
return 'ready';
case RecipientStatus.registered:
return 'registered';
case RecipientStatus.notRegistered:
return 'notRegistered';
}
}
RecipientType _recipientTypeFromValue(String value) {
switch (value) {
case 'external':
return RecipientType.external;
case 'internal':
default:
return RecipientType.internal;
}
}
String _recipientTypeToValue(RecipientType type) {
switch (type) {
case RecipientType.internal:
return 'internal';
case RecipientType.external:
return 'external';
}
}