Skip to content

Instantly share code, notes, and snippets.

@esslamben
Created January 16, 2018 21:23
Show Gist options
  • Save esslamben/65174f2f935f1d25f580f4a1894db8d3 to your computer and use it in GitHub Desktop.
Save esslamben/65174f2f935f1d25f580f4a1894db8d3 to your computer and use it in GitHub Desktop.
Test
const mongoose = require('mongoose');
const Compressor = mongoose.model('compressor');
module.exports = app => {
const uri = '/api/compressor';
// Gets all compressors
app.get(uri, async (req, res) => {
const compressors = await Compressor.find();
res.send(compressors);
});
// Post compressor
app.post(uri, async (req, res) => {
const details = req.body;
const compressor = new Compressor({
name: 'test123'
});
try {
await compressor.save();
res.send('Compressor Created!');
} catch (err) {
res.status(422).send(err);
}
});
// Delete compressor
app.get(`${uri}/:id`, async (req, res) => {
res.send(req.params.id);
try {
Compressor.findByIdAndRemove(req.params.id);
res.send('Compressor Deleted!');
} catch (err) {
res.status(422).send(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment