From 1d09e20ac88326b60ea158124909178bdc75f3fe Mon Sep 17 00:00:00 2001 From: Suriya Date: Fri, 20 Feb 2026 21:15:57 +0530 Subject: [PATCH] fix: resolve duplicate fields in Shift and unreachable code in ShiftsRepositoryImpl from bad merge --- .../domain/lib/src/entities/shifts/shift.dart | 37 +--- .../shifts_repository_impl.dart | 209 ------------------ 2 files changed, 4 insertions(+), 242 deletions(-) diff --git a/apps/mobile/packages/domain/lib/src/entities/shifts/shift.dart b/apps/mobile/packages/domain/lib/src/entities/shifts/shift.dart index ccfd5bfd..92fec9a0 100644 --- a/apps/mobile/packages/domain/lib/src/entities/shifts/shift.dart +++ b/apps/mobile/packages/domain/lib/src/entities/shifts/shift.dart @@ -2,39 +2,6 @@ import 'package:equatable/equatable.dart'; import 'package:krow_domain/src/entities/shifts/break/break.dart'; class Shift extends Equatable { - final String id; - final String title; - final String clientName; - final String? logoUrl; - final double hourlyRate; - final String location; - final String locationAddress; - final String date; - final String startTime; - final String endTime; - final String createdDate; - final bool? tipsAvailable; - final bool? travelTime; - final bool? mealProvided; - final bool? parkingAvailable; - final bool? gasCompensation; - final String? description; - final String? instructions; - final List? managers; - final double? latitude; - final double? longitude; - final String? status; - final int? durationDays; // For multi-day shifts - final int? requiredSlots; - final int? filledSlots; - final String? roleId; - final bool? hasApplied; - final double? totalValue; - final Break? breakInfo; - final String? orderId; - final String? orderType; - final List? schedules; - const Shift({ required this.id, required this.title, @@ -69,6 +36,7 @@ class Shift extends Equatable { this.orderType, this.schedules, }); + final String id; final String title; final String clientName; @@ -98,6 +66,9 @@ class Shift extends Equatable { final bool? hasApplied; final double? totalValue; final Break? breakInfo; + final String? orderId; + final String? orderType; + final List? schedules; @override List get props => [ diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/data/repositories_impl/shifts_repository_impl.dart b/apps/mobile/packages/features/staff/shifts/lib/src/data/repositories_impl/shifts_repository_impl.dart index 07b2d4d5..a41c5e1f 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/data/repositories_impl/shifts_repository_impl.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/data/repositories_impl/shifts_repository_impl.dart @@ -46,145 +46,6 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface { Future> getHistoryShifts() async { final staffId = await _service.getStaffId(); return _connectorRepository.getHistoryShifts(staffId: staffId); - final fdc.QueryResult response = await _service.executeProtected(() => _service.connector - .listCompletedApplicationsByStaffId(staffId: staffId) - .execute()); - final List shifts = []; - - for (final app in response.data.applications) { - _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 = _service.toDateTime(app.shift.date); - final DateTime? startDt = _service.toDateTime(app.shiftRole.startTime); - final DateTime? endDt = _service.toDateTime(app.shiftRole.endTime); - final DateTime? createdDt = _service.toDateTime(app.createdAt); - - shifts.add( - 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, - latitude: app.shift.latitude, - longitude: app.shift.longitude, - breakInfo: BreakAdapter.fromData( - isPaid: app.shiftRole.isBreakPaid ?? false, - breakTime: app.shiftRole.breakType?.stringValue, - ), - ), - ); - } - return shifts; - } - - Future> _fetchApplications({ - DateTime? start, - DateTime? end, - }) async { - final staffId = await _service.getStaffId(); - var query = _service.connector.getMyApplicationsByStaffId(staffId: staffId); - if (start != null && end != null) { - query = query.dayStart(_service.toTimestamp(start)).dayEnd(_service.toTimestamp(end)); - } - final fdc.QueryResult response = - await _service.executeProtected(() => query.execute()); - - final apps = response.data.applications; - final List shifts = []; - - for (final app in apps) { - _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 = _service.toDateTime(app.shift.date); - final DateTime? startDt = _service.toDateTime(app.shiftRole.startTime); - final DateTime? endDt = _service.toDateTime(app.shiftRole.endTime); - final DateTime? createdDt = _service.toDateTime(app.createdAt); - - // Override status to reflect the application state (e.g., CHECKED_OUT, CONFIRMED) - final bool hasCheckIn = app.checkInTime != null; - final bool hasCheckOut = app.checkOutTime != null; - dc.ApplicationStatus? appStatus; - if (app.status is dc.Known) { - appStatus = (app.status as dc.Known).value; - } - final String mappedStatus = hasCheckOut - ? 'completed' - : hasCheckIn - ? 'checked_in' - : _mapStatus(appStatus ?? dc.ApplicationStatus.CONFIRMED); - shifts.add( - 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: mappedStatus, - description: app.shift.description, - durationDays: app.shift.durationDays, - requiredSlots: app.shiftRole.count, - filledSlots: app.shiftRole.assigned ?? 0, - hasApplied: true, - latitude: app.shift.latitude, - longitude: app.shift.longitude, - breakInfo: BreakAdapter.fromData( - isPaid: app.shiftRole.isBreakPaid ?? false, - breakTime: app.shiftRole.breakType?.stringValue, - ), - ), - ); - } - return shifts; - } - - String _mapStatus(dc.ApplicationStatus status) { - switch (status) { - case dc.ApplicationStatus.CONFIRMED: - return 'confirmed'; - case dc.ApplicationStatus.PENDING: - return 'pending'; - case dc.ApplicationStatus.CHECKED_OUT: - return 'completed'; - case dc.ApplicationStatus.REJECTED: - return 'cancelled'; - default: - return 'open'; - } } @override @@ -195,76 +56,6 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface { query: query, type: type, ); - final String? vendorId = dc.StaffSessionStore.instance.session?.ownerId; - if (vendorId == null || vendorId.isEmpty) { - return []; - } - - final fdc.QueryResult result = await _service.executeProtected(() => _service.connector - .listShiftRolesByVendorId(vendorId: vendorId) - .execute()); - - final allShiftRoles = result.data.shiftRoles; - - // Fetch my applications to filter out already booked shifts - final List myShifts = await _fetchApplications(); - final Set myShiftIds = myShifts.map((s) => s.id).toSet(); - - final List mappedShifts = []; - for (final sr in allShiftRoles) { - // Skip if I have already applied/booked this shift - if (myShiftIds.contains(sr.shiftId)) continue; - - - final DateTime? shiftDate = _service.toDateTime(sr.shift.date); - final startDt = _service.toDateTime(sr.startTime); - final endDt = _service.toDateTime(sr.endTime); - final createdDt = _service.toDateTime(sr.createdAt); - - mappedShifts.add( - Shift( - id: sr.shiftId, - roleId: sr.roleId, - title: sr.role.name, - clientName: sr.shift.order.business.businessName, - logoUrl: null, - hourlyRate: sr.role.costPerHour, - location: sr.shift.location ?? '', - locationAddress: sr.shift.locationAddress ?? '', - date: shiftDate?.toIso8601String() ?? '', - startTime: startDt != null - ? DateFormat('HH:mm').format(startDt) - : '', - endTime: endDt != null ? DateFormat('HH:mm').format(endDt) : '', - createdDate: createdDt?.toIso8601String() ?? '', - status: sr.shift.status?.stringValue.toLowerCase() ?? 'open', - description: sr.shift.description, - durationDays: sr.shift.durationDays, - requiredSlots: sr.count, - filledSlots: sr.assigned ?? 0, - latitude: sr.shift.latitude, - longitude: sr.shift.longitude, - orderId: sr.shift.order.id, - orderType: sr.shift.order.orderType?.stringValue, - breakInfo: BreakAdapter.fromData( - isPaid: sr.isBreakPaid ?? false, - breakTime: sr.breakType?.stringValue, - ), - ), - ); - } - - if (query.isNotEmpty) { - return mappedShifts - .where( - (s) => - s.title.toLowerCase().contains(query.toLowerCase()) || - s.clientName.toLowerCase().contains(query.toLowerCase()), - ) - .toList(); - } - - return mappedShifts; } @override