UBER-480: Fix ValueFilter for space-like objects (#3428)

This commit is contained in:
Vyacheslav Tumanov 2023-06-15 10:31:36 +05:00 committed by GitHub
parent 8c282362a6
commit 9ea3f4c3a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,26 +67,30 @@
}
: {}
let prefix = ''
const hieararchy = client.getHierarchy()
const attr = hieararchy.getAttribute(filter.key._class, filter.key.key)
if (hieararchy.isMixin(attr.attributeOf)) {
const hierarchy = client.getHierarchy()
const attr = hierarchy.getAttribute(filter.key._class, filter.key.key)
if (hierarchy.isMixin(attr.attributeOf)) {
prefix = attr.attributeOf + '.'
}
const isDerivedFromSpace = hierarchy.isDerived(_class, core.class.Space)
objectsPromise = client.findAll(
_class,
{ ...resultQuery, ...(space ? { space } : { '$lookup.space.archived': false }) },
{
...resultQuery,
...(space ? { space } : isDerivedFromSpace ? { archived: false } : { '$lookup.space.archived': false })
},
{
sort: { [filter.key.key]: SortingOrder.Ascending },
projection: { [prefix + filter.key.key]: 1, space: 1 },
...(space ? {} : { lookup: { space: core.class.Space } })
...(space || isDerivedFromSpace ? {} : { lookup: { space: core.class.Space } })
}
)
const res = await objectsPromise
for (const object of res) {
let asDoc = object
if (hieararchy.isMixin(filter.key._class)) {
asDoc = hieararchy.as(object, filter.key._class)
if (hierarchy.isMixin(filter.key._class)) {
asDoc = hierarchy.as(object, filter.key._class)
}
const realValue = getObjectValue(filter.key.key, asDoc)
const value = getValue(realValue)