urca non ci credo, potrebbe già funzionare
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -29,6 +29,37 @@ class StaffRepository {
|
||||
return StaffMemberModel.fromMap(response);
|
||||
}
|
||||
|
||||
// --- LOGICA DI INVITO (Tramite Edge Function) ---
|
||||
|
||||
Future<String> inviteStaffMember(StaffMemberModel newMember) async {
|
||||
if (newMember.email == null || newMember.email!.isEmpty) {
|
||||
throw Exception(
|
||||
"L'indirizzo email è obbligatorio per invitare un collega.",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await _supabase.functions.invoke(
|
||||
'invite_staff',
|
||||
body: newMember.toMap(),
|
||||
);
|
||||
|
||||
if (response.status != 200) {
|
||||
throw Exception("Errore dal server: ${response.data}");
|
||||
}
|
||||
|
||||
// La funzione ci restituisce l'ID fresco di database!
|
||||
final responseData = response.data as Map<String, dynamic>;
|
||||
return responseData['user_id'] as String;
|
||||
} on FunctionException catch (e) {
|
||||
throw Exception(
|
||||
"Errore di comunicazione con il server: ${e.reasonPhrase}",
|
||||
);
|
||||
} catch (e) {
|
||||
throw Exception("Impossibile invitare il collega: $e");
|
||||
}
|
||||
}
|
||||
|
||||
// --- LOGICA DI GIUNZIONE (Staff <-> Store) ---
|
||||
|
||||
// Recupera i membri assegnati a uno specifico negozio
|
||||
@@ -62,7 +93,7 @@ class StaffRepository {
|
||||
}
|
||||
|
||||
// Assegna un membro a un negozio
|
||||
Future<void> assignToStore(String staffId, String storeId) async {
|
||||
Future<void> assignStaffToStore(String staffId, String storeId) async {
|
||||
await _supabase.from('staff_in_stores').insert({
|
||||
'staff_member_id': staffId,
|
||||
'store_id': storeId,
|
||||
@@ -70,7 +101,7 @@ class StaffRepository {
|
||||
}
|
||||
|
||||
// Rimuove l'assegnazione
|
||||
Future<void> removeFromStore(String staffId, String storeId) async {
|
||||
Future<void> removeStaffFromStore(String staffId, String storeId) async {
|
||||
await _supabase
|
||||
.from('staff_in_stores')
|
||||
.delete()
|
||||
|
||||
Reference in New Issue
Block a user