mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-12 19:30:52 +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)
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type Projection<T extends Doc> = {
|
||||
[P in keyof T]?: 0 | 1
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@ -113,9 +120,7 @@ export type FindOptions<T extends Doc> = {
|
||||
limit?: number
|
||||
sort?: SortingQuery<T>
|
||||
lookup?: Lookup<T>
|
||||
projection?: {
|
||||
[P in keyof T]?: 0 | 1
|
||||
}
|
||||
projection?: Projection<T>
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ import core, {
|
||||
Lookup,
|
||||
Mixin,
|
||||
ModelDb,
|
||||
Projection,
|
||||
QueryUpdate,
|
||||
Ref,
|
||||
ReverseLookups,
|
||||
@ -349,7 +350,12 @@ abstract class MongoAdapterBase extends TxProcessor {
|
||||
}
|
||||
}
|
||||
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({
|
||||
$facet: {
|
||||
@ -438,7 +444,12 @@ abstract class MongoAdapterBase extends TxProcessor {
|
||||
let cursor = coll.find<T>(this.translateQuery(_class, query))
|
||||
|
||||
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
|
||||
if (options !== null && options !== undefined) {
|
||||
|
Loading…
Reference in New Issue
Block a user