43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
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;
|