mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 05:13:06 +00:00
Mixin projection fix (#2527)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
42e354f0ff
commit
a7da534e06
@ -105,6 +105,13 @@ export interface ReverseLookup {
|
|||||||
*/
|
*/
|
||||||
export type Lookup<T extends Doc> = Refs<T> | ReverseLookups | (Refs<T> & ReverseLookups)
|
export type Lookup<T extends Doc> = Refs<T> | ReverseLookups | (Refs<T> & ReverseLookups)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export type Projection<T extends Doc> = {
|
||||||
|
[P in keyof T]?: 0 | 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -113,9 +120,7 @@ export type FindOptions<T extends Doc> = {
|
|||||||
limit?: number
|
limit?: number
|
||||||
sort?: SortingQuery<T>
|
sort?: SortingQuery<T>
|
||||||
lookup?: Lookup<T>
|
lookup?: Lookup<T>
|
||||||
projection?: {
|
projection?: Projection<T>
|
||||||
[P in keyof T]?: 0 | 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@ import core, {
|
|||||||
Lookup,
|
Lookup,
|
||||||
Mixin,
|
Mixin,
|
||||||
ModelDb,
|
ModelDb,
|
||||||
|
Projection,
|
||||||
QueryUpdate,
|
QueryUpdate,
|
||||||
Ref,
|
Ref,
|
||||||
ReverseLookups,
|
ReverseLookups,
|
||||||
@ -349,7 +350,12 @@ abstract class MongoAdapterBase extends TxProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options?.projection !== undefined) {
|
if (options?.projection !== undefined) {
|
||||||
resultPipeline.push({ $project: options.projection })
|
const projection: Projection<T> = {}
|
||||||
|
for (const key in options.projection) {
|
||||||
|
const ckey = this.checkMixinKey<T>(key, clazz) as keyof T
|
||||||
|
projection[ckey] = options.projection[key]
|
||||||
|
}
|
||||||
|
resultPipeline.push({ $project: projection })
|
||||||
}
|
}
|
||||||
pipeline.push({
|
pipeline.push({
|
||||||
$facet: {
|
$facet: {
|
||||||
@ -438,7 +444,12 @@ abstract class MongoAdapterBase extends TxProcessor {
|
|||||||
let cursor = coll.find<T>(this.translateQuery(_class, query))
|
let cursor = coll.find<T>(this.translateQuery(_class, query))
|
||||||
|
|
||||||
if (options?.projection !== undefined) {
|
if (options?.projection !== undefined) {
|
||||||
cursor = cursor.project(options.projection)
|
const projection: Projection<T> = {}
|
||||||
|
for (const key in options.projection) {
|
||||||
|
const ckey = this.checkMixinKey<T>(key, _class) as keyof T
|
||||||
|
projection[ckey] = options.projection[key]
|
||||||
|
}
|
||||||
|
cursor = cursor.project(projection)
|
||||||
}
|
}
|
||||||
let total: number | undefined
|
let total: number | undefined
|
||||||
if (options !== null && options !== undefined) {
|
if (options !== null && options !== undefined) {
|
||||||
|
Loading…
Reference in New Issue
Block a user