stjohnjohnson / smartthings-mqtt-bridge

Bridge between SmartThings and MQTT
https://hub.docker.com/r/stjohnjohnson/smartthings-mqtt-bridge/
MIT License
368 stars 243 forks source link

Type Error : Parameter must be string not undefined??? #134

Open samwebber11 opened 6 years ago

samwebber11 commented 6 years ago
var lodash=require('lodash');
var express=require('express');
var bodyparser=require('body-parser');
console.log('I m stunt');
var mongoose1=require('mongoose');
var {app1}=require('./todos');
var {ObjectId}=require('mongodb');
var {authenticate}=require('./middleware');
mongoose1.Promise=global.Promise;
mongoose1.connect(process.env.MONGODB_URI);
var port=process.env.PORT || 3000;
var app=express();
app.use(bodyparser.json());
console.log("plz let me start");
app.post('/todos',(req,res)=>
{
var todo=new app1({
    text:req.body.text,
    email:req.body.email
});
todo.save().then((docs)=>
{
    res.send(docs);
},(err)=>
{

    res.status(400).send(err);
});
    });
    console.log('Plz start up');

    app.get('/todos',(req,res)=>
   {
app1.find().then((todos)=>{
    res.send({
        todos
    })
},(err)=>
{
    res.status(400).send(err);
});
     });

    app.get('/todos/:id',(req,res)=>
    {
var id=req.params.id;
if(!ObjectId.isValid(id))
{  var text1='No id is found';
    res.status(404).send({text1});
}

    app1.findById(id).then((todos)=>
    {
        if(todos)
        {
            res.send(todos);
        }
        else
        {
            res.status(404).send();
        }
    },(err)=>
    {
        res.status(400).send(err);
    });
       });
        app.patch('/todos/:id',(req,res)=>
    {
var id=req.params.id;
var body=lodash.pick(req.body,['text','completed']);
if(!ObjectId.isValid(id))
{
    var text1="no id is found";
    return res.status(404).send({text1});
}
if(lodash.isBoolean(body.completed) && (body.completed))
{
 body.completedBy=new Date().getTime();
}
else
{
    body.completed=false;
    body.completedBy=null;
}

app1.findByIdAndUpdate(id,{$set:body},{new:true}).then((todos)=>
{
    if(todos)
    {
        return res.send(todos);
    }
    else
    {
        res.status(404).send();
    }
},(err)=>
{
    res.status(400).send(err);
});
     });

    app.delete('/todos/:id',(req,res)=>
   {
var id=req.params.id;
if(!ObjectId.isValid(id))
{
    var text1='No id is found';
    return res.status(404).send({text1});
}
app1.findByIdAndRemove(id).then((todos)=>
{
    if(todos)
    {
        return res.send(todos);
    }
    else
    {
        res.status(404).send();
    }
},(err)=>
{
    res.status(400).send(err);
});
}
    );
   app.post('/todos1',(req,res)=>
    {
console.log('I m Starting now');
var body=lodash.pick(req.body,['email','password','text']);
console.log('Why nt working');
var user=new app1(body);
console.log(user);
user.save().then((user)=>
{
    console.log('what is the problem dude');
    return user.generateAuthToken();
    }).then((token)=>
    {
        console.log('Why not heading up');
        console.log(token);
        res.header('x-auth',token).send(user);
    }).catch((e)=>
    {
        console.log(e);
        res.status(400).send(e);
    });
    console.log('I m finished');
        });

       app.get('/todos1/me',authenticate,(req,res)=>
     {
res.send(req.user);

      });

      app.listen(port,()=>
     {
console.log(`Starting port ${port}`);
     });

     module.exports={app};`](url)
stjohnjohnson commented 6 years ago

I'm sorry. What is this?

samwebber11 commented 6 years ago

i m getting error when i m processing post request that is it not sending data back to my database where as the data is correct