Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2017 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8e1d2cd9273161480a422bd7ded48cd7 to your computer and use it in GitHub Desktop.
Save anonymous/8e1d2cd9273161480a422bd7ded48cd7 to your computer and use it in GitHub Desktop.
import db from './../models';
const categoryController = {};
categoryController._cacheById = {};
categoryController._arrayCache = [];
categoryController.init = () =>{
return db.Category
.find({'isDeleted':false})
.then((categories) => {
categories.forEach((category) => {
category = category.toJSON();
categoryController._cacheById[category._id] = category;
});
categoryController._arrayCache = categories;
})
};
categoryController.getCategoryById = (id) =>{
console.log(categoryController._cacheById[id]);
return categoryController._cacheById[id];
};
import categoryController from './categoryController';
const imageController = {};
imageController._cacheById = {};
imageController._cache = {};
imageController.init = () =>{
return db.Image
.find({'isDeleted':false})
.then( images =>{
images.forEach( image =>{
image = image.toJSON();
image.categories = image.categories.map( id =>{
return categoryController.getCategoryById(id);
})
});
imageController._cache = images;
})
};
imageController.getAllImages = (req,res)=>{
res.json(imageController._cache);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment