update<T extends Model> static method

Future<bool> update<T extends Model>({
  1. required dynamic id,
  2. required String field,
  3. required dynamic value,
})

Implementation

static Future<bool> update<T extends Model>({
  required dynamic id,
  required String field,
  required dynamic value,
}) async {
  try {
    final allRecords = await _loadS3JsonFileRecords(_getS3TableKey<T>());
    final index = allRecords.indexWhere((record) => record['uuid'] == id);
    if (index < 0) return false;

    allRecords[index][field] = value;
    allRecords[index]['updated_at'] = DateTime.now()
        .toUtc()
        .toIso8601String();
    return await _s3client.putString(
      _getS3TableKey<T>(),
      jsonEncode(allRecords),
      contentType: 'application/json',
      acl: S3Acl.private,
    );
  } catch (e) {
    return false;
  }
}