#537 (Cost Center)#539 (Hub Manager)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs
|
||||
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs
|
||||
import 'dart:convert';
|
||||
import 'package:firebase_data_connect/src/core/ref.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -23,7 +23,25 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
.getTeamHubsByTeamId(teamId: teamId)
|
||||
.execute();
|
||||
|
||||
final QueryResult<
|
||||
dc.ListTeamHudDepartmentsData,
|
||||
dc.ListTeamHudDepartmentsVariables
|
||||
>
|
||||
deptsResult = await _service.connector.listTeamHudDepartments().execute();
|
||||
final Map<String, dc.ListTeamHudDepartmentsTeamHudDepartments> hubToDept =
|
||||
<String, dc.ListTeamHudDepartmentsTeamHudDepartments>{};
|
||||
for (final dc.ListTeamHudDepartmentsTeamHudDepartments dep
|
||||
in deptsResult.data.teamHudDepartments) {
|
||||
if (dep.costCenter != null &&
|
||||
dep.costCenter!.isNotEmpty &&
|
||||
!hubToDept.containsKey(dep.teamHubId)) {
|
||||
hubToDept[dep.teamHubId] = dep;
|
||||
}
|
||||
}
|
||||
|
||||
return response.data.teamHubs.map((dc.GetTeamHubsByTeamIdTeamHubs h) {
|
||||
final dc.ListTeamHudDepartmentsTeamHudDepartments? dept =
|
||||
hubToDept[h.id];
|
||||
return Hub(
|
||||
id: h.id,
|
||||
businessId: businessId,
|
||||
@@ -31,7 +49,13 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
address: h.address,
|
||||
nfcTagId: null,
|
||||
status: h.isActive ? HubStatus.active : HubStatus.inactive,
|
||||
costCenter: null,
|
||||
costCenter: dept != null
|
||||
? CostCenter(
|
||||
id: dept.id,
|
||||
name: dept.name,
|
||||
code: dept.costCenter ?? dept.name,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
@@ -50,6 +74,7 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
String? street,
|
||||
String? country,
|
||||
String? zipCode,
|
||||
String? costCenterId,
|
||||
}) async {
|
||||
return _service.run(() async {
|
||||
final String teamId = await _getOrCreateTeamId(businessId);
|
||||
@@ -73,14 +98,27 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
.zipCode(zipCode ?? placeAddress?.zipCode)
|
||||
.execute();
|
||||
|
||||
final String hubId = result.data.teamHub_insert.id;
|
||||
CostCenter? costCenter;
|
||||
if (costCenterId != null && costCenterId.isNotEmpty) {
|
||||
await _service.connector
|
||||
.createTeamHudDepartment(
|
||||
name: costCenterId,
|
||||
teamHubId: hubId,
|
||||
)
|
||||
.costCenter(costCenterId)
|
||||
.execute();
|
||||
costCenter = CostCenter(id: costCenterId, name: costCenterId, code: costCenterId);
|
||||
}
|
||||
|
||||
return Hub(
|
||||
id: result.data.teamHub_insert.id,
|
||||
id: hubId,
|
||||
businessId: businessId,
|
||||
name: name,
|
||||
address: address,
|
||||
nfcTagId: null,
|
||||
status: HubStatus.active,
|
||||
costCenter: null,
|
||||
costCenter: costCenter,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -99,6 +137,7 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
String? street,
|
||||
String? country,
|
||||
String? zipCode,
|
||||
String? costCenterId,
|
||||
}) async {
|
||||
return _service.run(() async {
|
||||
final _PlaceAddress? placeAddress = (placeId != null && placeId.isNotEmpty)
|
||||
@@ -130,7 +169,43 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
|
||||
await builder.execute();
|
||||
|
||||
// Return a basic hub object reflecting changes (or we could re-fetch)
|
||||
CostCenter? costCenter;
|
||||
final QueryResult<
|
||||
dc.ListTeamHudDepartmentsByTeamHubIdData,
|
||||
dc.ListTeamHudDepartmentsByTeamHubIdVariables
|
||||
>
|
||||
deptsResult = await _service.connector
|
||||
.listTeamHudDepartmentsByTeamHubId(teamHubId: id)
|
||||
.execute();
|
||||
final List<dc.ListTeamHudDepartmentsByTeamHubIdTeamHudDepartments> depts =
|
||||
deptsResult.data.teamHudDepartments;
|
||||
|
||||
if (costCenterId == null || costCenterId.isEmpty) {
|
||||
if (depts.isNotEmpty) {
|
||||
await _service.connector
|
||||
.updateTeamHudDepartment(id: depts.first.id)
|
||||
.costCenter(null)
|
||||
.execute();
|
||||
}
|
||||
} else {
|
||||
if (depts.isNotEmpty) {
|
||||
await _service.connector
|
||||
.updateTeamHudDepartment(id: depts.first.id)
|
||||
.costCenter(costCenterId)
|
||||
.execute();
|
||||
costCenter = CostCenter(id: costCenterId, name: costCenterId, code: costCenterId);
|
||||
} else {
|
||||
await _service.connector
|
||||
.createTeamHudDepartment(
|
||||
name: costCenterId,
|
||||
teamHubId: id,
|
||||
)
|
||||
.costCenter(costCenterId)
|
||||
.execute();
|
||||
costCenter = CostCenter(id: costCenterId, name: costCenterId, code: costCenterId);
|
||||
}
|
||||
}
|
||||
|
||||
return Hub(
|
||||
id: id,
|
||||
businessId: businessId,
|
||||
@@ -138,7 +213,7 @@ class HubsConnectorRepositoryImpl implements HubsConnectorRepository {
|
||||
address: address ?? '',
|
||||
nfcTagId: null,
|
||||
status: HubStatus.active,
|
||||
costCenter: null,
|
||||
costCenter: costCenter,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ abstract interface class HubsConnectorRepository {
|
||||
String? street,
|
||||
String? country,
|
||||
String? zipCode,
|
||||
String? costCenterId,
|
||||
});
|
||||
|
||||
/// Updates an existing hub.
|
||||
@@ -36,6 +37,7 @@ abstract interface class HubsConnectorRepository {
|
||||
String? street,
|
||||
String? country,
|
||||
String? zipCode,
|
||||
String? costCenterId,
|
||||
});
|
||||
|
||||
/// Deletes a hub.
|
||||
|
||||
Reference in New Issue
Block a user