adding extra shifts with no application

This commit is contained in:
José Salazar
2026-01-27 11:52:44 -05:00
parent ccd6385266
commit ab5fed8639

View File

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