mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
Fix query if "_class" is object with "$nin" (#2620)
Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
parent
ef77d22116
commit
47191c0b37
@ -121,6 +121,24 @@ abstract class MongoAdapterBase implements DbAdapter {
|
||||
// Only replace if not specified
|
||||
if (translated._class === undefined) {
|
||||
translated._class = { $in: classes }
|
||||
} else if (typeof translated._class === 'string') {
|
||||
if (!classes.includes(translated._class)) {
|
||||
translated._class = { $in: classes }
|
||||
}
|
||||
} else if (typeof translated._class === 'object') {
|
||||
const classesIds = new Set(classes)
|
||||
let descendants: Ref<Class<Doc>>[] = classes
|
||||
|
||||
if (Array.isArray(translated._class.$in)) {
|
||||
descendants = translated._class.$in.filter((c: Ref<Class<Doc>>) => classesIds.has(c))
|
||||
}
|
||||
|
||||
if (Array.isArray(translated._class.$nin)) {
|
||||
const excludedClassesIds = new Set<Ref<Class<Doc>>>(translated._class.$nin)
|
||||
descendants = descendants.filter((c) => !excludedClassesIds.has(c))
|
||||
}
|
||||
|
||||
translated._class = { $in: descendants }
|
||||
}
|
||||
|
||||
if (baseClass !== clazz) {
|
||||
|
Loading…
Reference in New Issue
Block a user