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.
|
/// Implementation of [ClockInRepositoryInterface] using Firebase Data Connect.
|
||||||
class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||||
final dc.ExampleConnector _dataConnect;
|
final dc.ExampleConnector _dataConnect;
|
||||||
|
final Map<String, String> _shiftToApplicationId = {};
|
||||||
|
|
||||||
ClockInRepositoryImpl({
|
ClockInRepositoryImpl({
|
||||||
required dc.ExampleConnector dataConnect,
|
required dc.ExampleConnector dataConnect,
|
||||||
@@ -100,6 +101,10 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
|||||||
final apps = result.data.applications;
|
final apps = result.data.applications;
|
||||||
if (apps.isEmpty) return const [];
|
if (apps.isEmpty) return const [];
|
||||||
|
|
||||||
|
_shiftToApplicationId
|
||||||
|
..clear()
|
||||||
|
..addEntries(apps.map((app) => MapEntry(app.shiftId, app.id)));
|
||||||
|
|
||||||
apps.sort((a, b) {
|
apps.sort((a, b) {
|
||||||
final DateTime? aTime =
|
final DateTime? aTime =
|
||||||
_toDateTime(a.shift.startTime) ?? _toDateTime(a.shift.date);
|
_toDateTime(a.shift.startTime) ?? _toDateTime(a.shift.date);
|
||||||
@@ -199,18 +204,24 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
|||||||
Future<AttendanceStatus> clockIn({required String shiftId, String? notes}) async {
|
Future<AttendanceStatus> clockIn({required String shiftId, String? notes}) async {
|
||||||
final String staffId = await _getStaffId();
|
final String staffId = await _getStaffId();
|
||||||
|
|
||||||
final QueryResult<dc.GetApplicationsByStaffIdData, dc.GetApplicationsByStaffIdVariables> appsResult =
|
final String? cachedAppId = _shiftToApplicationId[shiftId];
|
||||||
await _dataConnect.getApplicationsByStaffId(staffId: staffId).execute();
|
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);
|
||||||
|
|
||||||
final dc.GetApplicationsByStaffIdApplications app = appsResult.data.applications.firstWhere((dc.GetApplicationsByStaffIdApplications a) => a.shiftId == shiftId);
|
await _dataConnect
|
||||||
|
.updateApplicationStatus(
|
||||||
await _dataConnect.updateApplicationStatus(
|
id: app.id,
|
||||||
id: app.id,
|
roleId: app.shiftRole.id,
|
||||||
roleId: app.shiftRole.id,
|
)
|
||||||
)
|
.checkInTime(_fromDateTime(DateTime.now()))
|
||||||
.status(dc.ApplicationStatus.CHECKED_IN)
|
.execute();
|
||||||
.checkInTime(_fromDateTime(DateTime.now()))
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
return getAttendanceStatus();
|
return getAttendanceStatus();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user