Skip to content

Instantly share code, notes, and snippets.

@msfidelis
Created January 2, 2018 15:25
Show Gist options
  • Save msfidelis/177513a6d1c62520082ee83f1fbe1fca to your computer and use it in GitHub Desktop.
Save msfidelis/177513a6d1c62520082ee83f1fbe1fca to your computer and use it in GitHub Desktop.
'use strict';
const ProductSchema = require('../models/Products');
const Joi = require('joi');
const Boom = require('boom');
const hash = require('take-my-hash');
const cache = require('../configs/cache');
module.exports = [
{
method: "DELETE",
path: "/products/{id}",
handler: (req, res) => {
// Deleta o Item do Banco de dados
ProductSchema.remove({ "_id": req.params.id })
.then(product => {
const productHash = hash.sha1('products' + req.params.id);
// Deleta o item do cache caso exista
cache.del(productHash);
res(product).code(204);
})
.catch(err => {
console.log(err);
res(Boom.internal(err));
});
},
config: {
validate: {
params: {
id: Joi.string().required().min(20)
}
}
}
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment