Files
bodyshop/server/utils/ioHelpers.js
2025-05-20 13:14:05 -04:00

32 lines
900 B
JavaScript

/**
* @module ioHelpers
* @param app
* @param api
* @param io
* @param logger
* @returns {{getBodyshopRoom: (function(*): string), getBodyshopConversationRoom: (function({bodyshopId: *, conversationId: *}): string)}}
*/
const applyIOHelpers = ({ app, api, io, logger }) => {
// Global Bodyshop Room
const getBodyshopRoom = (bodyshopId) => `bodyshop-broadcast-room:${bodyshopId}`;
// Messaging - conversation specific room to handle detailed messages when the user has a conversation open.
const getBodyshopConversationRoom = ({ bodyshopId, conversationId }) =>
`bodyshop-conversation-room:${bodyshopId}:${conversationId}`;
const ioHelpersAPI = {
getBodyshopRoom,
getBodyshopConversationRoom
};
// Helper middleware
app.use((req, res, next) => {
req.ioHelpers = ioHelpersAPI;
next();
});
return ioHelpersAPI;
};
module.exports = { applyIOHelpers };