Skip to content

Commit

Permalink
Add reindex route, elastic delete on user deleteall
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy committed Aug 7, 2020
1 parent 0c66ace commit 57415d4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Backend/src/routes/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,13 @@ router.delete(
},
transaction: t
})
})
}).then(() => {
return ElasticService.deleteRecipesByUser(res.locals.session.userId);
});
}).then(() => {
res.status(200).send({})
}).catch(next);
})
});

router.post(
'/delete-bulk',
Expand Down Expand Up @@ -775,5 +777,18 @@ router.delete(
.catch(next);
});

router.post('/reindex', MiddlewareService.validateSession(['user']), async (req, res, next) => {
const recipes = await Recipe.findAll({
where: {
userId: res.locals.session.userId,
}
});

await ElasticService.deleteRecipesByUser(res.locals.session.userId);

await ElasticService.indexRecipes(recipes);

res.status(200).send({});
});

module.exports = router;

0 comments on commit 57415d4

Please sign in to comment.