feat(admin) route for removing admins

This commit is contained in:
CodeTrauma
2023-11-13 13:09:19 +03:00
parent 93e881e776
commit 6e0f7ae943
4 changed files with 40 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ const prisma = new PrismaClient();
/**
* Creates a new room with the given name and optional parameters.
* @param {string} name - The name of the room.
* @param {string} roomName - The name of the room.
* @param {number} [rateLimit=10000] - The length of an epoch in milliseconds
* @param {number} [userMessageLimit=12] - The message limit per user per epoch
* @param {number} [numClaimCodes=0] - The number of claim codes to generate for the room.

View File

@@ -55,7 +55,7 @@ https://github.com/Discreetly/IdentityCommitmentNullifierCircuit <- Circuit and
*/
/**
* This function takes in an identity and returns the rooms the identity is in.
* @param identity - the identity of a user
* @param {string} identity - the identity of a user
* @returns an array of roomIds
*/
export async function findRoomsByIdentity(identity: string): Promise<string[]> {
@@ -146,7 +146,7 @@ export async function findRoomWithMessageId(
if (room.epochs[0]) {
return room.epochs[0].messages[0] as MessageI;
} else {
console.debug('Epoch not found');
console.debug('Epoch not found, new epoch');
return null;
}
} catch (err) {

View File

@@ -13,8 +13,8 @@ const prisma = new PrismaClient();
* It adds the identity commitment to the identity list of each room,
* and also adds it to the bandada of each room. The identity commitment is
* sanitized before being added to the database.
* @param idc - The identity commitment of the user
* @param roomIds - The list of roomIds that the user is in
* @param {string} idc - The identity commitment of the user
* @param {string[]} roomIds - The list of roomIds that the user is in
* @returns {Promise<void>} - A promise that resolves when the update is complete
*/
export async function updateRoomIdentities(

View File

@@ -304,5 +304,39 @@ router.post(
}
})
);
router.post('/:roomId/removeAdmin', adminAuth, asyncHandler(async (req: Request, res: Response) => {
const { roomId } = req.params;
const { idc } = req.body as { idc: string };
try {
const admins = await prisma.rooms.findUnique({
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 not found in room' });
return;
}
await prisma.rooms.update({
where: {
roomId: roomId
},
data: {
adminIdentities: {
set: admins.adminIdentities.filter((admin) => admin !== idc)
}
}
});
res.status(200).json({ message: `Admin removed from room ${roomId}` });
} catch (err) {
res.status(500).json({ error: 'Internal Server Error' });
}
}));
export default router;