Skip to content

Instantly share code, notes, and snippets.

@msfidelis
Last active January 3, 2018 14:48
Show Gist options
  • Save msfidelis/232f847210ff4986a4d81caac6231bd4 to your computer and use it in GitHub Desktop.
Save msfidelis/232f847210ff4986a4d81caac6231bd4 to your computer and use it in GitHub Desktop.
'use strict';
const ProductSchema = require('../models/Products');
const ProductService = {
createProduct : productValues => {
return new ProductSchema(productValues).save();
},
updateProduct : (id, productValues) => {
return ProductSchema.findByIdAndUpdate(id, {$set: productValues}, {new: true});
},
findProductById: id => {
return ProductSchema.findOne({_id: id});
},
searchProductsWithPagination : (query = {}, paginationOptions = {}) => {
return ProductSchema.paginate(query, paginationOptions);
},
deleteProductById : id => {
return ProductSchema.remove({_id: id});
}
}
module.exports = ProductService;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment