@@ -22,14 +22,12 @@ const bulkCreate = async function (req, res, next) {
2222 if ( ! Array . isArray ( documents ) ) {
2323 err . message = "The request body must be an array of objects."
2424 err . status = 400
25- next ( utils . createExpressError ( err ) )
26- return
25+ return next ( utils . createExpressError ( err ) )
2726 }
2827 if ( documents . length === 0 ) {
2928 err . message = "No action on an empty array."
3029 err . status = 400
31- next ( utils . createExpressError ( err ) )
32- return
30+ return next ( utils . createExpressError ( err ) )
3331 }
3432 const gatekeep = documents . filter ( d => {
3533 // Each item must be valid JSON, but can't be an array.
@@ -42,12 +40,11 @@ const bulkCreate = async function (req, res, next) {
4240 // Items must not have an @id , and in some cases same for id.
4341 const idcheck = _contextid ( d [ "@context" ] ) ? ( d . id ?? d [ "@id" ] ) : d [ "@id" ]
4442 if ( idcheck ) return d
45- } )
43+ } )
4644 if ( gatekeep . length > 0 ) {
4745 err . message = "All objects in the body of a `/bulkCreate` must be JSON and must not contain a declared identifier property."
4846 err . status = 400
49- next ( utils . createExpressError ( err ) )
50- return
47+ return next ( utils . createExpressError ( err ) )
5148 }
5249
5350 // TODO: bulkWrite SLUGS? Maybe assign an id to each document and then use that to create the slug?
@@ -66,6 +63,7 @@ const bulkCreate = async function (req, res, next) {
6663 // unordered bulkWrite() operations have better performance metrics.
6764 let bulkOps = [ ]
6865 const generatorAgent = getAgentClaim ( req , next )
66+ if ( ! generatorAgent ) return
6967 for ( let d of documents ) {
7068 // Do not create empty {}s
7169 if ( Object . keys ( d ) . length === 0 ) continue
@@ -92,7 +90,7 @@ const bulkCreate = async function (req, res, next) {
9290 }
9391 catch ( error ) {
9492 //MongoServerError from the client has the following properties: index, code, keyPattern, keyValue
95- next ( utils . createExpressError ( error ) )
93+ return next ( utils . createExpressError ( error ) )
9694 }
9795}
9896
@@ -111,14 +109,12 @@ const bulkUpdate = async function (req, res, next) {
111109 if ( ! Array . isArray ( documents ) ) {
112110 err . message = "The request body must be an array of objects."
113111 err . status = 400
114- next ( utils . createExpressError ( err ) )
115- return
112+ return next ( utils . createExpressError ( err ) )
116113 }
117114 if ( documents . length === 0 ) {
118115 err . message = "No action on an empty array."
119116 err . status = 400
120- next ( utils . createExpressError ( err ) )
121- return
117+ return next ( utils . createExpressError ( err ) )
122118 }
123119 const gatekeep = documents . filter ( d => {
124120 // Each item must be valid JSON, but can't be an array.
@@ -136,12 +132,12 @@ const bulkUpdate = async function (req, res, next) {
136132 if ( gatekeep . length > 0 ) {
137133 err . message = "All objects in the body of a `/bulkUpdate` must be JSON and must contain a declared identifier property."
138134 err . status = 400
139- next ( utils . createExpressError ( err ) )
140- return
135+ return next ( utils . createExpressError ( err ) )
141136 }
142137 // unordered bulkWrite() operations have better performance metrics.
143138 let bulkOps = [ ]
144139 const generatorAgent = getAgentClaim ( req , next )
140+ if ( ! generatorAgent ) return
145141 for ( const objectReceived of documents ) {
146142 // We know it has an id
147143 const idReceived = objectReceived [ "@id" ] ?? objectReceived . id
@@ -154,8 +150,7 @@ const bulkUpdate = async function (req, res, next) {
154150 try {
155151 originalObject = await db . findOne ( { "$or" :[ { "_id" : id } , { "__rerum.slug" : id } ] } )
156152 } catch ( error ) {
157- next ( utils . createExpressError ( error ) )
158- return
153+ return next ( utils . createExpressError ( error ) )
159154 }
160155 if ( null === originalObject ) continue
161156 if ( utils . isDeleted ( originalObject ) ) continue
@@ -196,7 +191,7 @@ const bulkUpdate = async function (req, res, next) {
196191 }
197192 catch ( error ) {
198193 //MongoServerError from the client has the following properties: index, code, keyPattern, keyValue
199- next ( utils . createExpressError ( error ) )
194+ return next ( utils . createExpressError ( error ) )
200195 }
201196}
202197
0 commit comments