Created
January 2, 2018 15:25
-
-
Save msfidelis/177513a6d1c62520082ee83f1fbe1fca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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