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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user