You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
var express = require('express');
|
|
var controller = express.Router();
|
|
var Run = require('../models/runs.js');
|
|
|
|
controller.get('/', function(req, res){
|
|
Run.findAll({}).then(function(foundRuns){
|
|
//createdRun is the object representation of the row created in the DB
|
|
res.json(foundRuns);
|
|
});
|
|
});
|
|
|
|
controller.get('/:id', function(req, res){
|
|
// Run.findOne({
|
|
// where:{
|
|
// id:req.params.id
|
|
// }
|
|
Run.findById(req.params.id).then(function(foundRuns){
|
|
res.json(foundRuns);
|
|
});
|
|
});
|
|
|
|
controller.post('/', function(req, res){
|
|
Run.create(req.body).then(function(createdRun){
|
|
//createdRun is the object representation of the row created in the DB
|
|
res.json(createdRun);
|
|
});
|
|
});
|
|
|
|
controller.put('/:id', function(req, res){
|
|
runs[req.params.id] = req.body;
|
|
res.json(runs);
|
|
});
|
|
|
|
controller.delete('/:id', function(req, res){
|
|
Run.destroy({ //destroy the run as specified by id in the url
|
|
where: {
|
|
id: req.params.id //only delete rows that have the column id set to 1
|
|
}
|
|
}).then(function(didSucceed){
|
|
res.json(didSucceed); //send back if it succeeded
|
|
});
|
|
});
|
|
|
|
module.exports = controller;
|