2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 19:09:01 +00:00

rest_api: /api/resource/doctype/name/fieldname

This commit is contained in:
Rushabh Mehta 2018-01-23 18:48:37 +05:30
parent 920767717b
commit 1e9701d0be
2 changed files with 15 additions and 0 deletions

View File

@ -89,6 +89,15 @@ module.exports = class RESTClient {
.join('&');
}
async get_value(doctype, name, fieldname) {
let url = this.protocol + '://' + path.join(this.server, `/api/resource/${frappe.slug(doctype)}/${name}/${fieldname}`);
let response = await frappe.fetch(url, {
method: 'GET',
headers: this.json_headers
});
return (await response.json()).value;
}
init_type_map() {
this.type_map = {
'Currency': true

View File

@ -51,6 +51,12 @@ module.exports = {
return response.json(doc.get_valid_dict());
}));
// get value
app.get('/api/resource/:doctype/:name/:fieldname', frappe.async_handler(async function(request, response) {
let value = await frappe.db.get_value(request.params.doctype, request.params.name, request.params.fieldname);
return response.json({value: value});
}));
// delete
app.delete('/api/resource/:doctype/:name', frappe.async_handler(async function(request, response) {
let doc = await frappe.get_doc(request.params.doctype, request.params.name)