add api class
This commit is contained in:
parent
9f3c553740
commit
6b0a3d9fa9
3 changed files with 49 additions and 9 deletions
42
frontend/src/api.js
Normal file
42
frontend/src/api.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
class Api {
|
||||
static async getAddresses(fields = []) {
|
||||
const addressNames = await frappe.db.get_list("Address", { fields });
|
||||
console.log("DEBUG: API - Fetched Address list: ", addressNames);
|
||||
return addressNames;
|
||||
}
|
||||
|
||||
static async getDetailedAddress(name) {
|
||||
const address = await frappe.db.get_doc("Address", name);
|
||||
console.log("DEBUG: API - Fetched Detailed Address: ", address);
|
||||
return address;
|
||||
}
|
||||
|
||||
static async getCustomerList(fields = []) {
|
||||
const customers = await frappe.db.get_list("Customer", { fields });
|
||||
console.log("DEBUG: API - Fetched Customer list: ", customers);
|
||||
return customers;
|
||||
}
|
||||
|
||||
static async getDetailedCustomer(name) {
|
||||
const customer = await frappe.db.get_doc("Customer", name);
|
||||
console.log("DEBUG: API - Fetched Detailed Customer: ", customer);
|
||||
return customer;
|
||||
}
|
||||
|
||||
static async getClientDetails() {
|
||||
const data = [];
|
||||
const addresses = await this.getAddresses();
|
||||
for (const addr of addresses) {
|
||||
const clientDetail = {};
|
||||
const fullAddress = await this.getDetailedAddress(addr["name"] || addr["Name"]);
|
||||
const customer = await this.getDetailedCustomer(fullAddress["links"][0]["link_name"]);
|
||||
clientDetail.customer = customer;
|
||||
clientDetail.address = fullAddress;
|
||||
data.push(clientDetail);
|
||||
}
|
||||
console.log("DEBUG: API - Fetched Client Details: ", data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export default Api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue