Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const url = require('url')
const lowdb = require('lowdb')
const lodashId = require('lodash-id')
const dataIndex = 'data';

/**
* Module exports.
Expand Down Expand Up @@ -123,7 +124,7 @@ function lowdbApi(file, options = {}) {
throw new Error(`path not supported: ${pathname}`)
}

const updated = update(db, collection, parsedId, req.body)
const updated = update(db, collection, parsedId, { [dataIndex] : req.body })
return res.status(200).send(updated)

case 'DELETE':
Expand Down Expand Up @@ -160,9 +161,8 @@ function insert(db, key, data) {
db.defaults({ [key]: [] }).write()
const lastInserted = db.get(key).maxBy('id').value()
const nextId = lastInserted ? lastInserted.id + 1 : 1
data.id = nextId
db.get(key).push(data).write()
return data
db.get(key).push({ 'id' : nextId, [dataIndex] : data }).write()
return { 'id': nextId, [dataIndex]: data };
}

function update(db, key, id, partial) {
Expand Down
Loading