var express = require('express')
var router = express.Router()
var Promise = require('bluebird')
var passport = require('passport')
var jwt = require('jwt-simple')
var db = require('../db')

db.createTables()

/* GET home page. */
router.get('/', function(req, res) {
  if (!req.user) return res.render('error', { message: 'Permission denied!', error: {status: 403}})
  res.render('../views/api');
});

router.get('/weapons', function(req, res) {
  db.getWeapons().then(function(weapons) {
    res.send(weapons.toJSON())
  }).catch(function(err) {
    res.send(err)
  })
})

router.post('/weapons', function(req, res) {
  db.createWeapons([
    {
      model: 'test 1 weapon',
      damage: 200.5
    },
    {
      model: 'test 2 weapon',
      damage: 500
    }
  ]).then(function(msg) {
    res.send(msg)
  }).catch(function(err) {
    res.send(err)
  })
})



router.get('/users', function(req, res) {
  db.getUsers().then(function(users) {
    res.send(users.toJSON())
  }).catch(function(err) {
    res.send(err)
  })
})

router.post('/users', function(req, res) {
  if (!req.body.password)
    return res.status(500).send('Password missing.')
  if (!req.body.email)
    return res.status(500).send('Email address missing')

  db.createUser({
    local_email: req.body.email,
    local_password: req.body.password
  }).then(function() {
    res.status(200).send()
  }).catch(function(err) {
    res.send(err)
  })
})

module.exports = router;
@@ -187,25 +187,491 @@
 b')%0A
-%0Adb.createTables(
+var User = require('../models/User')%0A%0Adb.createTables()%0A%0Avar dummyUsers = %5B%0A  %7B%0A    local_email: 'admin',%0A    local_password: 'no password'%0A  %7D,%0A  %7B%0A    local_email: 'orange.tree@garden.com',%0A    local_password: 'Test3test'%0A  %7D,%0A  %7B%0A    local_email: 'user',%0A    local_password: 'user'%0A  %7D%0A%5D%0Anew User(%7B local_email: dummyUsers%5B0%5D.local_email %7D)%0A  .fetch()%0A  .then(function(user) %7B%0A    if (!user)%0A      db.createUsers(dummyUsers) // create dummy users if we don't already have them%0A  %7D
 )%0A%0A/

Create dummy users.