Removed a non sense entity ownership classroom name check I added a while back, patched the same entity + same name + same admin query
This commit is contained in:
@@ -22,9 +22,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
case 'existantGroupIds':
|
||||
res.status(200).json(await existantGroupIds(req.body.names));
|
||||
break;
|
||||
case 'crossRefOwnership':
|
||||
res.status(200).json(await crossRefOwnership(req.body));
|
||||
break;
|
||||
case 'getIds':
|
||||
res.status(200).json(await getIds(req.body));
|
||||
break;
|
||||
@@ -40,45 +37,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
async function crossRefOwnership(body: any): Promise<string[]> {
|
||||
const { userId, classrooms, entity } = body;
|
||||
|
||||
const existingClassrooms = await db.collection('groups')
|
||||
.find({
|
||||
name: { $in: classrooms },
|
||||
admin: { $ne: userId }
|
||||
})
|
||||
.project({ name: 1, admin: 1, _id: 0 })
|
||||
.toArray();
|
||||
|
||||
if (existingClassrooms.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const adminUsers = await db.collection('users')
|
||||
.find({
|
||||
id: { $in: existingClassrooms.map(classroom => classroom.admin) }
|
||||
})
|
||||
.project({ id: 1, entities: 1, _id: 0 })
|
||||
.toArray();
|
||||
|
||||
const adminEntitiesMap = new Map(
|
||||
adminUsers.map(admin => [
|
||||
admin.id,
|
||||
admin.entities?.map((e: any) => e.id) || []
|
||||
])
|
||||
);
|
||||
|
||||
return Array.from(new Set(
|
||||
existingClassrooms
|
||||
.filter(classroom => {
|
||||
const adminEntities = adminEntitiesMap.get(classroom.admin) || [];
|
||||
return adminEntities.includes(entity);
|
||||
})
|
||||
.map(classroom => classroom.name)
|
||||
));
|
||||
}
|
||||
|
||||
async function getIds(body: any): Promise<Record<string, string>> {
|
||||
const { names, userEmails } = body;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user