var express = require('express');
var bodyParser = require('body-parser');
var Database = require('./db');
var db = new Database();

var app = express();
app.use(bodyParser.json());

app.get('/api/:user_id', function (req, res) {
    var payload = {user: req.params.user_id};
    db.find(payload, function(results){
        return res.json(results);
    });
});

app.post('/api/:user_id', function (req, res) {
    var payload = {user: req.params.user_id};
    var data = {user: req.params.user_id, led: true};
    if (req.body.led === true) {
        data.led = true;
    }

    db.find(payload, function(results){
        if(results.length>0){
            db.update(data);
            res.send({db: "update"});
        } else {
            db.insert(data);
            res.send({db: "insert"});
        }
    });
});

app.put('/api/:user_id', function (req, res) {
    var payload = {user: req.params.user_id};
    var data = {user: req.params.user_id, led: true};
    if (req.body.led === true) {
        data.led = true;
    }

    db.find(payload, function(results){
        if(results.length>0){
            db.update(data);
            res.send({db: "update"});
        } else {
            db.insert(data);
            res.send({db: "insert"});
        }
    });
});

app.delete('/api', function (req, res) {
    data.method = 'delete';
    data = {};
    res.send(data);
});

app.listen(3000);
@@ -1285,16 +1285,25 @@
 te('/api
+/:user_id
 ', funct
@@ -1323,51 +1323,8 @@
 ) %7B%0A
-    data.method = 'delete';%0A    data = %7B%7D;%0A
     
@@ -1332,20 +1332,18 @@
 es.send(
-data
+%7B%7D
 );%0A%7D);%0A%0A

update delete method