refactor nomi tabelle
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flux/core/enums_and_consts/consts.dart';
|
||||
import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -10,7 +12,7 @@ class StoreRepository {
|
||||
/// Crea un nuovo negozio associato alla compagnia dell'utente
|
||||
Future<void> createStore(StoreModel store) async {
|
||||
try {
|
||||
await _supabase.from('store').insert(store.toMap());
|
||||
await _supabase.from(Tables.stores).insert(store.toMap());
|
||||
} on PostgrestException catch (e) {
|
||||
// Intercettiamo errori specifici del database
|
||||
throw e.message;
|
||||
@@ -22,7 +24,7 @@ class StoreRepository {
|
||||
Future<StoreModel> saveStore(StoreModel store) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('store')
|
||||
.from(Tables.stores)
|
||||
.upsert(store.toMap())
|
||||
.select()
|
||||
.single();
|
||||
@@ -41,7 +43,7 @@ class StoreRepository {
|
||||
try {
|
||||
// 1. Eliminiamo tutte le associazioni correnti per questo negozio
|
||||
await _supabase
|
||||
.from('providers_in_stores')
|
||||
.from(Tables.providersInStores)
|
||||
.delete()
|
||||
.eq('store_id', storeId);
|
||||
|
||||
@@ -51,7 +53,7 @@ class StoreRepository {
|
||||
.map((p) => {'store_id': storeId, 'provider_id': p.id})
|
||||
.toList();
|
||||
|
||||
await _supabase.from('providers_in_stores').insert(inserts);
|
||||
await _supabase.from(Tables.providersInStores).insert(inserts);
|
||||
}
|
||||
} catch (e) {
|
||||
throw 'Errore durante la sincronizzazione provider: $e';
|
||||
@@ -64,7 +66,10 @@ class StoreRepository {
|
||||
) async {
|
||||
try {
|
||||
// 1. Eliminiamo tutte le associazioni correnti per questo negozio
|
||||
await _supabase.from('staff_in_stores').delete().eq('store_id', storeId);
|
||||
await _supabase
|
||||
.from(Tables.staffInStores)
|
||||
.delete()
|
||||
.eq('store_id', storeId);
|
||||
|
||||
// 2. Se ci sono nuovi dipendenti da associare, li inseriamo
|
||||
if (staffMembers.isNotEmpty) {
|
||||
@@ -72,7 +77,7 @@ class StoreRepository {
|
||||
.map((s) => {'store_id': storeId, 'staff_id': s.id})
|
||||
.toList();
|
||||
|
||||
await _supabase.from('staff_in_stores').insert(inserts);
|
||||
await _supabase.from(Tables.staffInStores).insert(inserts);
|
||||
}
|
||||
} catch (e) {
|
||||
throw 'Errore durante la sincronizzazione staff: $e';
|
||||
@@ -83,16 +88,16 @@ class StoreRepository {
|
||||
Future<List<StoreModel>> fetchAllCompanyStores(String companyId) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('store')
|
||||
.from(Tables.stores)
|
||||
.select('''
|
||||
*,
|
||||
associated_providers:providers_in_stores (
|
||||
provider (
|
||||
associated_providers:${Tables.providersInStores} (
|
||||
${Tables.providers} (
|
||||
*
|
||||
)
|
||||
)
|
||||
associated_staff:staff_in_stores (
|
||||
staff_member (
|
||||
associated_staff:${Tables.staffInStores} (
|
||||
${Tables.staffMembers} (
|
||||
*
|
||||
)
|
||||
)
|
||||
@@ -111,7 +116,7 @@ class StoreRepository {
|
||||
required String providerId,
|
||||
}) async {
|
||||
try {
|
||||
await _supabase.from('providers_in_stores').insert({
|
||||
await _supabase.from(Tables.providersInStores).insert({
|
||||
'store_id': storeId,
|
||||
'provider_id': providerId,
|
||||
});
|
||||
@@ -126,7 +131,7 @@ class StoreRepository {
|
||||
}) async {
|
||||
try {
|
||||
await _supabase
|
||||
.from('providers_in_stores')
|
||||
.from(Tables.providersInStores)
|
||||
.delete()
|
||||
.eq('store_id', storeId)
|
||||
.eq('provider_id', providerId);
|
||||
|
||||
Reference in New Issue
Block a user