chaging id for application
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../domain/repositories/clock_in_repository_interface.dart';
|
||||
/// Implementation of [ClockInRepositoryInterface] using Firebase Data Connect.
|
||||
class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||
final dc.ExampleConnector _dataConnect;
|
||||
final Map<String, String> _shiftToApplicationId = {};
|
||||
|
||||
ClockInRepositoryImpl({
|
||||
required dc.ExampleConnector dataConnect,
|
||||
@@ -100,6 +101,10 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||
final apps = result.data.applications;
|
||||
if (apps.isEmpty) return const [];
|
||||
|
||||
_shiftToApplicationId
|
||||
..clear()
|
||||
..addEntries(apps.map((app) => MapEntry(app.shiftId, app.id)));
|
||||
|
||||
apps.sort((a, b) {
|
||||
final DateTime? aTime =
|
||||
_toDateTime(a.shift.startTime) ?? _toDateTime(a.shift.date);
|
||||
@@ -198,19 +203,25 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||
@override
|
||||
Future<AttendanceStatus> clockIn({required String shiftId, String? notes}) async {
|
||||
final String staffId = await _getStaffId();
|
||||
|
||||
final QueryResult<dc.GetApplicationsByStaffIdData, dc.GetApplicationsByStaffIdVariables> appsResult =
|
||||
await _dataConnect.getApplicationsByStaffId(staffId: staffId).execute();
|
||||
|
||||
final dc.GetApplicationsByStaffIdApplications app = appsResult.data.applications.firstWhere((dc.GetApplicationsByStaffIdApplications a) => a.shiftId == shiftId);
|
||||
|
||||
await _dataConnect.updateApplicationStatus(
|
||||
id: app.id,
|
||||
roleId: app.shiftRole.id,
|
||||
)
|
||||
.status(dc.ApplicationStatus.CHECKED_IN)
|
||||
.checkInTime(_fromDateTime(DateTime.now()))
|
||||
.execute();
|
||||
|
||||
final String? cachedAppId = _shiftToApplicationId[shiftId];
|
||||
dc.GetApplicationsByStaffIdApplications? app;
|
||||
if (cachedAppId != null) {
|
||||
try {
|
||||
final apps = await _getTodaysApplications(staffId);
|
||||
app = apps.firstWhere((a) => a.id == cachedAppId);
|
||||
} catch (_) {}
|
||||
}
|
||||
app ??= (await _getTodaysApplications(staffId))
|
||||
.firstWhere((a) => a.shiftId == shiftId);
|
||||
|
||||
await _dataConnect
|
||||
.updateApplicationStatus(
|
||||
id: app.id,
|
||||
roleId: app.shiftRole.id,
|
||||
)
|
||||
.checkInTime(_fromDateTime(DateTime.now()))
|
||||
.execute();
|
||||
|
||||
return getAttendanceStatus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user