updatePartially method

Future<T?> updatePartially(
  1. String? correlationId,
  2. K id,
  3. AnyValueMap data
)

Updates only few selected fields in a data item.

  • correlation_id (optional) transaction id to trace execution through call chain.
  • id an id of data item to be updated.
  • data a map with fields to be updated. Return Future that receives updated item Throws error.

Implementation

Future<T?> updatePartially(
    String? correlationId, K id, AnyValueMap data) async {
  var index = List.from(items.map((x) {
    return x.id;
  })).indexOf(id);

  if (index < 0) {
    logger.trace(correlationId, 'Item %s was not found', [id]);
    return null;
  }

  var item = items[index];
  ObjectWriter.setProperties(item, data);

  items[index] = item;
  logger.trace(correlationId, 'Partially updated item %s', [id]);

  await save(correlationId);
  return item;
}