Files
bodyshop/server/web-sockets/updateBodyshopCache.js
2025-03-04 17:07:31 -05:00

37 lines
1.0 KiB
JavaScript

/**
* Update or invalidate bodyshop cache
* @param req
* @param res
* @returns {Promise<void>}
*/
const updateBodyshopCache = async (req, res) => {
const {
sessionUtils: { updateOrInvalidateBodyshopFromRedis },
logger
} = req;
const { event } = req.body;
const { new: newData } = event.data;
try {
if (newData && newData.id) {
// Update cache with the full new data object
await updateOrInvalidateBodyshopFromRedis(newData.id, newData);
logger.logger.debug("Bodyshop cache updated successfully.");
} else {
// Invalidate cache if no valid data provided
await updateOrInvalidateBodyshopFromRedis(newData.id);
logger.logger.debug("Bodyshop cache invalidated successfully.");
}
res.status(200).json({ success: true });
} catch (error) {
logger.log("bodyshop-cache-update-error", "ERROR", "api", "redis", {
message: error?.message,
stack: error?.stack
});
res.status(500).json({ success: false, error: error.message });
}
};
module.exports = updateBodyshopCache;