saveDeployment method

Future<bool> saveDeployment(
  1. SmartphoneDeployment deployment
)

Save the deployment persistently to a local cache. Returns true if successful.

Implementation

Future<bool> saveDeployment(SmartphoneDeployment deployment) async {
  info("$runtimeType - Saving deployment to database.");
  bool success = true;
  try {
    final Map<String, dynamic> map = {
      DEPLOYMENT_ID_COLUMN: deployment.studyDeploymentId,
      ROLE_NAME_COLUMN: deployment.deviceConfiguration.roleName,
      DEPLOYMENT_STATUS_COLUMN: deployment.status.index,
      UPDATED_AT_COLUMN: DateTime.now().toUtc().toIso8601String(),
      DEPLOYED_AT_COLUMN: deployment.deployed?.toUtc().toIso8601String(),
      USER_ID_COLUMN: deployment.userId,
      DEPLOYMENT_COLUMN: jsonEncode(deployment),
    };
    await database?.insert(
      DEPLOYMENT_TABLE_NAME,
      map,
      conflictAlgorithm: ConflictAlgorithm.replace,
    );
  } catch (exception) {
    success = false;
    warning('$runtimeType - Failed to save deployment - $exception');
  }
  return success;
}