Onboarding completato, ora super rapido e top Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/7 Co-authored-by: Mark M2 Macbook <marco@catelli.it> Co-committed-by: Mark M2 Macbook <marco@catelli.it>
39 lines
1.0 KiB
Dart
39 lines
1.0 KiB
Dart
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
import '../models/company_model.dart';
|
|
|
|
class CompanyRepository {
|
|
final SupabaseClient _supabase = Supabase.instance.client;
|
|
|
|
Future<CompanyModel> createCompany(CompanyModel company) async {
|
|
try {
|
|
// .select().single() trasforma la risposta nell'oggetto appena inserito
|
|
final response = await _supabase
|
|
.from('company')
|
|
.insert(company.toMap())
|
|
.select()
|
|
.single();
|
|
|
|
return CompanyModel.fromMap(response);
|
|
} on PostgrestException catch (e) {
|
|
throw e.message;
|
|
} catch (e) {
|
|
throw 'Errore imprevisto durante la creazione dell\'azienda';
|
|
}
|
|
}
|
|
|
|
Future<CompanyModel?> getCompany() async {
|
|
try {
|
|
final userId = _supabase.auth.currentUser?.id;
|
|
final response = await _supabase
|
|
.from('company')
|
|
.select()
|
|
.eq('user_id', userId as Object)
|
|
.maybeSingle();
|
|
|
|
return response != null ? CompanyModel.fromMap(response) : null;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|