validation if a hug has orders
This commit is contained in:
@@ -94,6 +94,25 @@ class HubRepositoryImpl implements HubRepositoryInterface {
|
||||
|
||||
@override
|
||||
Future<void> deleteHub(String id) async {
|
||||
final String? businessId = dc.ClientSessionStore.instance.session?.business?.id;
|
||||
if (businessId == null || businessId.isEmpty) {
|
||||
await _firebaseAuth.signOut();
|
||||
throw Exception('Business is missing. Please sign in again.');
|
||||
}
|
||||
|
||||
final QueryResult<
|
||||
dc.ListOrdersByBusinessAndTeamHubData,
|
||||
dc.ListOrdersByBusinessAndTeamHubVariables> result = await _dataConnect
|
||||
.listOrdersByBusinessAndTeamHub(
|
||||
businessId: businessId,
|
||||
teamHubId: id,
|
||||
)
|
||||
.execute();
|
||||
|
||||
if (result.data.orders.isNotEmpty) {
|
||||
throw Exception("Sorry this hub has orders, it can't be deleted.");
|
||||
}
|
||||
|
||||
await _dataConnect.deleteTeamHub(id: id).execute();
|
||||
}
|
||||
|
||||
|
||||
@@ -404,6 +404,7 @@ query listOrdersByBusinessAndTeamHub(
|
||||
where: {
|
||||
businessId: { eq: $businessId }
|
||||
teamHubId: { eq: $teamHubId }
|
||||
#status: {in: [ DRAFT POSTED FILLED PENDING FULLY_STAFFED PARTIAL_STAFFED ] }
|
||||
}
|
||||
offset: $offset
|
||||
limit: $limit
|
||||
|
||||
Reference in New Issue
Block a user