updateByIds method

Future<Response<T>> updateByIds(
  1. Iterable<DataWriter> updates, {
  2. DataFieldParams? params,
  3. bool? resolveRefs,
  4. Ignore? ignore,
  5. bool updateRefs = false,
})

Method to update data by multiple IDs with optional data source builder.

Example:

List<UpdatingInfo> updates = [
  UpdatingInfo('userId1', {'status': 'inactive'}),
  UpdatingInfo('userId2', {'status': 'active'}),
];
repository.updateByIds(
  updates,
  params: Params({"field1": "value1", "field2": "value2"}),
);

Implementation

Future<Response<T>> updateByIds(
  Iterable<DataWriter> updates, {
  DataFieldParams? params,
  bool? resolveRefs,
  Ignore? ignore,
  bool updateRefs = false,
}) async {
  if (updates.isEmpty) return Response(status: Status.invalid);
  return execute(() {
    final callbacks = updates.map((e) {
      return updateById(
        e.id,
        e.data,
        params: params,
        resolveRefs: resolveRefs ?? updateRefs,
        ignore: ignore,
        updateRefs: updateRefs,
      );
    });
    return Future.wait(callbacks).then((value) {
      final x = value.where((e) => e.isSuccessful);
      return Response(
        status: x.length == updates.length ? Status.ok : Status.canceled,
        snapshot: value,
        backups: value.map((e) => e.data).whereType<T>().toList(),
      );
    });
  });
}