mohd-faraz

_blogs

// blogs / 20260623.md

Dev Log: June 23 Wrap-up

2026-06-23
#javascript#backend#crm#refactoring

Overview

Today was mostly about smoothing out the rough edges in the CRM and rounding off the billing logic I've been wrestling with all week. It felt like one of those 'final 10%' days where you stop building new things and start making sure the things you already built actually work for the people using them.

What I Worked On

Fixing the Role-Based Logic

I spent a good portion of the afternoon digging into our CRM service. We had some flaky logic where the system wasn't always correctly identifying whether a user was a 'Partner' or an 'Admin,' especially when their session data was structured a specific way.

I realized I was being a bit too narrow in how I was looking up roles. I ended up refactoring the check to be more robust—it now pulls from the current user object, the roles array, and the session list as a fallback. It’s much cleaner now and should stop those random 'missing permission' errors that have been popping up in the logs.

// Consolidating how we identify user roles across the service
const role = this.getCurrentUser()?.role || this.getRoles()?.role || this.sessionData.roles[0]?.name;

if (role === 'Business Partner') {
  this.verifyAccess(resource.id, 'partner_id', 'FETCH_PARTNER_DATA');
} else if (role === 'Distributor Admin') {
  this.verifyAccess(resource.id, 'distributor_id', 'FETCH_DISTRIBUTOR_DATA');
}

Refining the Billing Flow

Following up on yesterday's work with the invoice statuses, I spent some time today ensuring the frontend and backend are perfectly in sync when an invoice transitions to PARTIALLY_PAID.

It was a bit of a headache getting the metadata (like payment references and modes) to pass through the helper methods correctly without bloating the API calls. I finally managed to get the payment schedules updating dynamically whenever a partial payment is logged. It's a small win, but it makes the whole invoicing system feel a lot more professional than just a simple 'paid/unpaid' toggle.

Squashing UI State Gremlins

I also revisited a bug where the invoice edit screen would occasionally 'lose' its configuration if the user refreshed the page at the wrong time. I moved some of the resource initialization logic higher up in the component lifecycle. It's not the most glamorous fix, but it makes the UI feel significantly more stable.

Wrapping Up

Everything feels much more solid now. The connection issues from earlier in the week are a distant memory, and the core CRM plumbing is finally behaving. Tomorrow, I'm planning to dive into some reporting exports—hopefully, that goes smoother than the database config saga did!