Front: fix entry removed from collection not updating UI

This commit is contained in:
X4Lo committed 2024-10-21 15:55:36 +01:00
1 parent 302f2830ff
commit 1e1384d777
10 files changed
+170 -73

No files matched your search

+13 -15
View File
@@ -301,18 +301,18 @@ collectionRouter.delete('/:id', async (req, res) => {
});
// * POST - ADD ENTRY TO A COLLECTION
collectionRouter.post('/:userCollectionId/entries/:entryId', async (req, res) => {
collectionRouter.post('/:collectionId/entries/:entryId', async (req, res) => {
try {
const { userCollectionId, entryId } = req.params;
const { collectionId, entryId } = req.params;
const newUserCollectionEntry = await UserCollectionEntry.create({
user_collection_id: userCollectionId,
user_collection_id: collectionId,
entry_id: entryId
});
// ? set a default poster if none exists
const userCollection = await Collection.findByPk(userCollectionId);
if (!userCollection.poster_path || userCollection.poster_path.trim() === '') {
const userCollection = await Collection.findByPk(collectionId);
if (!userCollection.poster_path || userCollection.poster_path.trim() == '') {
const entry = await Entry.findByPk(entryId);
userCollection.poster_path = entry.poster_path;
await userCollection.save();
@@ -326,15 +326,15 @@ collectionRouter.post('/:userCollectionId/entries/:entryId', async (req, res) =>
});
// * PATCH - UPDATE ENTRY ORDER IN COLLECTION
collectionRouter.patch('/:userCollectionId/entries/:entryId', async (req, res) => {
collectionRouter.patch('/:collectionId/entries/:entryId', async (req, res) => {
try {
const { userCollectionId, entryId } = req.params;
const { collectionId, entryId } = req.params;
const { newOrder } = req.body;
// ? getting the collectionEntry
const collectionEntry = await UserCollectionEntry.findOne({
where: {
user_collection_id: userCollectionId,
user_collection_id: collectionId,
entry_id: entryId
}
});
@@ -354,23 +354,21 @@ collectionRouter.patch('/:userCollectionId/entries/:entryId', async (req, res) =
});
// * DELETE - REMOVE AN ENTRY FROM A COLLECTION
collectionRouter.delete('/:userCollectionId/entries/:entryId', async (req, res) => {
collectionRouter.delete('/:collectionId/entries/:entryId', async (req, res) => {
try {
const { userCollectionId, entryId } = req.params;
const { collectionId, entryId } = req.params;
const deleted = await UserCollectionEntry.findOne({
where: {
user_collection_id: userCollectionId,
user_collection_id: collectionId,
entry_id: entryId
}
});
console.log(`deleteing : `, deleted)
const deletedCount = deleted.destroy();
if (deleted) {
await deleted.destroy();
res.status(204).send();
} else {
res.status(404).json({ message: 'UserCollection entry not found.' });
res.status(404).json({ message: 'CollectionEntry not found.' });
}
} catch (error) {
res.status(500).json({ error: error.message });