53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
|
import 'package:brick_supabase/brick_supabase.dart';
|
|
|
|
@ConnectOfflineFirstWithSupabase(
|
|
supabaseConfig: SupabaseSerializable(tableName: 'network_sites'),
|
|
)
|
|
class NetworkSite extends OfflineFirstWithSupabaseModel {
|
|
final String id;
|
|
final String name;
|
|
final String? address;
|
|
final String? notes;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final String? createdBy;
|
|
|
|
NetworkSite({
|
|
required this.id,
|
|
required this.name,
|
|
this.address,
|
|
this.notes,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
this.createdBy,
|
|
});
|
|
|
|
factory NetworkSite.fromMap(Map<String, dynamic> map) {
|
|
return NetworkSite(
|
|
id: map['id'] as String,
|
|
name: (map['name'] as String?) ?? '',
|
|
address: map['address'] as String?,
|
|
notes: map['notes'] as String?,
|
|
createdAt:
|
|
DateTime.tryParse(map['created_at']?.toString() ?? '') ?? DateTime.now(),
|
|
updatedAt:
|
|
DateTime.tryParse(map['updated_at']?.toString() ?? '') ?? DateTime.now(),
|
|
createdBy: map['created_by'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toInsertMap() => {
|
|
'name': name,
|
|
if (address != null) 'address': address,
|
|
if (notes != null) 'notes': notes,
|
|
if (createdBy != null) 'created_by': createdBy,
|
|
};
|
|
|
|
Map<String, dynamic> toUpdateMap() => {
|
|
'name': name,
|
|
'address': address,
|
|
'notes': notes,
|
|
};
|
|
}
|