-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mongo-datasource): should return record with empty flattened reco…
…rd (#1080)
- Loading branch information
Showing
13 changed files
with
297 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
packages/datasource-mongoose/src/utils/pipeline/as-model-not-null.ts
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
packages/datasource-mongoose/src/utils/pipeline/condition-generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { AnyExpression } from 'mongoose'; | ||
|
||
export const FOREST_RECORD_DOES_NOT_EXIST = 'FOREST_RECORD_DOES_NOT_EXIST'; | ||
export default class ConditionGenerator { | ||
/** | ||
* Tag a record if it does not exist | ||
* It will replace the record with a special object that can be used to filter out records | ||
*/ | ||
static tagRecordIfNotExist(field: string, then: AnyExpression): AnyExpression { | ||
return this.ifMissing(field, then, { FOREST_RECORD_DOES_NOT_EXIST: true }); | ||
} | ||
|
||
/** | ||
* Tag a record if it does not exist by value | ||
* It will replace the record with a special value that can be used to filter out records | ||
*/ | ||
static tagRecordIfNotExistByValue(field: string, then: AnyExpression): AnyExpression { | ||
return this.ifMissing(field, then, FOREST_RECORD_DOES_NOT_EXIST); | ||
} | ||
|
||
private static ifMissing( | ||
field: string, | ||
then: AnyExpression, | ||
elseResult: AnyExpression, | ||
): AnyExpression { | ||
return { | ||
$cond: { | ||
if: { $and: [{ $ne: [{ $type: `$${field}` }, 'missing'] }, { $ne: [`$${field}`, null] }] }, | ||
then, | ||
else: elseResult, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.