implemented UserCollectionEntry order update on the backend
This commit is contained in:
1 parent
537763ff7d
commit
1b21d84d0b
5 files changed
+49
-36
No files matched your search
@@ -123,33 +123,34 @@ router.post('/:userCollectionId/entries/:entryId', async (req, res) => {
|
||||
});
|
||||
|
||||
// * PATCH - UPDATE ENTRY ORDER IN UserCollection
|
||||
router.patch('/:userCollectionId/entries/:entryId/order', async (req, res) => {
|
||||
router.patch('/:userCollectionId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { userCollectionId, entryId } = req.params;
|
||||
const { newOrder } = req.body; // The new order value
|
||||
const { newOrder } = req.body;
|
||||
|
||||
// Assuming you have a model UserCollectionEntry for the junction table
|
||||
const updated = await UserCollectionEntry.update(
|
||||
{ entryOrder: newOrder }, // Set new order
|
||||
{
|
||||
where: {
|
||||
userCollectionId: userCollectionId,
|
||||
entryId: entryId
|
||||
}
|
||||
// ? getting the collectionEntry
|
||||
const collectionEntry = await UserCollectionEntry.findOne({
|
||||
where: {
|
||||
user_collection_id: userCollectionId,
|
||||
entry_id: entryId
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (updated[0] > 0) {
|
||||
res.status(200).json({ message: 'Entry order updated successfully.' });
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection entry not found.' });
|
||||
if (!collectionEntry) {
|
||||
res.status(404).json({ message: 'UserCollectionEntry not found.' });
|
||||
}
|
||||
|
||||
// ? updating
|
||||
const updated = await collectionEntry.update({ order: newOrder });
|
||||
|
||||
res.status(200).json({ message: 'UserCollectionEntry order updated successfully.' });
|
||||
} catch (error) {
|
||||
console.log(`Error Updating UserCollectionEntry order: `, error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// * DELETE - AND ENTRY FROM A UserCollection
|
||||
// * DELETE - REMOVE AN ENTRY FROM A UserCollection
|
||||
router.delete('/:userCollectionId/entries/:entryId', async (req, res) => {
|
||||
try {
|
||||
const { userCollectionId, entryId } = req.params;
|
||||
|
||||
Reference in new issue
Block a user