changing a way of search my shifts
This commit is contained in:
@@ -83,55 +83,22 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Helper method to map Data Connect application to domain Shift using ShiftAdapter.
|
||||
Shift _mapApplicationToShift(
|
||||
dynamic app,
|
||||
String status, {
|
||||
bool hasApplied = true,
|
||||
}) {
|
||||
return ShiftAdapter.fromApplicationData(
|
||||
shiftId: app.shift.id,
|
||||
roleId: app.shiftRole.roleId,
|
||||
roleName: app.shiftRole.role.name,
|
||||
businessName: app.shift.order.business.businessName,
|
||||
companyLogoUrl: app.shift.order.business.companyLogoUrl,
|
||||
costPerHour: app.shiftRole.role.costPerHour,
|
||||
shiftLocation: app.shift.location,
|
||||
teamHubName: app.shift.order.teamHub.hubName,
|
||||
shiftDate: _toDateTime(app.shift.date),
|
||||
startTime: _toDateTime(app.shiftRole.startTime),
|
||||
endTime: _toDateTime(app.shiftRole.endTime),
|
||||
createdAt: _toDateTime(app.createdAt),
|
||||
status: status,
|
||||
description: app.shift.description,
|
||||
durationDays: app.shift.durationDays,
|
||||
count: app.shiftRole.count,
|
||||
assigned: app.shiftRole.assigned,
|
||||
eventName: app.shift.order.eventName,
|
||||
hasApplied: hasApplied,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Shift>> getMyShifts({
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
}) async {
|
||||
return _fetchApplications(
|
||||
[dc.ApplicationStatus.ACCEPTED, dc.ApplicationStatus.CONFIRMED],
|
||||
start: start,
|
||||
end: end,
|
||||
);
|
||||
return _fetchApplications(start: start, end: end);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Shift>> getPendingAssignments() async {
|
||||
return _fetchApplications([dc.ApplicationStatus.PENDING]);
|
||||
return <Shift>[];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Shift>> getCancelledShifts() async {
|
||||
return _fetchApplications([dc.ApplicationStatus.REJECTED]);
|
||||
return <Shift>[];
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -147,10 +114,37 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
_shiftToAppIdMap[app.shift.id] = app.id;
|
||||
_appToRoleIdMap[app.id] = app.shiftRole.id;
|
||||
|
||||
final String roleName = app.shiftRole.role.name;
|
||||
final String orderName =
|
||||
(app.shift.order.eventName ?? '').trim().isNotEmpty
|
||||
? app.shift.order.eventName!
|
||||
: app.shift.order.business.businessName;
|
||||
final String title = '$roleName - $orderName';
|
||||
final DateTime? shiftDate = _toDateTime(app.shift.date);
|
||||
final DateTime? startDt = _toDateTime(app.shiftRole.startTime);
|
||||
final DateTime? endDt = _toDateTime(app.shiftRole.endTime);
|
||||
final DateTime? createdDt = _toDateTime(app.createdAt);
|
||||
|
||||
shifts.add(
|
||||
_mapApplicationToShift(
|
||||
app,
|
||||
_mapStatus(dc.ApplicationStatus.CHECKED_OUT),
|
||||
Shift(
|
||||
id: app.shift.id,
|
||||
roleId: app.shiftRole.roleId,
|
||||
title: title,
|
||||
clientName: app.shift.order.business.businessName,
|
||||
logoUrl: app.shift.order.business.companyLogoUrl,
|
||||
hourlyRate: app.shiftRole.role.costPerHour,
|
||||
location: app.shift.location ?? '',
|
||||
locationAddress: app.shift.order.teamHub.hubName,
|
||||
date: shiftDate?.toIso8601String() ?? '',
|
||||
startTime: startDt != null ? DateFormat('HH:mm').format(startDt) : '',
|
||||
endTime: endDt != null ? DateFormat('HH:mm').format(endDt) : '',
|
||||
createdDate: createdDt?.toIso8601String() ?? '',
|
||||
status: _mapStatus(dc.ApplicationStatus.CHECKED_OUT),
|
||||
description: app.shift.description,
|
||||
durationDays: app.shift.durationDays,
|
||||
requiredSlots: app.shiftRole.count,
|
||||
filledSlots: app.shiftRole.assigned ?? 0,
|
||||
hasApplied: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -160,8 +154,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Shift>> _fetchApplications(
|
||||
List<dc.ApplicationStatus> statuses, {
|
||||
Future<List<Shift>> _fetchApplications({
|
||||
DateTime? start,
|
||||
DateTime? end,
|
||||
}) async {
|
||||
@@ -175,10 +168,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
}
|
||||
final response = await query.execute();
|
||||
|
||||
final statusNames = statuses.map((s) => s.name).toSet();
|
||||
final apps = response.data.applications.where(
|
||||
(app) => statusNames.contains(app.status.stringValue),
|
||||
);
|
||||
final apps = response.data.applications;
|
||||
final List<Shift> shifts = [];
|
||||
|
||||
for (final app in apps) {
|
||||
@@ -199,8 +189,15 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
// Override status to reflect the application state (e.g., CHECKED_OUT, ACCEPTED)
|
||||
final bool hasCheckIn = app.checkInTime != null;
|
||||
final bool hasCheckOut = app.checkOutTime != null;
|
||||
final String mappedStatus =
|
||||
hasCheckOut ? 'completed' : hasCheckIn ? 'checked_in' : _mapStatus(status);
|
||||
dc.ApplicationStatus? appStatus;
|
||||
if (app.status is dc.Known<dc.ApplicationStatus>) {
|
||||
appStatus = (app.status as dc.Known<dc.ApplicationStatus>).value;
|
||||
}
|
||||
final String mappedStatus = hasCheckOut
|
||||
? 'completed'
|
||||
: hasCheckIn
|
||||
? 'checked_in'
|
||||
: _mapStatus(appStatus ?? dc.ApplicationStatus.ACCEPTED);
|
||||
shifts.add(
|
||||
Shift(
|
||||
id: app.shift.id,
|
||||
@@ -516,7 +513,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
shiftId: shiftId,
|
||||
staffId: staffId,
|
||||
roleId: targetRoleId,
|
||||
status: dc.ApplicationStatus.CONFIRMED,
|
||||
status: dc.ApplicationStatus.ACCEPTED,
|
||||
origin: dc.ApplicationOrigin.STAFF,
|
||||
)
|
||||
// TODO: this should be PENDING so a vendor can accept it.
|
||||
@@ -550,7 +547,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
|
||||
@override
|
||||
Future<void> acceptShift(String shiftId) async {
|
||||
await _updateApplicationStatus(shiftId, dc.ApplicationStatus.CONFIRMED);
|
||||
await _updateApplicationStatus(shiftId, dc.ApplicationStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -51,13 +51,11 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
final myShiftsResult = await getMyShifts(
|
||||
GetMyShiftsArguments(start: days.first, end: days.last),
|
||||
);
|
||||
final pendingResult = await getPendingAssignments();
|
||||
final cancelledResult = await getCancelledShifts();
|
||||
|
||||
emit(ShiftsLoaded(
|
||||
myShifts: myShiftsResult,
|
||||
pendingShifts: pendingResult,
|
||||
cancelledShifts: cancelledResult,
|
||||
pendingShifts: const [],
|
||||
cancelledShifts: const [],
|
||||
availableShifts: const [],
|
||||
historyShifts: const [],
|
||||
availableLoading: false,
|
||||
@@ -130,13 +128,10 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
return;
|
||||
}
|
||||
|
||||
final pendingResult = await getPendingAssignments();
|
||||
final cancelledResult = await getCancelledShifts();
|
||||
|
||||
emit(ShiftsLoaded(
|
||||
myShifts: myShiftsResult,
|
||||
pendingShifts: pendingResult,
|
||||
cancelledShifts: cancelledResult,
|
||||
pendingShifts: const [],
|
||||
cancelledShifts: const [],
|
||||
availableShifts: const [],
|
||||
historyShifts: const [],
|
||||
availableLoading: false,
|
||||
|
||||
Reference in New Issue
Block a user