add notifiaction handling, error handling

This commit is contained in:
Casey 2025-11-12 15:13:49 -06:00
parent ce708f5209
commit 1af288aa62
21 changed files with 4864 additions and 224 deletions

View file

@ -3,12 +3,14 @@ import ApiUtils from "./apiUtils";
const ZIPPOPOTAMUS_BASE_URL = "https://api.zippopotam.us/us";
const FRAPPE_PROXY_METHOD = "custom_ui.api.proxy.request";
const FRAPPE_UPSERT_ESTIMATE_METHOD = "custom_ui.api.db.estimates.upsert_estimate";
const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.get_jobs";
const FRAPPE_UPSERT_JOB_METHOD = "custom_ui.api.db.jobs.upsert_job";
const FRAPPE_UPSERT_INVOICE_METHOD = "custom_ui.api.db.invoices.upsert_invoice";
const FRAPPE_UPSERT_CLIENT_METHOD = "custom_ui.api.db.clients.upsert_client";
const FRAPPE_GET_CLIENT_STATUS_COUNTS_METHOD = "custom_ui.api.db.clients.get_client_status_counts";
const FRAPPE_GET_CLIENT_TABLE_DATA_METHOD = "custom_ui.api.db.clients.get_clients_table_data";
const FRAPPE_GET_CLIENT_METHOD = "custom_ui.api.db.clients.get_client";
const FRAPPE_GET_CLIENT_NAMES_METHOD = "custom_ui.api.db.clients.get_client_names";
class Api {
static async request(frappeMethod, args = {}) {
@ -19,10 +21,12 @@ class Api {
let response = await frappe.call(request);
response = ApiUtils.toCamelCaseObject(response);
console.log("DEBUG: API - Request Response: ", response);
return response.message;
if (response.message.status && response.message.status === "error") {
throw new Error(response.message.message);
}
return response.message.data;
} catch (error) {
console.error("DEBUG: API - Request Error: ", error);
// Re-throw the error so calling code can handle it
console.error("ERROR: API - Request Error: ", error);
throw error;
}
}
@ -145,7 +149,7 @@ class Api {
console.log("DEBUG: API - Sending job options to backend:", options);
const result = await this.request("custom_ui.api.db.get_jobs", { options });
const result = await this.request(FRAPPE_GET_JOBS_METHOD, { options });
return result;
}
@ -238,11 +242,8 @@ class Api {
return doc;
}
static async getCustomerNames() {
const customers = await this.getDocsList("Customer", ["name"]);
const customerNames = customers.map((customer) => customer.name);
console.log("DEBUG: API - Fetched Customer Names: ", customerNames);
return customerNames;
static async getCustomerNames(type) {
return await this.request(FRAPPE_GET_CLIENT_NAMES_METHOD, { type });
}
static async getCompanyNames() {