juhaelee / hapi-massive Goto Github PK
View Code? Open in Web Editor NEWHapi plugin for massive 2.0
License: MIT License
Hapi plugin for massive 2.0
License: MIT License
Hello!
First of thanks for this awesomeness!
Sadly the documentation is lacking a bit and that makes me not knowing how to use it. I'm also very new to the concept of "promises" so this is what my question is about.
I'm trying to write a jsonapi which has to return the document up on creation. "this.db" is an instance created with this hapi-plugin. code is basically:
ResourceModel.prototype.addResource = function(newResource) {
const newDoc = {
fields: newResource.attributes.fields,
categories: newResource.attributes.categories
}
let test = this.db.saveDocAsync("resources",newDoc).then(function(doc){
//console.log(doc);
return doc;
});
return ??? //need to return doc here.
};
I can't figure out how to return the value of "doc" in my "addResource"-function. A console log of doc inside the function gives me exactly what i want. But HOW can i wait for this function to complete and then return the value of doc as the return-value from the whole function?
This would be a phenomenal package if I could figure out how to get it working.
I tried this...
let db = request.plugins["hapi-massive"].db;
...and the error tells me that request is undefined...So, if I try the same thing within the request handler, the error says...'Cannot ready property "db" of undefined'
I'm fairly new to plugins, especially custom plugins, and I feel like I'm missing something obvious.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.