updateShift method
Updates an existing Shift.
When adding a Break to a Shift, any earlier Break instances in the Shift have the end_at property set to a valid RFC-3339 datetime string.
When closing a Shift, all Break instances in the Shift must be complete with end_at set on each Break.
Implementation
Future<Shift> updateShift({
required Shift shift,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Uri endpoint = Uri.https(
baseUrl, "/v2/labor/shifts/${shift.id}");
//print (endpoint.toString());
var response = await
http.put(endpoint, body:shift.toJson(), headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return ShiftResponse.fromJson(jsonDecode(response.body)).shift!;
}
else {
print (response.body);
throw TeamMemberException(statusCode: response.statusCode, message: ShiftResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}