Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-03-04 21:42:02 +07:00 committed by GitHub
parent f5682c1f73
commit ab4cea6ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 13 deletions

View File

@ -144,8 +144,20 @@ export async function createClient (
const txMap = new Map<Ref<Tx>, Ref<Tx>>()
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)

View File

@ -364,7 +364,7 @@ export class Hierarchy {
const _cl = getClass(v as ToClassRefT<T, keyof T>)
if (this.isMixin(_cl)) {
const mval = (lookup as any)[k]
if (mval !== undefined) {
if (mval != null) {
(lookup as any)[k] = this.as(mval, _cl)
}
}

View File

@ -30,34 +30,45 @@
}
let search: string = ''
let vquery: string = ''
let resultQuery: DocumentQuery<Doc> = {}
let vacancyQuery: DocumentQuery<Doc> = {}
async function updateResultQuery (search: string): Promise<void> {
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<Ref<Vacancy>, number> | undefined
const applicantQuery = createQuery()
$: if (vacancies.length > 0) {
appQuery = true
applicantQuery.query(
recruit.class.Applicant,
{ ...(resultQuery as DocumentQuery<Applicant>), space: { $in: vacancies.map((it) => it._id) } },
@ -69,6 +80,7 @@
}
applications = result
appQuery = false
}
)
}
@ -86,7 +98,7 @@
<SearchEdit
bind:value={search}
on:change={() => {
updateResultQuery(search)
vquery = search
}}
/>
<Button label={recruit.string.Create} primary={true} size={'small'} on:click={(ev) => showCreateDialog(ev)} />

View File

@ -314,12 +314,20 @@ export async function createServerStorage (conf: DbConfiguration, options?: Serv
const model = await txAdapter.getModel()
for (const tx of model) {
try {
hierarchy.tx(tx)
await triggers.tx(tx)
} catch (err: any) {
console.error('failed to apply model transaction, skipping', JSON.stringify(tx), err)
}
}
for (const tx of model) {
try {
await modelDb.tx(tx)
} catch (err: any) {
console.error('failed to apply model transaction, skipping', JSON.stringify(tx), err)
}
}
for (const [, adapter] of adapters) {