providers-in-store (#4)
Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/4 Co-authored-by: mark-cachy <marco@catelli.it> Co-committed-by: mark-cachy <marco@catelli.it>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
|
||||
class StoreModel extends Equatable {
|
||||
final String? id;
|
||||
@@ -11,6 +13,9 @@ class StoreModel extends Equatable {
|
||||
final String cap;
|
||||
final String comune;
|
||||
final String provincia;
|
||||
final List<ProviderModel> associatedProviders; // Provider associati
|
||||
final List<StaffMemberModel>
|
||||
associatedStaffMembers; // Membri dello staff associati
|
||||
|
||||
const StoreModel({
|
||||
this.id,
|
||||
@@ -23,6 +28,8 @@ class StoreModel extends Equatable {
|
||||
required this.cap,
|
||||
required this.comune,
|
||||
required this.provincia,
|
||||
this.associatedProviders = const [],
|
||||
this.associatedStaffMembers = const [],
|
||||
});
|
||||
|
||||
// Fondamentale per Equatable: definisce quali proprietà determinano l'uguaglianza
|
||||
@@ -38,6 +45,8 @@ class StoreModel extends Equatable {
|
||||
cap,
|
||||
comune,
|
||||
provincia,
|
||||
associatedProviders,
|
||||
associatedStaffMembers,
|
||||
];
|
||||
|
||||
// Il mitico copyWith per creare nuove istanze modificando solo ciò che serve
|
||||
@@ -52,6 +61,8 @@ class StoreModel extends Equatable {
|
||||
String? cap,
|
||||
String? comune,
|
||||
String? provincia,
|
||||
List<ProviderModel>? associatedProviders,
|
||||
List<StaffMemberModel>? associatedStaffMembers,
|
||||
}) {
|
||||
return StoreModel(
|
||||
id: id ?? this.id,
|
||||
@@ -64,27 +75,55 @@ class StoreModel extends Equatable {
|
||||
cap: cap ?? this.cap,
|
||||
comune: comune ?? this.comune,
|
||||
provincia: provincia ?? this.provincia,
|
||||
associatedProviders: associatedProviders ?? this.associatedProviders,
|
||||
associatedStaffMembers:
|
||||
associatedStaffMembers ?? this.associatedStaffMembers,
|
||||
);
|
||||
}
|
||||
|
||||
factory StoreModel.fromJson(Map<String, dynamic> json) {
|
||||
factory StoreModel.fromMap(Map<String, dynamic> map) {
|
||||
final providersPivotList = map['associated_providers'] as List?;
|
||||
List<ProviderModel> providers = [];
|
||||
if (providersPivotList != null) {
|
||||
providers = providersPivotList
|
||||
.where((item) => item['provider'] != null) // Sicurezza
|
||||
.map(
|
||||
(item) =>
|
||||
ProviderModel.fromMap(item['provider'] as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
final staffPivotList = map['associated_staff'] as List?;
|
||||
List<StaffMemberModel> staffMembers = [];
|
||||
if (staffPivotList != null) {
|
||||
staffMembers = staffPivotList
|
||||
.where((item) => item['staff_member'] != null) // Sicurezza
|
||||
.map(
|
||||
(item) => StaffMemberModel.fromMap(
|
||||
item['staff_member'] as Map<String, dynamic>,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
return StoreModel(
|
||||
id: json['id'] as String,
|
||||
nome: json['nome'],
|
||||
companyId: json['company_id'] as String,
|
||||
isActive: json['is_active'] ?? true,
|
||||
isPaid: json['is_paid'] ?? false,
|
||||
paymentExpiration: json['payment_expiration'] != null
|
||||
? DateTime.parse(json['payment_expiration'])
|
||||
id: map['id'] as String,
|
||||
nome: map['nome'],
|
||||
companyId: map['company_id'] as String,
|
||||
isActive: map['is_active'] ?? true,
|
||||
isPaid: map['is_paid'] ?? false,
|
||||
paymentExpiration: map['payment_expiration'] != null
|
||||
? DateTime.parse(map['payment_expiration'])
|
||||
: null,
|
||||
indirizzo: json['indirizzo'],
|
||||
cap: json['cap'],
|
||||
comune: json['comune'],
|
||||
provincia: json['provincia'],
|
||||
indirizzo: map['indirizzo'],
|
||||
cap: map['cap'],
|
||||
comune: map['comune'],
|
||||
provincia: map['provincia'],
|
||||
associatedProviders: providers,
|
||||
associatedStaffMembers: staffMembers,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'nome': nome,
|
||||
|
||||
Reference in New Issue
Block a user