еще правки для бэка
This commit is contained in:
@@ -18,4 +18,7 @@ export const updateStream = (id, s) =>
|
||||
body: JSON.stringify(s),
|
||||
}).then((r) => r.json());
|
||||
|
||||
export const deleteStream = (id) => fetch(`${BASE}/${id}`, { method: "DELETE" });
|
||||
export const deleteStream = (id) =>
|
||||
fetch(`${BASE}/${id}`, {
|
||||
method: "DELETE",
|
||||
}).then((r) => r.json());
|
||||
|
||||
@@ -34,10 +34,10 @@ export function useStreams() {
|
||||
const extended = streamsData.map((stream) => ({
|
||||
...stream,
|
||||
id: String(stream.id),
|
||||
playlistId: String(stream.playlistId),
|
||||
categoryId: String(stream.categoryId),
|
||||
category: categoriesData.find((g) => String(g.id) === String(stream.categoryId)),
|
||||
playlist: playlistsData.find((d) => String(d.id) === String(stream.playlistId)),
|
||||
playlistId: stream.playlist ? String(stream.playlist.id) : "",
|
||||
categoryId: stream.category ? String(stream.category.id) : "",
|
||||
category: stream.category,
|
||||
playlist: stream.playlist,
|
||||
}));
|
||||
|
||||
setStreams(extended);
|
||||
@@ -88,16 +88,18 @@ export function useStreams() {
|
||||
}
|
||||
|
||||
async function save(stream) {
|
||||
const streamWithStringIds = {
|
||||
...stream,
|
||||
playlistId: String(stream.playlistId),
|
||||
categoryId: String(stream.categoryId),
|
||||
const saveStream = {
|
||||
name: stream.name,
|
||||
image: stream.image,
|
||||
description: stream.description,
|
||||
playlistId: Number(stream.playlistId),
|
||||
categoryId: Number(stream.categoryId),
|
||||
};
|
||||
|
||||
if (stream.id) {
|
||||
await API.updateStream(String(stream.id), streamWithStringIds);
|
||||
await API.updateStream(String(stream.id), saveStream);
|
||||
} else {
|
||||
await API.createStream(streamWithStringIds);
|
||||
await API.createStream(saveStream);
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user