Skip to content

Instantly share code, notes, and snippets.

@msfidelis
Created January 6, 2018 16:00
Show Gist options
  • Save msfidelis/ddaec0abd9ba6bd70f3d60f9ce184cc3 to your computer and use it in GitHub Desktop.
Save msfidelis/ddaec0abd9ba6bd70f3d60f9ce184cc3 to your computer and use it in GitHub Desktop.
'use strict';
const Joi = require('joi');
const Boom = require('boom');
const hash = require('take-my-hash');
const cache = require('../configs/cache');
const ProductService = require('../services/products');
module.exports = [
{
method: "DELETE",
path: "/products/{id}",
handler: (req, res) => {
//Remove o produto informado pelo id
ProductService
.deleteProductById(req.params.id)
.then(product => {
const productHash = hash.sha1('products' + req.params.id);
cache.del(productHash);
res(product).code(204);
}).catch(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