80 lines
2.5 KiB
Dart
80 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:fcs/data/services/services.dart';
|
|
import 'package:fcs/constants.dart';
|
|
import 'package:fcs/domain/entities/user.dart';
|
|
import 'package:fcs/pages/main/model/base_model.dart';
|
|
import 'package:logging/logging.dart';
|
|
|
|
import '../../../pagination/paginator_listener.dart';
|
|
|
|
class CustomerModel extends BaseModel {
|
|
final log = Logger('CustomerModel');
|
|
PaginatorListener<User>? getCustomers;
|
|
|
|
@override
|
|
logout() async {
|
|
getCustomers?.close();
|
|
}
|
|
|
|
loadPaginationCustomers() {
|
|
if (user == null && !user!.hasCustomers()) return;
|
|
|
|
String path = "/$user_collection";
|
|
Query col = FirebaseFirestore.instance
|
|
.collection(path)
|
|
.where("is_sys_admin", isEqualTo: false);
|
|
|
|
Query pageQuery = FirebaseFirestore.instance
|
|
.collection(path)
|
|
.where("is_sys_admin", isEqualTo: false)
|
|
.orderBy("message_time", descending: true);
|
|
|
|
getCustomers?.close();
|
|
getCustomers = PaginatorListener<User>(
|
|
col, pageQuery, (data, id) => User.fromMap(data, id),
|
|
rowPerLoad: 30);
|
|
}
|
|
|
|
Future<User> getUser(String? id) async {
|
|
String path = "/$user_collection";
|
|
var snap = await FirebaseFirestore.instance.collection(path).doc(id).get();
|
|
return User.fromMap(snap.data() as Map<String, dynamic>, snap.id);
|
|
}
|
|
|
|
Future<List<User>> getInvoiceUsers(String fcsShipmentID) async {
|
|
List<User> users = [];
|
|
try {
|
|
var snaps = await FirebaseFirestore.instance
|
|
.collection(
|
|
"/$fcs_shipment_collection/$fcsShipmentID/$user_collection")
|
|
.where("pending_invoice_carton_count", isGreaterThan: 0)
|
|
.get(GetOptions(source: Source.server));
|
|
users = snaps.docs.map((documentSnapshot) {
|
|
var user = User.fromMap(documentSnapshot.data(), documentSnapshot.id);
|
|
return user;
|
|
}).toList();
|
|
} catch (e) {
|
|
log.warning("Error!! $e");
|
|
}
|
|
return users;
|
|
}
|
|
|
|
Future<void> enableUser(User user, bool enabled) {
|
|
return Services.instance.userService.enableUser(user.id ?? "", enabled);
|
|
}
|
|
|
|
Future<void> inviteUser(String userName, String phoneNumber) {
|
|
return Services.instance.userService.inviteUser(userName, phoneNumber);
|
|
}
|
|
|
|
Future<void> deleteInvite(String phoneNumber) {
|
|
return Services.instance.userService.deleteInvite(phoneNumber);
|
|
}
|
|
|
|
Future<void> acceptRequest(String userID) {
|
|
return Services.instance.userService.acceptRequest(userID);
|
|
}
|
|
}
|