feat(shift): enhance Shift entity with client and role names, update JSON deserialization

This commit is contained in:
Achintha Isuru
2026-03-18 17:56:48 -04:00
parent f5699865f9
commit baf426935e
3 changed files with 69 additions and 35 deletions

View File

@@ -28,19 +28,36 @@ class Shift extends Equatable {
this.clockInMode,
this.allowClockInOverride,
this.nfcTagId,
this.clientName,
this.roleName,
});
/// Deserialises from the V2 API JSON response.
///
/// Supports both the standard shift JSON shape (`id`, `startsAt`, `endsAt`)
/// and the today-shifts endpoint shape (`shiftId`, `startTime`, `endTime`).
factory Shift.fromJson(Map<String, dynamic> json) {
final String? clientName = json['clientName'] as String?;
final String? roleName = json['roleName'] as String?;
return Shift(
id: json['id'] as String,
id: json['id'] as String? ?? json['shiftId'] as String,
orderId: json['orderId'] as String?,
title: json['title'] as String? ?? '',
title: json['title'] as String? ??
roleName ??
clientName ??
'',
status: ShiftStatus.fromJson(json['status'] as String?),
startsAt: DateTime.parse(json['startsAt'] as String),
endsAt: DateTime.parse(json['endsAt'] as String),
startsAt: DateTime.parse(
json['startsAt'] as String? ?? json['startTime'] as String,
),
endsAt: DateTime.parse(
json['endsAt'] as String? ?? json['endTime'] as String,
),
timezone: json['timezone'] as String? ?? 'UTC',
locationName: json['locationName'] as String?,
locationName: json['locationName'] as String? ??
json['locationAddress'] as String? ??
json['location'] as String?,
locationAddress: json['locationAddress'] as String?,
latitude: parseDouble(json['latitude']),
longitude: parseDouble(json['longitude']),
@@ -51,6 +68,8 @@ class Shift extends Equatable {
clockInMode: json['clockInMode'] as String?,
allowClockInOverride: json['allowClockInOverride'] as bool?,
nfcTagId: json['nfcTagId'] as String?,
clientName: clientName,
roleName: roleName,
);
}
@@ -108,6 +127,12 @@ class Shift extends Equatable {
/// NFC tag identifier for NFC-based clock-in.
final String? nfcTagId;
/// Name of the client (business) this shift belongs to.
final String? clientName;
/// Name of the role the worker is assigned for this shift.
final String? roleName;
/// Serialises to JSON.
Map<String, dynamic> toJson() {
return <String, dynamic>{
@@ -129,6 +154,8 @@ class Shift extends Equatable {
'clockInMode': clockInMode,
'allowClockInOverride': allowClockInOverride,
'nfcTagId': nfcTagId,
'clientName': clientName,
'roleName': roleName,
};
}
@@ -161,5 +188,7 @@ class Shift extends Equatable {
clockInMode,
allowClockInOverride,
nfcTagId,
clientName,
roleName,
];
}