{
"workingHours":
[
{
"date":"2023-02-01",
"amount":3,
"freigegeben":false
}
]
}
Whenever I include this in my request Body, I encounter the error mentioned in the title. How can I manually change the format to make it an Array by adding [ and ], or what other solutions could I explore?
Below is the request I am sending:
public async saveWorkingHours(
employeeId: string | null,
workingHours: WorkingHours[]
): Promise<boolean> {
var result = Object.entries(workingHours.map(wh => ({ ...wh, date: this.dateService.format(wh.date) })));
try {
await this.httpService.fetch(
`${this.apiUrl}employees/${employeeId}/workingHours`,
HttpMethod.PUT,
{
// The issue lies in the body starting with "{", instead of "[".
workingHours: workingHours.map(wh => ({ ...wh, date: this.dateService.format(wh.date) })),
}
);
return true;
} catch (e) {
console.error(e);
return false;
}
}
Definition of Workinghours interface:
export interface WorkingHours {
date: Date;
amount: number;
freigegeben: boolean;
}
Converting the format:
var convertedFormatData = [];
var tempObj = {
workingHours: workingHours.map((wh) => ({
...wh,
date: this.dateService.format(wh.date),
})),
};
convertedFormatData.push(tempObj);
The resulting output appears as shown below:
{"convertedFormatData":[{"workingHours":[{"date":"2023-02-01","amount":3,"freigegeben":false},{ ...