Implementert admin-funksjoner: Dashboard, Ansattliste, Avvikshåndtering og Profil-oppdatering
This commit is contained in:
@@ -140,6 +140,20 @@ class AuthService {
|
||||
return 'default_aml';
|
||||
}
|
||||
|
||||
// Hent alle brukere i en organisasjon
|
||||
Future<List<UserModel>> getUsersInOrganization(String organizationId) async {
|
||||
try {
|
||||
final snapshot = await _firestore
|
||||
.collection('users')
|
||||
.where('organizationId', isEqualTo: organizationId)
|
||||
.get();
|
||||
|
||||
return snapshot.docs.map((doc) => UserModel.fromFirestore(doc)).toList();
|
||||
} catch (e) {
|
||||
throw Exception('Kunne ikke hente brukere: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Håndter Firebase Auth exceptions
|
||||
String _handleAuthException(FirebaseAuthException e) {
|
||||
switch (e.code) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../models/time_registration.dart';
|
||||
import '../models/deviation.dart';
|
||||
|
||||
class TimeService {
|
||||
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
||||
@@ -319,4 +320,41 @@ class TimeService {
|
||||
'overtime': overtimeMinutes,
|
||||
};
|
||||
}
|
||||
// Hent avvik for organisasjon
|
||||
Future<List<Deviation>> getDeviations({
|
||||
required String organizationId,
|
||||
bool? onlyUnacknowledged,
|
||||
}) async {
|
||||
try {
|
||||
Query query = _firestore
|
||||
.collection('deviations')
|
||||
.where('organizationId', isEqualTo: organizationId);
|
||||
|
||||
if (onlyUnacknowledged == true) {
|
||||
query = query.where('acknowledgedAt', isNull: true);
|
||||
}
|
||||
|
||||
final snapshot = await query.orderBy('detectedAt', descending: true).get();
|
||||
return snapshot.docs.map((doc) => Deviation.fromFirestore(doc)).toList();
|
||||
} catch (e) {
|
||||
throw Exception('Kunne ikke hente avvik: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Kvitter ut avvik
|
||||
Future<void> acknowledgeDeviation({
|
||||
required String deviationId,
|
||||
required String userId,
|
||||
String? comment,
|
||||
}) async {
|
||||
try {
|
||||
await _firestore.collection('deviations').doc(deviationId).update({
|
||||
'acknowledgedAt': Timestamp.now(),
|
||||
'acknowledgedBy': userId,
|
||||
if (comment != null) 'comment': comment,
|
||||
});
|
||||
} catch (e) {
|
||||
throw Exception('Kunne ikke kvittere ut avvik: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user