updateById method
Method to update data by ID with optional data source builder.
Example:
repository.updateById(
'userId123',
{'status': 'inactive'},
params: Params({"field1": "value1", "field2": "value2"}),
);
Implementation
Future<Response<T>> updateById(
String id,
Map<String, dynamic> data, {
DataFieldParams? params,
bool? resolveRefs,
Ignore? ignore,
bool updateRefs = false,
}) async {
if (id.isEmpty || data.isEmpty) return Response(status: Status.invalid);
return execute(() {
final path = ref(params, DataModifiers.updateById, id);
data = data.map((k, v) => MapEntry(k, delegate.updatingFieldValue(v)));
if (!isEncryptor) {
return operation
.update(path, data, updateRefs: updateRefs)
.then((value) => Response(status: Status.ok));
}
return getById(
id,
params: params,
countable: false,
resolveRefs: resolveRefs ?? updateRefs,
ignore: ignore,
).then((value) {
final x = value.data?.filtered ?? {};
x.addAll(data);
return encryptor.input(x).then((v) {
if (v.isEmpty) return Response(status: Status.nullable);
return operation
.update(path, v, updateRefs: updateRefs)
.then((value) => Response(status: Status.ok));
});
});
});
}