updateProgress method

Future<void> updateProgress(
  1. String topicId,
  2. Map<String, dynamic> updates
)

Implementation

Future<void> updateProgress(
  String topicId,
  Map<String, dynamic> updates,
) async {
  final userId = _client.auth.currentUser?.id;
  if (userId == null) {
    throw StateError('Cannot update progress: user is not authenticated');
  }

  await _client
      .from('user_topic_progress')
      .upsert(
        {
          'user_id': userId,
          'topic_id': topicId,
          'updated_at': DateTime.now().toIso8601String(),
          ...updates,
        },
        onConflict: 'user_id, topic_id',
        defaultToNull: false,
      );
}