From ab4cea6ee61010dc4fdcd585202a84ea1221acd2 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Fri, 4 Mar 2022 21:42:02 +0700 Subject: [PATCH] Few fixes (#1099) Signed-off-by: Andrey Sobolev --- packages/core/src/client.ts | 16 ++++++++++-- packages/core/src/hierarchy.ts | 2 +- .../src/components/Vacancies.svelte | 26 ++++++++++++++----- server/core/src/storage.ts | 14 +++++++--- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 34e87cd110..59c89fd356 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -144,8 +144,20 @@ export async function createClient ( const txMap = new Map, Ref>() for (const tx of txes) txMap.set(tx._id, tx._id) - for (const tx of txes) hierarchy.tx(tx) - for (const tx of txes) await model.tx(tx) + for (const tx of txes) { + try { + hierarchy.tx(tx) + } catch (err: any) { + console.error('failed to apply model transaction, skipping', JSON.stringify(tx), err) + } + } + for (const tx of txes) { + try { + await model.tx(tx) + } catch (err: any) { + console.error('failed to apply model transaction, skipping', JSON.stringify(tx), err) + } + } txBuffer = txBuffer.filter((tx) => txMap.get(tx._id) === undefined) diff --git a/packages/core/src/hierarchy.ts b/packages/core/src/hierarchy.ts index 68f9970c6c..d99c807ff9 100644 --- a/packages/core/src/hierarchy.ts +++ b/packages/core/src/hierarchy.ts @@ -364,7 +364,7 @@ export class Hierarchy { const _cl = getClass(v as ToClassRefT) if (this.isMixin(_cl)) { const mval = (lookup as any)[k] - if (mval !== undefined) { + if (mval != null) { (lookup as any)[k] = this.as(mval, _cl) } } diff --git a/plugins/recruit-resources/src/components/Vacancies.svelte b/plugins/recruit-resources/src/components/Vacancies.svelte index dd892bb03a..d0c99f1c38 100644 --- a/plugins/recruit-resources/src/components/Vacancies.svelte +++ b/plugins/recruit-resources/src/components/Vacancies.svelte @@ -30,34 +30,45 @@ } let search: string = '' + let vquery: string = '' let resultQuery: DocumentQuery = {} let vacancyQuery: DocumentQuery = {} - async function updateResultQuery (search: string): Promise { - resultQuery = search === '' ? {} : { $search: search } - } - let vacancies: Vacancy[] = [] const query = createQuery() + let appQuery = false $: query.query(recruit.class.Vacancy, { archived: false }, (res) => { vacancies = res }) - $: if (vacancies.length > 0) { + function lowerIncludes (a?: string, b: string): boolean { + return (a ?? '').toLowerCase().includes(b) + } + + $: if (vacancies.length > 0 && !appQuery) { vacancyQuery = { _id: { $in: vacancies - .filter((it) => it.name.includes(search) || it.description.includes(search) || it.company?.includes(search) || ((applications?.get(it._id) ?? 0) > 0)) + .filter( + (it) => + lowerIncludes(it.name, vquery) || + lowerIncludes(it.description, vquery) || + lowerIncludes(it.company, vquery) || + (applications?.get(it._id) ?? 0) > 0 + ) .map((it) => it._id) } } } + $: resultQuery = vquery === '' ? {} : { $search: vquery } + let applications: Map, number> | undefined const applicantQuery = createQuery() $: if (vacancies.length > 0) { + appQuery = true applicantQuery.query( recruit.class.Applicant, { ...(resultQuery as DocumentQuery), space: { $in: vacancies.map((it) => it._id) } }, @@ -69,6 +80,7 @@ } applications = result + appQuery = false } ) } @@ -86,7 +98,7 @@ { - updateResultQuery(search) + vquery = search }} />