mmmh
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/tasks/models/task_status.dart';
|
||||
|
||||
@@ -9,11 +10,12 @@ class TaskModel extends Equatable {
|
||||
final String? description;
|
||||
final List<String> assignedToIds;
|
||||
final List<StaffMemberModel> assignedToStaff; // I dati completi dal JOIN
|
||||
final String? createdById;
|
||||
final StaffMemberModel? createdBy;
|
||||
final DateTime? dueDate;
|
||||
final TaskStatus status;
|
||||
final DateTime? createdAt;
|
||||
final String? storeId;
|
||||
final StaffMemberModel? updatedBy;
|
||||
|
||||
const TaskModel({
|
||||
this.id,
|
||||
@@ -22,24 +24,25 @@ class TaskModel extends Equatable {
|
||||
this.description,
|
||||
this.assignedToIds = const [],
|
||||
this.assignedToStaff = const [],
|
||||
this.createdById,
|
||||
this.createdBy,
|
||||
this.dueDate,
|
||||
this.status = TaskStatus.open,
|
||||
this.createdAt,
|
||||
this.storeId,
|
||||
this.updatedBy,
|
||||
});
|
||||
|
||||
bool get isGlobal => storeId == null;
|
||||
|
||||
// --- FACTORY: MODELLO VUOTO (Per le creazioni) ---
|
||||
factory TaskModel.empty({String? companyId, String? createdById}) {
|
||||
factory TaskModel.empty({String? companyId, StaffMemberModel? createdBy}) {
|
||||
return TaskModel(
|
||||
companyId: companyId,
|
||||
title: '',
|
||||
description: '',
|
||||
assignedToIds: const [],
|
||||
assignedToStaff: const [],
|
||||
createdById: createdById,
|
||||
createdBy: createdBy,
|
||||
status: TaskStatus.open,
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
@@ -54,11 +57,12 @@ class TaskModel extends Equatable {
|
||||
description,
|
||||
assignedToIds,
|
||||
assignedToStaff,
|
||||
createdById,
|
||||
createdBy,
|
||||
dueDate,
|
||||
status,
|
||||
createdAt,
|
||||
storeId,
|
||||
updatedBy,
|
||||
];
|
||||
|
||||
// --- COPY WITH ---
|
||||
@@ -69,13 +73,15 @@ class TaskModel extends Equatable {
|
||||
String? description,
|
||||
List<String>? assignedToIds,
|
||||
List<StaffMemberModel>? assignedToStaff,
|
||||
String? createdById,
|
||||
StaffMemberModel? createdBy,
|
||||
DateTime? dueDate,
|
||||
bool clearDueDate = false, // Flag ninja per resettare la scadenza
|
||||
TaskStatus? status,
|
||||
DateTime? createdAt,
|
||||
String? storeId,
|
||||
bool clearStoreId = false,
|
||||
StaffMemberModel? updatedBy,
|
||||
String? updatedByDisplayName,
|
||||
}) {
|
||||
return TaskModel(
|
||||
id: id ?? this.id,
|
||||
@@ -84,11 +90,12 @@ class TaskModel extends Equatable {
|
||||
description: description ?? this.description,
|
||||
assignedToIds: assignedToIds ?? this.assignedToIds,
|
||||
assignedToStaff: assignedToStaff ?? this.assignedToStaff,
|
||||
createdById: createdById ?? this.createdById,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
dueDate: clearDueDate ? null : (dueDate ?? this.dueDate),
|
||||
status: status ?? this.status,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
storeId: clearStoreId ? null : (storeId ?? this.storeId),
|
||||
updatedBy: updatedBy ?? this.updatedBy,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -124,7 +131,9 @@ class TaskModel extends Equatable {
|
||||
description: map['description'] as String?,
|
||||
assignedToIds: parsedAssignedToIds,
|
||||
assignedToStaff: staffList,
|
||||
createdById: map['created_by_id'] as String?,
|
||||
createdBy: map['created_by_id'] != null
|
||||
? StaffMemberModel.fromMap(map['creator'])
|
||||
: null,
|
||||
dueDate: map['due_date'] != null
|
||||
? DateTime.parse(map['due_date'] as String).toLocal()
|
||||
: null,
|
||||
@@ -133,6 +142,9 @@ class TaskModel extends Equatable {
|
||||
? DateTime.parse(map['created_at'] as String).toLocal()
|
||||
: null,
|
||||
storeId: map['store_id'] as String?,
|
||||
updatedBy: map['updated_by_id'] != null
|
||||
? StaffMemberModel.fromMap(map['updater'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,10 +157,11 @@ class TaskModel extends Equatable {
|
||||
if (description != null) 'description': description,
|
||||
// Passiamo l'array vuoto se non ci sono assegnazioni
|
||||
'assigned_to_ids': assignedToIds.isEmpty ? null : assignedToIds,
|
||||
if (createdById != null) 'created_by_id': createdById,
|
||||
if (createdBy != null) 'created_by_id': createdBy!.id,
|
||||
'due_date': dueDate?.toUtc().toIso8601String(),
|
||||
'status': status.toValue,
|
||||
'store_id': storeId,
|
||||
if (updatedBy != null) 'updated_by_id': updatedBy!.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user