mirror of
https://github.com/frappe/books.git
synced 2025-02-02 12:08:27 +00:00
frappe.call
This commit is contained in:
parent
fa049a37a1
commit
4d9b9ecd5b
@ -66,7 +66,7 @@ module.exports = class ReportPage extends Page {
|
||||
const filterValues = this.getFilterValues();
|
||||
if (filterValues === false) return;
|
||||
|
||||
let data = await frappe.call({method: this.method, args: filterValues});
|
||||
let data = await frappe.call(this.method, filterValues);
|
||||
this.datatable.refresh(data);
|
||||
}
|
||||
|
||||
|
@ -29,23 +29,16 @@ module.exports = {
|
||||
},
|
||||
|
||||
setCall() {
|
||||
frappe.call = async ({method, type='get', args}) => {
|
||||
frappe.call = async (method, args) => {
|
||||
let url = `/api/method/${method}`;
|
||||
let request = {};
|
||||
|
||||
if (args) {
|
||||
if (type.toLowerCase()==='get') {
|
||||
url += '?' + frappe.getQueryString(args);
|
||||
} else {
|
||||
// POST / PUT / DELETE
|
||||
request.body = JSON.stringify(args);
|
||||
}
|
||||
}
|
||||
|
||||
request.headers = { 'Accept': 'application/json' };
|
||||
request.method = type.toUpperCase();
|
||||
|
||||
let response = await fetch(url, request);
|
||||
let response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(args || {})
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
13
index.js
13
index.js
@ -47,19 +47,12 @@ module.exports = {
|
||||
this.views[view][name] = module;
|
||||
},
|
||||
|
||||
registerMethod({method, type, handler}) {
|
||||
type = type.toLowerCase();
|
||||
registerMethod({method, handler}) {
|
||||
this.methods[method] = handler;
|
||||
if (this.app) {
|
||||
// add to router if client-server
|
||||
this.app[type](`/api/method/${method}`, this.asyncHandler(async function(request, response) {
|
||||
let args = {};
|
||||
if (type==='get') {
|
||||
args = request.query;
|
||||
} else {
|
||||
args = request.body;
|
||||
}
|
||||
const data = await handler(args);
|
||||
this.app.post(`/api/method/${method}`, this.asyncHandler(async function(request, response) {
|
||||
const data = await handler(request.body);
|
||||
response.json(data);
|
||||
}));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user