FindOne Fix (#847)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-01-21 15:05:26 +06:00 committed by GitHub
parent 626ece4045
commit ea19fe2bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -84,7 +84,7 @@ class ClientImpl implements Client {
query: DocumentQuery<T>,
options?: FindOptions<T>
): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options))[0]
return (await this.findAll(_class, query, { ...options, limit: 1 }))[0]
}
async tx (tx: Tx): Promise<TxResult> {

View File

@ -35,8 +35,8 @@ export class TxOperations implements Omit<Client, 'notify'> {
return this.client.findAll(_class, query, options)
}
async findOne <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options))[0]
findOne <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<WithLookup<T> | undefined> {
return this.client.findOne(_class, query, options)
}
tx (tx: Tx): Promise<TxResult> {

View File

@ -109,7 +109,7 @@ export class LiveQuery extends TxProcessor implements Client {
query: DocumentQuery<T>,
options?: FindOptions<T>
): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options))[0]
return await this.client.findOne(_class, query, options)
}
query<T extends Doc>(
@ -285,7 +285,7 @@ export class LiveQuery extends TxProcessor implements Client {
for (const key in lookup) {
const _class = (lookup as any)[key] as Ref<Class<Doc>>
const _id = (doc as any)[key] as Ref<Doc>
;(result as any)[key] = (await this.client.findAll(_class, { _id }))[0]
;(result as any)[key] = await this.client.findOne(_class, { _id })
}
;(doc as WithLookup<Doc>).$lookup = result
}

View File

@ -56,7 +56,7 @@
onDestroy(
location.subscribe(async (loc) => {
currentApp = loc.path[1] as Ref<Application>
currentApplication = (await client.findAll(workbench.class.Application, { _id: currentApp }))[0]
currentApplication = await client.findOne(workbench.class.Application, { _id: currentApp })
navigatorModel = currentApplication?.navigatorModel
const currentFolder = loc.path[2] as Ref<Space>
ownSpecialComponent = getOwnSpecialComponent(currentFolder)
@ -71,7 +71,7 @@
return
}
const space = (await client.findAll(core.class.Space, { _id: currentFolder }))[0]
const space = await client.findOne(core.class.Space, { _id: currentFolder })
currentSpace = currentFolder
if (space) {
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]