2
0
mirror of https://github.com/frappe/books.git synced 2024-11-12 16:36:27 +00:00
books/frappe/rest.js
2018-01-01 17:48:55 +05:30

28 lines
838 B
JavaScript

const frappe = require('frappe-core');
module.exports = {
setup(app) {
// get list
app.get('/api/resource/:doctype', function(request, response) {
return response.json(frappe.db.get_all(request.params.doctype, ['name', 'subject'], null,
start = request.params.start || 0, limit = request.params.limit || 20));
});
// create
app.post('/api/resource/:doctype', function(request, response) {
data = request.body;
data.doctype = request.params.doctype;
let doc = frappe.get_doc(data).insert();
frappe.db.write();
return response.json(doc.get_valid_dict());
});
// get list
app.get('/api/resource/:doctype/:name', function(request, response) {
let data = frappe.get_doc(request.params.doctype, request.params.name).get_valid_dict();
console.log(data);
return response.json(data);
});
}
};