getDurations method
Gets the time entries for the current user
If date
is not defined, it will be DateTime.now()
Implementation
Future<List<HeartbeatDuration>> getDurations({
DateTime? date,
String? project,
SlicedBy? sliceBy,
}) async {
date ??= DateTime.now();
final path = '$_baseUrl/users/current/durations';
final response = await _provider.get(
path,
headers: _defaultHeaders,
queryParams: {
'date': DateFormat('yyyy-MM-dd').format(date),
if (project != null) 'project': project,
if (sliceBy != null) 'slice_by': sliceBy.value,
},
);
if (response.statusCode == 200) {
final data = (jsonDecode(response.body) as Map<String, dynamic>);
return (data['data'] as List)
.map((i) => HeartbeatDuration.parse(i))
.toList();
}
return [];
}