Implement organization maker-checker workflows
This commit is contained in:
@@ -16,6 +16,7 @@ import { RecurringDepositsService } from 'app/deposits/recurring-deposits/recurr
|
||||
import { SystemService } from 'app/system/system.service';
|
||||
import { AccountingService } from 'app/accounting/accounting.service';
|
||||
import { UsersService } from 'app/users/users.service';
|
||||
import { OrganizationService } from 'app/organization/organization.service';
|
||||
|
||||
/**
|
||||
* The services a maker-checker review screen needs in order to read an entity's current state.
|
||||
@@ -30,8 +31,17 @@ export interface EntityFetchServices {
|
||||
system: SystemService;
|
||||
accounting: AccountingService;
|
||||
users: UsersService;
|
||||
organization: OrganizationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entities with exactly one row in the whole tenant (a global settings screen, not a record with an
|
||||
* id) - Working Days being the first. These commands carry no resourceId at all, so the normal
|
||||
* "no id, no lookup" guard below is relaxed for exactly this set; every other entity's behavior is
|
||||
* unchanged.
|
||||
*/
|
||||
const SINGLETON_ENTITIES: ReadonlySet<string> = new Set(['WORKINGDAYS']);
|
||||
|
||||
/**
|
||||
* Maps a maker-checker `entityName` to the existing API that returns that entity as it stands today,
|
||||
* so an UPDATE can be shown as OLD -> NEW and a DELETE can show what is about to be removed.
|
||||
@@ -66,7 +76,11 @@ const ENTITY_FETCHERS: Record<string, (id: string, s: EntityFetchServices) => Ob
|
||||
CLIENT: (id, s) => s.clients.getClientData(id, true),
|
||||
ROLE: (id, s) => s.system.getRole(id),
|
||||
USER: (id, s) => s.users.getUser(id),
|
||||
GLACCOUNT: (id, s) => s.accounting.getGlAccount(id, true)
|
||||
GLACCOUNT: (id, s) => s.accounting.getGlAccount(id, true),
|
||||
|
||||
// ---- Singleton settings screens ----------------------------------------------
|
||||
// No resourceId - the command applies to the one Working Days row the tenant has.
|
||||
WORKINGDAYS: (id, s) => s.organization.getWorkingDays()
|
||||
};
|
||||
|
||||
/** Whether this screen can read the entity's current state, and therefore produce a real diff. */
|
||||
@@ -83,11 +97,16 @@ export function fetchCurrentEntity(
|
||||
resourceId: string | number | undefined | null,
|
||||
services: EntityFetchServices
|
||||
): Observable<any> | null {
|
||||
const fetcher = ENTITY_FETCHERS[(entityName ?? '').toUpperCase()];
|
||||
if (!fetcher || resourceId === null || resourceId === undefined || resourceId === '') {
|
||||
const key = (entityName ?? '').toUpperCase();
|
||||
const fetcher = ENTITY_FETCHERS[key];
|
||||
if (!fetcher) {
|
||||
return null;
|
||||
}
|
||||
return fetcher(String(resourceId), services);
|
||||
const hasResourceId = resourceId !== null && resourceId !== undefined && resourceId !== '';
|
||||
if (!hasResourceId && !SINGLETON_ENTITIES.has(key)) {
|
||||
return null;
|
||||
}
|
||||
return fetcher(String(resourceId ?? ''), services);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user