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:
Carlos-Mesquita
2025-01-06 20:46:18 +00:00
parent bc89f4b9ce
commit f6cd509aa4
4 changed files with 17 additions and 166 deletions

View File

@@ -169,8 +169,12 @@ async function entityCheck(body: Record<string, any>): Promise<Array<{
}
async function crossRefClassrooms(body: any) {
const { sets, entity } = body as { sets: { email: string, classroom: string }[], entity: string };
const { sets, entity, userId } = body as {
sets: { email: string, classroom: string }[],
entity: string,
userId: string
};
const pipeline = [
// Match users with the provided emails
{
@@ -189,6 +193,8 @@ async function crossRefClassrooms(body: any) {
$expr: {
$and: [
{ $in: ['$$userId', '$participants'] },
{ $eq: ['$admin', userId] },
{ $eq: ['$entity', entity] },
{
$let: {
vars: {
@@ -210,38 +216,6 @@ async function crossRefClassrooms(body: any) {
]
}
}
},
// Lookup admin's entities
{
$lookup: {
from: 'users',
let: { adminId: '$admin' },
pipeline: [
{
$match: {
$expr: { $eq: ['$id', '$$adminId'] }
}
}
],
as: 'adminInfo'
}
},
// Filter where admin has the target entity
{
$match: {
$expr: {
$in: [
entity,
{
$map: {
input: { $arrayElemAt: ['$adminInfo.entities', 0] },
as: 'entityObj',
in: '$$entityObj.id'
}
}
]
}
}
}
],
as: 'matchingGroups'