Skip to content

Commit a1516ee

Browse files
authored
Merge pull request #109 from codeurjc-students/feature-websocket-admin-notifications
feat: Implement WebSocket notifications for admin when objects are shared
2 parents 5f635cf + 84de43e commit a1516ee

File tree

12 files changed

+744
-92
lines changed

12 files changed

+744
-92
lines changed

LogArtApp/backend/controllers/objectController.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const objectService = require("../services/objectService");
22
const userService = require("../services/userService");
3+
const socketUtils = require("../utils/socketUtils");
34

45
/**
56
* @swagger
@@ -378,6 +379,23 @@ const togglePublicShare = async (req, res) => {
378379
const { objectId } = req.params;
379380
const userId = req.user.userId;
380381
const result = await objectService.togglePublicShare(objectId, userId);
382+
if (result.isPubliclyShared) {
383+
try {
384+
const user = await userService.getUserById(userId);
385+
const object = await objectService.getObjectById(objectId, userId);
386+
const notification = {
387+
type: "object_shared",
388+
objectId: objectId,
389+
objectName: object.name,
390+
userId: userId,
391+
userName: `${user.firstName} ${user.lastName}`,
392+
timestamp: new Date(),
393+
};
394+
socketUtils.notifyAdmins(req, notification);
395+
} catch (notifyError) {
396+
console.error("Error al notificar a los administradores:", notifyError);
397+
}
398+
}
381399
return res.status(200).json(result);
382400
} catch (error) {
383401
console.error("Error en togglePublicShare:", error);

0 commit comments

Comments
 (0)