80 lines
3.0 KiB
TypeScript
80 lines
3.0 KiB
TypeScript
/**
|
|
* Copyright since 2025 Mifos Initiative
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
/** Angular Imports */
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { ActivatedRouteSnapshot } from '@angular/router';
|
|
|
|
/** rxjs Imports */
|
|
import { Observable, forkJoin, of } from 'rxjs';
|
|
import { map, switchMap } from 'rxjs/operators';
|
|
|
|
/** Custom Services */
|
|
import { CurrentAccountsService } from '../current-accounts.service';
|
|
import { ClientsService } from 'app/clients/clients.service';
|
|
import { GroupsService } from 'app/groups/groups.service';
|
|
import { OrganizationService } from 'app/organization/organization.service';
|
|
|
|
/**
|
|
* Current Account Actions data resolver.
|
|
*/
|
|
@Injectable()
|
|
export class CurrentAccountActionsResolver {
|
|
private currentAccountsService = inject(CurrentAccountsService);
|
|
private clientsService = inject(ClientsService);
|
|
private groupsService = inject(GroupsService);
|
|
private organizationService = inject(OrganizationService);
|
|
|
|
/**
|
|
* Returns the Current account actions data.
|
|
* @param {ActivatedRouteSnapshot} route Route Snapshot
|
|
* @returns {Observable<any>}
|
|
*/
|
|
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
|
const actionName = route.paramMap.get('name');
|
|
const currentAccountId =
|
|
route.paramMap.get('currentAccountId') || route.parent.parent.paramMap.get('currentAccountId');
|
|
switch (actionName) {
|
|
case 'Assign Staff':
|
|
return this.currentAccountsService.getCurrentAccountData(currentAccountId).pipe(
|
|
switchMap((account: any) => {
|
|
if (!account.clientId && !account.groupId) {
|
|
return of({ ...account, fieldOfficerOptions: [] });
|
|
}
|
|
const entityObs = account.clientId
|
|
? this.clientsService.getClientData(account.clientId)
|
|
: this.groupsService.getGroupData(account.groupId);
|
|
return entityObs.pipe(
|
|
switchMap((entity: any) => this.organizationService.getStaff(entity.officeId, true)),
|
|
map((staff: any) => ({
|
|
...account,
|
|
fieldOfficerOptions: staff
|
|
}))
|
|
);
|
|
})
|
|
);
|
|
case 'Add Charge':
|
|
return this.currentAccountsService.getCurrentAccountChargeTemplateResource(currentAccountId);
|
|
case 'Withdrawal':
|
|
case 'Deposit':
|
|
case 'Hold Amount':
|
|
return this.currentAccountsService.getCurrentAccountTransactionTemplateResource(currentAccountId);
|
|
case 'Close':
|
|
return forkJoin([
|
|
this.currentAccountsService.getCurrentAccountTransactionTemplateResource(currentAccountId),
|
|
this.currentAccountsService.getCurrentAccountData(currentAccountId)
|
|
]);
|
|
case 'Activate':
|
|
case 'Apply Annual Fees':
|
|
return this.currentAccountsService.getCurrentAccountData(currentAccountId);
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
}
|