File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change
1
+ import ObjectIdImport from 'bson-objectid'
2
+ import { isValidObjectId } from 'mongoose'
1
3
import {
2
4
buildVersionCollectionFields ,
3
5
type CreateVersion ,
@@ -10,6 +12,8 @@ import type { MongooseAdapter } from './index.js'
10
12
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'
11
13
import { withSession } from './withSession.js'
12
14
15
+ const ObjectId = ( ObjectIdImport . default ||
16
+ ObjectIdImport ) as unknown as typeof ObjectIdImport . default
13
17
export const createVersion : CreateVersion = async function createVersion (
14
18
this : MongooseAdapter ,
15
19
{
@@ -47,6 +51,23 @@ export const createVersion: CreateVersion = async function createVersion(
47
51
48
52
const [ doc ] = await VersionModel . create ( [ data ] , options , req )
49
53
54
+ const parentQuery = {
55
+ $or : [
56
+ {
57
+ parent : {
58
+ $eq : data . parent ,
59
+ } ,
60
+ } ,
61
+ ] ,
62
+ }
63
+ if ( typeof data . parent === 'string' && isValidObjectId ( data . parent ) ) {
64
+ parentQuery . $or . push ( {
65
+ parent : {
66
+ $eq : ObjectId ( data . parent ) ,
67
+ } ,
68
+ } )
69
+ }
70
+
50
71
await VersionModel . updateMany (
51
72
{
52
73
$and : [
@@ -55,11 +76,7 @@ export const createVersion: CreateVersion = async function createVersion(
55
76
$ne : doc . _id ,
56
77
} ,
57
78
} ,
58
- {
59
- parent : {
60
- $eq : data . parent ,
61
- } ,
62
- } ,
79
+ parentQuery ,
63
80
{
64
81
latest : {
65
82
$eq : true ,
You can’t perform that action at this time.
0 commit comments