update staff list, add pin editor and privilege editor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
@@ -10,6 +11,8 @@ import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import '../../../domain/entities/user.dart';
|
||||
import '../../../helpers/firebase_helper.dart';
|
||||
import 'package:path/path.dart' as Path;
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
final log = Logger('CartonModel');
|
||||
@@ -227,7 +230,7 @@ class CartonModel extends BaseModel {
|
||||
return Services.instance.cartonService.searchCarton(term);
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartonsByIds(List<String> cartonIds) async {
|
||||
Future<List<Carton>> getCartonsByIds(List<String> cartonIds) async {
|
||||
List<Carton> cartons = [];
|
||||
try {
|
||||
for (var e in cartonIds) {
|
||||
@@ -241,4 +244,40 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
return cartons;
|
||||
}
|
||||
|
||||
Future<void> uploadCartonImages(
|
||||
Carton carton, List<File?> files, List<String?> deletedUrls) async {
|
||||
if (deletedUrls.isNotEmpty) {
|
||||
for (String? url in deletedUrls) {
|
||||
carton.photoUrls.remove(url);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> uploadedURL = [];
|
||||
if (files.isNotEmpty) {
|
||||
var count =
|
||||
(carton.photoUrls.length) + files.length - (deletedUrls.length);
|
||||
|
||||
if (count > uploadPhotoLimit)
|
||||
throw Exception("Exceed number of file upload");
|
||||
|
||||
carton.photoUrls = carton.photoUrls;
|
||||
String path = Path.join(carton_files_path);
|
||||
uploadedURL = await uploadFiles(path, files);
|
||||
uploadedURL.forEach((url) {
|
||||
carton.photoUrls.add(url);
|
||||
});
|
||||
}
|
||||
try {
|
||||
// await Services.instance.packageService.updateReceiving(package);
|
||||
} catch (e) {
|
||||
// delete newly uploaded photos if fails
|
||||
try {
|
||||
deleteStorageFromUrls(uploadedURL);
|
||||
carton.photoUrls.removeWhere((i) => uploadedURL.contains(i));
|
||||
} catch (e) {}
|
||||
throw e;
|
||||
}
|
||||
return deleteStorageFromUrls(deletedUrls);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user