expressa 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/collections.js +6 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/util.js +3 -1
|
@@ -172,6 +172,7 @@ exports.replaceById = async function (req) {
|
|
|
172
172
|
oldDoc = await req.db[req.params.collection].get(req.params.id)
|
|
173
173
|
} catch (error) {
|
|
174
174
|
// happens when new documents are created via a PUT
|
|
175
|
+
// todo: use setDocumentOwner
|
|
175
176
|
oldDoc = { meta: { owner: req.user._id } }
|
|
176
177
|
}
|
|
177
178
|
const data = req.body
|
|
@@ -211,6 +212,11 @@ exports.updateById = async function (req) {
|
|
|
211
212
|
doc.meta.owner_collection = ownerCollection
|
|
212
213
|
}
|
|
213
214
|
}
|
|
215
|
+
if (doc._id) {
|
|
216
|
+
doc._id = doc._id.trim()
|
|
217
|
+
} else {
|
|
218
|
+
throw new util.ApiError(400, '_id property is required')
|
|
219
|
+
}
|
|
214
220
|
req.body = doc
|
|
215
221
|
await util.notify('put', req, req.params.collection, doc)
|
|
216
222
|
await req.db[req.params.collection].update(req.params.id, req.body)
|
package/index.js
CHANGED
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -338,7 +338,9 @@ exports.generateDocumentId = function generateDocumentId() {
|
|
|
338
338
|
|
|
339
339
|
exports.addIdIfMissing = function addIdIfMissing (document) {
|
|
340
340
|
if (!document._id) {
|
|
341
|
-
document._id = exports.generateDocumentId()
|
|
341
|
+
document._id = exports.generateDocumentId().trim()
|
|
342
|
+
} else {
|
|
343
|
+
document._id = document._id.trim()
|
|
342
344
|
}
|
|
343
345
|
}
|
|
344
346
|
|