Supposing that I have a Post
schema, I want a method with this structure here:
function getPostDetails(post_id)
{
// The function searches the db for a document with that id,
// Finds it, and returns an object containing some of its details:
return {
title: post.title,
thumbnail: post.thumbnail,
views: post.views
// ....
};
}
It must have this form, I have a lot of async
, lambda, and nested functions and I don't want to make that code messier...
I did a lot of research but didn't find the way of doing it, maybe because I suck at handling promises and async code? yes!