adding extra shifts with no application
This commit is contained in:
@@ -37,9 +37,20 @@ class CoverageRepositoryImpl implements CoverageRepository {
|
||||
print(
|
||||
'Coverage: request businessId=$businessId dayStart=${start.toIso8601String()} dayEnd=${end.toIso8601String()}',
|
||||
);
|
||||
final fdc.QueryResult<
|
||||
dc.ListShiftRolesByBusinessAndDateRangeData,
|
||||
dc.ListShiftRolesByBusinessAndDateRangeVariables> shiftRolesResult =
|
||||
await _dataConnect
|
||||
.listShiftRolesByBusinessAndDateRange(
|
||||
businessId: businessId,
|
||||
start: _toTimestamp(start),
|
||||
end: _toTimestamp(end),
|
||||
)
|
||||
.execute();
|
||||
|
||||
final fdc.QueryResult<
|
||||
dc.ListStaffsApplicationsByBusinessForDayData,
|
||||
dc.ListStaffsApplicationsByBusinessForDayVariables> result =
|
||||
dc.ListStaffsApplicationsByBusinessForDayVariables> applicationsResult =
|
||||
await _dataConnect
|
||||
.listStaffsApplicationsByBusinessForDay(
|
||||
businessId: businessId,
|
||||
@@ -48,10 +59,14 @@ class CoverageRepositoryImpl implements CoverageRepository {
|
||||
)
|
||||
.execute();
|
||||
print(
|
||||
'Coverage: ${date.toIso8601String()} staffsApplications=${result.data.applications.length}',
|
||||
'Coverage: ${date.toIso8601String()} staffsApplications=${applicationsResult.data.applications.length}',
|
||||
);
|
||||
|
||||
return _mapCoverageShifts(result.data.applications, date);
|
||||
return _mapCoverageShifts(
|
||||
shiftRolesResult.data.shiftRoles,
|
||||
applicationsResult.data.applications,
|
||||
date,
|
||||
);
|
||||
}
|
||||
|
||||
/// Fetches coverage statistics for a specific date.
|
||||
@@ -91,16 +106,31 @@ class CoverageRepositoryImpl implements CoverageRepository {
|
||||
return fdc.Timestamp(nanoseconds, seconds);
|
||||
}
|
||||
|
||||
Future<List<CoverageShift>> _mapCoverageShifts(
|
||||
List<CoverageShift> _mapCoverageShifts(
|
||||
List<dc.ListShiftRolesByBusinessAndDateRangeShiftRoles> shiftRoles,
|
||||
List<dc.ListStaffsApplicationsByBusinessForDayApplications> applications,
|
||||
DateTime date,
|
||||
) async {
|
||||
if (applications.isEmpty) {
|
||||
) {
|
||||
if (shiftRoles.isEmpty && applications.isEmpty) {
|
||||
return <CoverageShift>[];
|
||||
}
|
||||
|
||||
final Map<String, _CoverageGroup> groups =
|
||||
<String, _CoverageGroup>{};
|
||||
final Map<String, _CoverageGroup> groups = <String, _CoverageGroup>{};
|
||||
for (final dc.ListShiftRolesByBusinessAndDateRangeShiftRoles shiftRole
|
||||
in shiftRoles) {
|
||||
final String key = '${shiftRole.shiftId}:${shiftRole.roleId}';
|
||||
groups[key] = _CoverageGroup(
|
||||
shiftId: shiftRole.shiftId,
|
||||
roleId: shiftRole.roleId,
|
||||
title: shiftRole.role.name,
|
||||
location: shiftRole.shift.location ?? '',
|
||||
startTime: _formatTime(shiftRole.startTime) ?? '00:00',
|
||||
workersNeeded: shiftRole.count,
|
||||
date: shiftRole.shift.date?.toDateTime() ?? date,
|
||||
workers: <CoverageWorker>[],
|
||||
);
|
||||
}
|
||||
|
||||
for (final dc.ListStaffsApplicationsByBusinessForDayApplications app
|
||||
in applications) {
|
||||
final String key = '${app.shiftId}:${app.roleId}';
|
||||
@@ -108,8 +138,11 @@ class CoverageRepositoryImpl implements CoverageRepository {
|
||||
_CoverageGroup(
|
||||
shiftId: app.shiftId,
|
||||
roleId: app.roleId,
|
||||
roleName: app.shiftRole.role.name,
|
||||
title: app.shiftRole.role.name,
|
||||
location: app.shiftRole.shift.location ?? '',
|
||||
startTime: '00:00',
|
||||
workersNeeded: 0,
|
||||
date: date,
|
||||
workers: <CoverageWorker>[],
|
||||
);
|
||||
|
||||
@@ -123,37 +156,19 @@ class CoverageRepositoryImpl implements CoverageRepository {
|
||||
groups[key] = existing;
|
||||
}
|
||||
|
||||
final List<_CoverageGroup> groupList = groups.values.toList();
|
||||
final List<CoverageShift> shifts = <CoverageShift>[];
|
||||
for (final _CoverageGroup group in groupList) {
|
||||
final fdc.QueryResult<dc.GetShiftRoleByIdData,
|
||||
dc.GetShiftRoleByIdVariables> shiftRoleResult =
|
||||
await _dataConnect
|
||||
.getShiftRoleById(
|
||||
shiftId: group.shiftId,
|
||||
roleId: group.roleId,
|
||||
)
|
||||
.execute();
|
||||
final dc.GetShiftRoleByIdShiftRole? shiftRole =
|
||||
shiftRoleResult.data.shiftRole;
|
||||
if (shiftRole == null) {
|
||||
continue;
|
||||
}
|
||||
final String startTime = _formatTime(shiftRole.startTime) ?? '00:00';
|
||||
shifts.add(
|
||||
CoverageShift(
|
||||
id: shiftRole.id,
|
||||
title: group.roleName,
|
||||
location: group.location,
|
||||
startTime: startTime,
|
||||
workersNeeded: shiftRole.count,
|
||||
date: date,
|
||||
workers: group.workers,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return shifts;
|
||||
return groups.values
|
||||
.map(
|
||||
(_CoverageGroup group) => CoverageShift(
|
||||
id: '${group.shiftId}:${group.roleId}',
|
||||
title: group.title,
|
||||
location: group.location,
|
||||
startTime: group.startTime,
|
||||
workersNeeded: group.workersNeeded,
|
||||
date: group.date,
|
||||
workers: group.workers,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
String _mapWorkerStatus(
|
||||
@@ -191,14 +206,20 @@ class _CoverageGroup {
|
||||
_CoverageGroup({
|
||||
required this.shiftId,
|
||||
required this.roleId,
|
||||
required this.roleName,
|
||||
required this.title,
|
||||
required this.location,
|
||||
required this.startTime,
|
||||
required this.workersNeeded,
|
||||
required this.date,
|
||||
required this.workers,
|
||||
});
|
||||
|
||||
final String shiftId;
|
||||
final String roleId;
|
||||
final String roleName;
|
||||
final String title;
|
||||
final String location;
|
||||
final String startTime;
|
||||
final int workersNeeded;
|
||||
final DateTime date;
|
||||
final List<CoverageWorker> workers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user