From 3ea351d20dd4160e6ac7834c04dd5fb8063f0807 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Mon, 6 Apr 2026 17:51:41 +0500 Subject: [PATCH] dynamically show transaction permission apis from backend --- src/app/menu/menu.component.html | 2 +- src/app/menu/menu.component.ts | 36 ++++++++++++++++++-------------- src/app/utils/uri-enums.ts | 4 +++- src/assets/data/app.uri.json | 7 ++++++- src/assets/i18n/English.json | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/app/menu/menu.component.html b/src/app/menu/menu.component.html index 70442ab..782a6a4 100644 --- a/src/app/menu/menu.component.html +++ b/src/app/menu/menu.component.html @@ -48,7 +48,7 @@ {{ i + 1 }} - {{ item.name | translate }} + {{ item.endpoint | translate }} diff --git a/src/app/menu/menu.component.ts b/src/app/menu/menu.component.ts index c63dc1f..5df2f5c 100644 --- a/src/app/menu/menu.component.ts +++ b/src/app/menu/menu.component.ts @@ -25,12 +25,7 @@ export class MenuComponent { showPermissions = false; permissions: PermissionNode[] = []; saving = false; - menuItems = [ - { name: 'accountToAccount', endpoint: URIKey.ACCOUNT_TO_ACCOUNT, checked: true }, - { name: 'glToGl', endpoint: URIKey.GL_TO_GL, checked: false }, - { name: 'accountToGl', endpoint: URIKey.ACCOUNT_TO_GL, checked: false }, - { name: 'glToAccount', endpoint: URIKey.GL_TO_ACCOUNT, checked: false } -]; + menuItems: { endpoint: string; checked: boolean }[] = []; constructor( private credentialService: CredentialService, @@ -47,7 +42,21 @@ export class MenuComponent { ngOnInit() { this.getAllUsers(); + this.loadTransactionEndpoints(); } + + loadTransactionEndpoints() { + this.httpService.requestGET(URIKey.TRANSACTION_ENDPOINTS).subscribe((response) => { + if (!(response instanceof HttpErrorResponse)) { + this.menuItems = response.map(endpoint => ({ + endpoint, + checked: false + })); + } + }); +} + + defaultPermissions(): Observable { return this.httpService.requestGET('assets/data/sideMenu.json'); } @@ -88,18 +97,13 @@ onUserChange() { .filter(p => p.allowed) .map(p => this.normalizeUrl(p.transactionEndpoint)); // ← normalize - this.uriService.canSubscribe.pipe( - filter(ready => ready === true), - take(1) - ).subscribe(() => { this.menuItems.forEach(item => { - const resolvedEndpoint = this.normalizeUrl( - this.uriService.getURIForRequest(item.endpoint) // ← normalize + item.checked = allowedEndpoints.some(allowed => + allowed.endsWith(this.normalizeUrl(item.endpoint)) ); - item.checked = allowedEndpoints.includes(resolvedEndpoint); + }); - }); - + } else { this.menuItems.forEach(item => item.checked = false); } @@ -151,7 +155,7 @@ savePermissions() { ).subscribe(() => { const transactionEndpoints: string[] = this.menuItems .filter(item => item.checked) - .map(item => this.uriService.getURIForRequest(item.endpoint)); + .map(item => item.endpoint); const payload = { userId: selectedUser, transactionEndpoints }; diff --git a/src/app/utils/uri-enums.ts b/src/app/utils/uri-enums.ts index c1e3236..0fb8fb8 100644 --- a/src/app/utils/uri-enums.ts +++ b/src/app/utils/uri-enums.ts @@ -21,6 +21,8 @@ export enum URIKey { ACCOUNT_TO_GL = "ACCOUNT_TO_GL", GL_TO_ACCOUNT = "GL_TO_ACCOUNT", TRANSACTION_PERMISSIONS_ASSIGN = "TRANSACTION_PERMISSIONS_ASSIGN", - TRANSACTION_PERMISSIONS = "TRANSACTION_PERMISSIONS" + TRANSACTION_PERMISSIONS = "TRANSACTION_PERMISSIONS", + TRANSACTION_ENDPOINTS = "TRANSACTION_ENDPOINTS" + } \ No newline at end of file diff --git a/src/assets/data/app.uri.json b/src/assets/data/app.uri.json index 9abba5b..44ee2a7 100644 --- a/src/assets/data/app.uri.json +++ b/src/assets/data/app.uri.json @@ -112,10 +112,15 @@ "URI": "/transactions/gl-account", "UUID": "GL_TO_ACCOUNT" }, - { + { "Id": "ENTITY_TRANSACTION_PERMISSIONS", "URI": "/transaction-permissions/{userId}", "UUID": "TRANSACTION_PERMISSIONS" + }, + { + "Id": "ENTITY_TRANSACTION_ENDPOINTS", + "URI": "/transaction-permissions/endpoints", + "UUID": "TRANSACTION_ENDPOINTS" } ] } diff --git a/src/assets/i18n/English.json b/src/assets/i18n/English.json index ea1973a..bd8e133 100644 --- a/src/assets/i18n/English.json +++ b/src/assets/i18n/English.json @@ -315,7 +315,7 @@ "exportAllData": "Export All Data", "transactionLogDetails": "Transaction Logs Details", "USER_UPDATED_SUCCESS": "User Updated Successfully", - "menu": "Menu", + "menu": "Transaction Permissions", "type": "Transaction Type", "ACCOUNT_TO_ACCOUNT": "Account to Account", "GL_TO_GL": "General Ledger to General Ledger",