pofider / node-simple-odata-server

Simple OData server for node.js
MIT License
97 stars 61 forks source link

Hook samples #34

Closed carrbrpoa closed 6 years ago

carrbrpoa commented 6 years ago

Hello,

Could you please provide some hook samples? Let's say I have an Express endpoint and before inserting in an specific set, I wish to do something and then proceed with the default behavior.

What I tried:

var model = {
    namespace: "testes",
    entityTypes: {
        "Document": {
            "_id": {
                "type": "Edm.String",
                key: true
            },
            "tipo": {
                "type": "Edm.Int32"
            }
        }
    },
    entitySets: {
        "documents": {
            entityType: "testes.Document"
        }
    }
};

odataServer.beforeInsert((setName, doc, req, cb) => {
    if (setName == 'documents') {
        console.log('test!');
    }
});

app.use("/odata", function (req, res) {
    odataServer.handle(req, res);
});
...

I see test logged in console but there is no response anymore. What should I do next?

Thanks

pofider commented 6 years ago
odataServer.beforeInsert((setName, doc, req, cb) => {
    if (setName == 'documents') {
        console.log('test!');
    }

       // you need to call cb to notify the async hook has finished
       cb()
});