providers (#3)

Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/3
Co-authored-by: Mark M2 Macbook <marco@catelli.it>
Co-committed-by: Mark M2 Macbook <marco@catelli.it>
This commit is contained in:
2026-04-17 10:34:23 +02:00
committed by brontomark
parent 5229571fa1
commit c1b6c9e7ac
7 changed files with 585 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
class ProviderModel extends Equatable {
final String id;
final String? id;
final String nome;
final bool telefoniaFissa;
final bool telefoniaMobile;
@@ -11,9 +11,10 @@ class ProviderModel extends Equatable {
final bool altro;
final bool isActive;
final String companyId;
final int storesCount;
const ProviderModel({
required this.id,
this.id,
required this.nome,
required this.telefoniaFissa,
required this.telefoniaMobile,
@@ -23,6 +24,7 @@ class ProviderModel extends Equatable {
required this.altro,
required this.isActive,
required this.companyId,
this.storesCount = 0, // Numero di store associati, default a 0
});
factory ProviderModel.fromMap(Map<String, dynamic> map) {
@@ -37,11 +39,16 @@ class ProviderModel extends Equatable {
altro: map['altro'] ?? false,
isActive: map['is_active'] ?? true,
companyId: map['company_id'],
storesCount:
map['providers_in_stores'] != null &&
map['providers_in_stores'].isNotEmpty
? map['providers_in_stores'][0]['count'] as int
: 0, // Assumiamo che l'API possa restituire questo campo
);
}
Map<String, dynamic> toMap() {
return {
final map = {
'nome': nome,
'telefonia_fissa': telefoniaFissa,
'telefonia_mobile': telefoniaMobile,
@@ -52,6 +59,12 @@ class ProviderModel extends Equatable {
'is_active': isActive,
'company_id': companyId,
};
// AGGIUNGIAMO L'ID SOLO SE NON È NULLO
// Senza questo, l'upsert non sa dove andare a parare
if (id != null) {
map['id'] = id!;
}
return map;
}
@override
@@ -66,6 +79,7 @@ class ProviderModel extends Equatable {
altro,
isActive,
companyId,
storesCount,
];
ProviderModel copyWith({
@@ -79,6 +93,7 @@ class ProviderModel extends Equatable {
bool? altro,
bool? isActive,
String? companyId,
int? storesCount,
}) {
return ProviderModel(
id: id ?? this.id,
@@ -91,6 +106,7 @@ class ProviderModel extends Equatable {
altro: altro ?? this.altro,
isActive: isActive ?? this.isActive,
companyId: companyId ?? this.companyId,
storesCount: storesCount ?? this.storesCount,
);
}
}