setDefaultDocument method
Atomically unsets the current default for documentTypeSlug and sets
documentId as the new default. Returns the updated document.
Implementation
@override
Future<DeskDocument> setDefaultDocument(
String documentTypeSlug,
String documentId,
) async {
// Unset any existing default for this type
final currentDefault = _documents.values.firstWhereOrNull(
(d) => d.documentType == documentTypeSlug && d.isDefault,
);
if (currentDefault?.id != null) {
_documents[currentDefault!.id!] = currentDefault.copyWith(
isDefault: false,
);
}
// Set new default
final doc = _documents[documentId];
if (doc == null) {
throw DeskNotFoundException(
resourceType: 'Document',
resourceId: documentId,
);
}
final updated = doc.copyWith(isDefault: true);
_documents[documentId] = updated;
return updated;
}