jServicesOfClient function

  1. @Riverpod(keepAlive: true)
Map<ServiceState, List<ServiceOfJournal>> jServicesOfClient(
  1. Ref<Object?> ref,
  2. ClientService clientService
)

Return ServiceOfJournal grouped by type for ClientService.

Implementation

@Riverpod(keepAlive: true)
Map<ServiceState, List<ServiceOfJournal>> jServicesOfClient(
  Ref ref,
  ClientService clientService,
  // AppState archive,
) {
  // if (archive.isArchive) {
  //
  // } else {
  final journal = ref.watch(journalProvider(clientService.apiKey));
  final groups = ref.watch(servicesOfJournalProvider(journal));
  final res = groups.map(
    (key, value) => MapEntry(
      key,
      value
          .where((e) =>
              e.contractId == clientService.contractId &&
              e.servId == clientService.servId)
          .toList(growable: false),
    ),
  );

  // make sure it is not contains null
  ServiceState.values.forEach((state) {
    if (!res.containsKey(state)) {
      res[state] = [];
    }
  });

  return res;
}