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.
@@ -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
@@ -114,6 +114,7 @@ module.exports.api = function (settings) {
114
114
  return util.getPgPool(router.settings.postgresql_uri)
115
115
  },
116
116
  doLogin: auth.doLogin,
117
+ createHash: auth.createHash,
117
118
  ...util,
118
119
  }
119
120
  router.eventListeners = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expressa",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "API framework using JSON schemas",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/thomas4019/expressa",
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