File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,10 +224,13 @@ async function getAllVersions(obj) {
224224 let rootObj
225225 if ( primeID === "root" ) {
226226 rootObj = JSON . parse ( JSON . stringify ( obj ) )
227- } else {
227+ } else if ( primeID ) {
228228 //Use _id for indexed query performance instead of @id
229229 const primeHexId = parseDocumentID ( primeID )
230230 rootObj = await db . findOne ( { "$or" :[ { "_id" : primeHexId } , { "__rerum.slug" : primeHexId } ] } )
231+ } else {
232+ //primeID is undefined or null, cannot proceed
233+ throw new Error ( "Object has no valid history.prime value" )
231234 }
232235 ls_versions = await db . find ( { "__rerum.history.prime" : rootObj [ '@id' ] } ) . toArray ( )
233236 ls_versions . unshift ( rootObj )
Original file line number Diff line number Diff line change @@ -202,11 +202,14 @@ async function getAllVersions(obj) {
202202 if ( primeID === "root" ) {
203203 //The obj passed in is root. So it is the rootObj we need.
204204 rootObj = JSON . parse ( JSON . stringify ( obj ) )
205- } else {
205+ } else if ( primeID ) {
206206 //The obj passed in knows the ID of root, grab it from Mongo
207207 //Use _id for indexed query performance instead of @id
208208 const primeHexId = parseDocumentID ( primeID )
209209 rootObj = await db . findOne ( { "$or" :[ { "_id" : primeHexId } , { "__rerum.slug" : primeHexId } ] } )
210+ } else {
211+ //primeID is undefined or null, cannot proceed
212+ throw new Error ( "Object has no valid history.prime value" )
210213 }
211214 //All the children of this object will have its @id in __rerum.history.prime
212215 ls_versions = await db . find ( { "__rerum.history.prime" : rootObj [ '@id' ] } ) . toArray ( )
You can’t perform that action at this time.
0 commit comments