refactor(rooms) adding idc checks for adding admins to rooms

This commit is contained in:
CodeTrauma
2023-11-13 14:41:49 +03:00
parent c4f0c9f467
commit c1803e4984
2 changed files with 17 additions and 1 deletions

View File

@@ -288,6 +288,22 @@ router.post(
const { roomId } = req.params;
const { idc } = req.body as { idc: string };
try {
const admins = await prisma.rooms.findFirst({
where: {
roomId: roomId
},
select: {
adminIdentities: true
}
}) as { adminIdentities: string[] };
if (!admins) {
res.status(400).json({ error: 'Room not found' });
return;
}
if (admins.adminIdentities.includes(idc)) {
res.status(400).json({ error: 'Admin already in room' });
return;
}
await prisma.rooms.update({
where: {
roomId: roomId

View File

@@ -338,7 +338,7 @@ router.post('/setpassword/:id', limiter, asyncHandler(async (req: Request, res:
res.status(500).send('Error finding room');
})
} else {
res.status(401).json({ success: false, message: 'Unauthorized ' });
res.status(401).json({ success: false, message: 'Unauthorized' });
}
}))