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