This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/#582-unit-visibility-toggle-2
- Loading branch information
Showing
36 changed files
with
631 additions
and
287 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Tries to extract the id from a mongoose object. | ||
* This could be a node-mongodb-native ObjectID (i.e. mongoose.Types.ObjectId), via toHexString, | ||
* or anything that contains an 'id' property, which is directly returned. | ||
* | ||
* @param from A mongoose object. | ||
* @param fallback Return this if no id is found. | ||
*/ | ||
function extractMongoIdImpl(from: any, fallback?: any) { | ||
if (from instanceof Object) { | ||
if (from._bsontype === 'ObjectID') { | ||
return from.toString(); | ||
} else if ('id' in from) { | ||
return from.id; | ||
} | ||
} | ||
return fallback; | ||
} | ||
|
||
/** | ||
* Tries to extract the id from a mongoose object or array of such. | ||
* This could be a node-mongodb-native ObjectID (i.e. mongoose.Types.ObjectId), via toHexString, | ||
* or anything that contains an 'id' property, which is directly returned. | ||
* For arrays, anything === undefined won't be pushed. | ||
* | ||
* @param from A mongoose object or array of such. | ||
* @param fallback Return this if no id is found. | ||
*/ | ||
export function extractMongoId(from: any | any[], fallback?: any) { | ||
if (Array.isArray(from)) { | ||
const results: any[] = []; | ||
for (const value of from) { | ||
const result = extractMongoIdImpl(value, fallback); | ||
if (result !== undefined) { | ||
results.push(result); | ||
} | ||
} | ||
return results; | ||
} else { | ||
return extractMongoIdImpl(from, fallback); | ||
} | ||
} |
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.