streamby-core 0.26.3 → 0.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ const manager_1 = require("../../models/manager");
6
6
  const auth_1 = require("../../utils/auth");
7
7
  const connectionManager_1 = require("../../adapters/database/connectionManager");
8
8
  const sql_1 = require("../../adapters/database/sql");
9
+ const notification_1 = require("../../services/notification");
9
10
  const VALID_ROLES = ['viewer', 'editor', 'admin'];
10
11
  function memberRouter(config) {
11
12
  const router = (0, express_1.Router)();
@@ -77,7 +78,7 @@ function memberRouter(config) {
77
78
  if (!user) {
78
79
  return res.status(404).json({ message: 'User not found' });
79
80
  }
80
- const newMember = { userId, username: user.username, role, archived: false };
81
+ const newMember = { userId, username: user.username, role, archived: false, status: 'pending', invitedBy: auth.userId };
81
82
  if (project.dbType === 'sql') {
82
83
  const connection = getSqlConnection();
83
84
  if (!connection) {
@@ -88,11 +89,14 @@ function memberRouter(config) {
88
89
  userId,
89
90
  role,
90
91
  archived: false,
92
+ status: 'pending',
93
+ invitedBy: auth.userId,
91
94
  }, 'streamby');
92
95
  }
93
96
  else {
94
97
  await Project.update({ _id: projectId }, { $push: { members: newMember } });
95
98
  }
99
+ await (0, notification_1.createNotification)(userId, 'member_invited', `Te invitaron al proyecto "${project.name}"`, { projectId, role, invitedBy: auth.userId });
96
100
  res.status(201).json({ member: newMember, message: 'Member invited successfully' });
97
101
  }
98
102
  catch (err) {
@@ -139,6 +143,59 @@ function memberRouter(config) {
139
143
  res.status(500).json({ message: 'Failed to update member role', details: err.message });
140
144
  }
141
145
  });
146
+ router.patch('/projects/:id/members/:userId/accept', async (req, res) => {
147
+ try {
148
+ const auth = req.auth;
149
+ const { id: projectId, userId: targetUserId } = req.params;
150
+ if (auth.userId !== targetUserId) {
151
+ return res.status(403).json({ message: 'You can only accept your own invitations' });
152
+ }
153
+ const project = await Project.findOne({ _id: projectId });
154
+ if (!project) {
155
+ return res.status(404).json({ message: 'Project not found' });
156
+ }
157
+ const member = project.members?.find((m) => m.userId?.toString() === targetUserId);
158
+ if (!member) {
159
+ return res.status(404).json({ message: 'Invitation not found' });
160
+ }
161
+ if (member.status !== 'pending') {
162
+ return res.status(400).json({ message: 'Invitation is no longer pending' });
163
+ }
164
+ const updatedMembers = project.members.map((m) => m.userId?.toString() === targetUserId ? { ...m, status: 'active' } : m);
165
+ await Project.update({ _id: projectId }, { members: updatedMembers });
166
+ await (0, notification_1.createNotification)(member.invitedBy, 'member_accepted', `${member.username} aceptó la invitación al proyecto "${project.name}"`, { projectId, userId: targetUserId });
167
+ res.status(200).json({ message: 'Invitation accepted' });
168
+ }
169
+ catch (err) {
170
+ res.status(500).json({ message: 'Failed to accept invitation', details: err.message });
171
+ }
172
+ });
173
+ router.patch('/projects/:id/members/:userId/reject', async (req, res) => {
174
+ try {
175
+ const auth = req.auth;
176
+ const { id: projectId, userId: targetUserId } = req.params;
177
+ if (auth.userId !== targetUserId) {
178
+ return res.status(403).json({ message: 'You can only reject your own invitations' });
179
+ }
180
+ const project = await Project.findOne({ _id: projectId });
181
+ if (!project) {
182
+ return res.status(404).json({ message: 'Project not found' });
183
+ }
184
+ const member = project.members?.find((m) => m.userId?.toString() === targetUserId);
185
+ if (!member) {
186
+ return res.status(404).json({ message: 'Invitation not found' });
187
+ }
188
+ if (member.status !== 'pending') {
189
+ return res.status(400).json({ message: 'Invitation is no longer pending' });
190
+ }
191
+ await Project.update({ _id: projectId }, { $pull: { members: { userId: targetUserId } } });
192
+ await (0, notification_1.createNotification)(member.invitedBy, 'member_rejected', `${member.username} rechazó la invitación al proyecto "${project.name}"`, { projectId, userId: targetUserId });
193
+ res.status(200).json({ message: 'Invitation rejected' });
194
+ }
195
+ catch (err) {
196
+ res.status(500).json({ message: 'Failed to reject invitation', details: err.message });
197
+ }
198
+ });
142
199
  router.delete('/projects/:id/members/:userId', async (req, res) => {
143
200
  try {
144
201
  const auth = req.auth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.26.3",
3
+ "version": "0.26.4",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",