mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-24 04:17:50 +00:00
TSK-889: Fix hang and displayName search for Employee (#2783)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
f0319b42e5
commit
1c8a7d521d
@ -128,17 +128,17 @@
|
||||
}
|
||||
}
|
||||
categoryStatus = newCategoryStatus
|
||||
}
|
||||
$: updateItems(category, query, relatedDocuments)
|
||||
|
||||
$: if (items.length === 0) {
|
||||
for (const c of categories) {
|
||||
if ((categoryStatus[c._id] ?? 0) > 0) {
|
||||
category = c
|
||||
break
|
||||
if (items.length === 0) {
|
||||
for (const c of categories) {
|
||||
if (category !== c && (categoryStatus[c._id] ?? 0) > 0) {
|
||||
category = c
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$: updateItems(category, query, relatedDocuments)
|
||||
|
||||
const manager = createFocusManager()
|
||||
</script>
|
||||
|
@ -108,8 +108,38 @@ async function queryContact (
|
||||
search: string,
|
||||
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
||||
): Promise<ObjectSearchResult[]> {
|
||||
let q: DocumentQuery<Contact> = { name: { $like: `%${search}%` } }
|
||||
if (_class === contact.class.Employee) q = { ...q, active: true }
|
||||
const q: DocumentQuery<Contact> = { name: { $like: `%${search}%` } }
|
||||
return await doContactQuery(_class, q, filter, client)
|
||||
}
|
||||
|
||||
async function queryEmployee (
|
||||
client: Client,
|
||||
search: string,
|
||||
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
||||
): Promise<ObjectSearchResult[]> {
|
||||
const q1 = await doContactQuery(contact.class.Employee, { name: { $like: `%${search}%` } }, filter, client)
|
||||
const q2 = await doContactQuery(
|
||||
contact.class.Employee,
|
||||
{ displayName: { $like: `%${search}%` } },
|
||||
{
|
||||
in: filter?.in,
|
||||
nin: [...(filter?.nin ?? []), ...Array.from(q1.map((it) => ({ _id: it.doc._id, _class: it.doc._class })))]
|
||||
},
|
||||
client
|
||||
)
|
||||
|
||||
return q1.concat(q2)
|
||||
}
|
||||
|
||||
async function doContactQuery (
|
||||
_class: Ref<Class<Contact>>,
|
||||
q: DocumentQuery<Contact>,
|
||||
filter: { in?: RelatedDocument[] | undefined, nin?: RelatedDocument[] | undefined } | undefined,
|
||||
client: Client
|
||||
): Promise<ObjectSearchResult[]> {
|
||||
if (_class === contact.class.Employee) {
|
||||
q = { ...q, active: true }
|
||||
}
|
||||
if (filter?.in !== undefined || filter?.nin !== undefined) {
|
||||
q._id = {}
|
||||
if (filter.in !== undefined) {
|
||||
@ -199,7 +229,7 @@ export default async (): Promise<Resources> => ({
|
||||
client: Client,
|
||||
query: string,
|
||||
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
||||
) => await queryContact(contact.class.Employee, client, query, filter),
|
||||
) => await queryEmployee(client, query, filter),
|
||||
PersonQuery: async (client: Client, query: string, filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }) =>
|
||||
await queryContact(contact.class.Person, client, query, filter),
|
||||
OrganizationQuery: async (
|
||||
|
Loading…
Reference in New Issue
Block a user