Initial and done prolly
This commit is contained in:
commit
6f88b9966f
175 changed files with 15445 additions and 0 deletions
88
lib/db/crud/storage_locations_crud.dart
Normal file
88
lib/db/crud/storage_locations_crud.dart
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
part of '../database.dart';
|
||||
|
||||
extension StorageLocationsCrud on AppDatabase {
|
||||
Stream<List<StorageLocationData>> get storageLocationsSubscription =>
|
||||
managers.storageLocation.watch();
|
||||
|
||||
Future<int> addStorageLocation({
|
||||
required String name,
|
||||
required String description,
|
||||
required TemperatureMode temperatureMode,
|
||||
required String icon,
|
||||
}) async {
|
||||
return await managers.storageLocation.create((c) => c(
|
||||
name: name,
|
||||
description: description,
|
||||
temperatureMode: temperatureMode.name,
|
||||
icon: icon,
|
||||
));
|
||||
}
|
||||
|
||||
Future<int> updateStorageLocation({
|
||||
required int id,
|
||||
String? name,
|
||||
String? description,
|
||||
TemperatureMode? temperatureMode,
|
||||
double? capacity,
|
||||
String? icon,
|
||||
}) async {
|
||||
return await managers.storageLocation
|
||||
.filter((f) => f.id(id))
|
||||
.update((u) => u(
|
||||
name: Value.absentIfNull(name),
|
||||
description: Value.absentIfNull(description),
|
||||
temperatureMode: Value.absentIfNull(temperatureMode?.name),
|
||||
icon: Value.absentIfNull(icon),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> deleteStorageLocation(StorageLocationData item) async {
|
||||
await managers.storageLocation.filter((f) => f.id(item.id)).delete();
|
||||
}
|
||||
|
||||
Future<List<(StorageLocationData, List<(ProductData, ProductCategoryData)>)>>
|
||||
getStorageLocations() async {
|
||||
final storageLocations = await managers.storageLocation
|
||||
.withReferences((prefetch) => prefetch(productRefs: true))
|
||||
.get();
|
||||
|
||||
final result =
|
||||
<(StorageLocationData, List<(ProductData, ProductCategoryData)>)>[];
|
||||
|
||||
for (final (storage, refs) in storageLocations) {
|
||||
final products = await refs.productRefs
|
||||
.withReferences((prefetch) => prefetch(category: true))
|
||||
.get();
|
||||
final productsWithCategories = <(ProductData, ProductCategoryData)>[];
|
||||
for (final (product, refs) in products) {
|
||||
productsWithCategories.add((
|
||||
product,
|
||||
await refs.category.getSingle(),
|
||||
));
|
||||
}
|
||||
result.add((
|
||||
storage,
|
||||
productsWithCategories,
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<bool> defaultExists() async {
|
||||
final exists = await managers.storageLocation
|
||||
.filter((f) => f.isDefault(true))
|
||||
.exists();
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
Future<void> switchDefault(int newDefaultId) async {
|
||||
await managers.storageLocation
|
||||
.filter((f) => f.isDefault(true))
|
||||
.update((u) => u(isDefault: const Value(false)));
|
||||
await managers.storageLocation
|
||||
.filter((f) => f.id(newDefaultId))
|
||||
.update((u) => u(isDefault: const Value(true)));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue