Here is how to use it, module index.js:
const Zinko = require('zinko');
class Crud extends Zinko {
get useZongel() { return true; }
async POST_root(req, res) {
await this.model.insertOne({ name: 'rruk', age: 'r' })
return "ok"
}
async GET_root(req, res) {
let j = await this.model.findOne({ name: 'rruk' });
return j
}
async PUT_root(req, res) {
let j = await this.model.updateOne({ name: 'rruk' }, { $set: { age: 1 } });
console.log(j.ops)
return 'ok'
}
}
module.exports = Crud;
And model.js in the same folder:
const Zongel = require("zongel");
class Model extends Zongel {
get collectionName() { return "crud" }
get schema() {
return {
properties: {
name: { type: "string" },
age: { type: "integer" }
},
required: ["name"],
private: ["age"]
}
}
}
module.exports = Model;