-
-
Save anonymous/8e1d2cd9273161480a422bd7ded48cd7 to your computer and use it in GitHub Desktop.
This file contains 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
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]; | |
}; |
This file contains 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
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