diff --git a/src/app/customApis.service.ts b/src/app/customApis.service.ts index 19da5188a9..4afc229a08 100644 --- a/src/app/customApis.service.ts +++ b/src/app/customApis.service.ts @@ -231,3 +231,18 @@ export class OrganizationService { }); } } + +@Injectable({ + providedIn: 'root' +}) +export class SharesService { + constructor(private http: HttpClient) {} + + /** + * @param {string} accountId shares account Id + * @returns {Observable} + */ + deleteSharesAccount(accountId: string): Observable { + return this.http.delete(`/accounts/share/${accountId}`); + } +} diff --git a/src/app/shares/common-resolvers/share-account-actions.resolver.ts b/src/app/shares/common-resolvers/share-account-actions.resolver.ts index e0e6610cf7..a2b8efc2c0 100644 --- a/src/app/shares/common-resolvers/share-account-actions.resolver.ts +++ b/src/app/shares/common-resolvers/share-account-actions.resolver.ts @@ -6,7 +6,7 @@ import { ActivatedRouteSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; /** * Shares Account Actions data resolver. @@ -14,9 +14,9 @@ import { SharesService } from '../shares.service'; @Injectable() export class ShareAccountActionsResolver { /** - * @param {sharesService} SharesService Shares service. + * @param {ShareAccountService} ShareAccountService Shares account service. */ - constructor(private sharesService: SharesService) {} + constructor(private shareAccountService: ShareAccountService) {} /** * Returns the Shares account actions data. @@ -31,7 +31,10 @@ export class ShareAccountActionsResolver { case 'Redeem Shares': case 'Approve Additional Shares': case 'Reject Additional Shares': - return this.sharesService.getSharesAccountData(shareAccountId, true); + return this.shareAccountService.retrieveAccount({ + accountId: Number(shareAccountId), + type: 'full' + }); default: return undefined; } diff --git a/src/app/shares/common-resolvers/share-account-and-template.resolver.ts b/src/app/shares/common-resolvers/share-account-and-template.resolver.ts index d9bd450558..de224bba9e 100644 --- a/src/app/shares/common-resolvers/share-account-and-template.resolver.ts +++ b/src/app/shares/common-resolvers/share-account-and-template.resolver.ts @@ -6,7 +6,7 @@ import { ActivatedRouteSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; /** * Shares Account data and template resolver. @@ -14,9 +14,9 @@ import { SharesService } from '../shares.service'; @Injectable() export class SharesAccountAndTemplateResolver { /** - * @param {SharesService} SharesService Shares service. + * @param {ShareAccountService} ShareAccountService Share account service. */ - constructor(private sharesService: SharesService) {} + constructor(private shareAccountService: ShareAccountService) {} /** * Returns the Shares Account data and template. @@ -25,6 +25,9 @@ export class SharesAccountAndTemplateResolver { */ resolve(route: ActivatedRouteSnapshot): Observable { const shareAccountId = route.paramMap.get('shareAccountId'); - return this.sharesService.getSharesAccountData(shareAccountId, true); + return this.shareAccountService.retrieveAccount({ + accountId: Number(shareAccountId), + type: 'true' + }); } } diff --git a/src/app/shares/common-resolvers/share-account-view.resolver.ts b/src/app/shares/common-resolvers/share-account-view.resolver.ts index 841a1241b6..bdd064987a 100644 --- a/src/app/shares/common-resolvers/share-account-view.resolver.ts +++ b/src/app/shares/common-resolvers/share-account-view.resolver.ts @@ -6,7 +6,7 @@ import { ActivatedRouteSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; /** * Shares Account data resolver. @@ -14,9 +14,9 @@ import { SharesService } from '../shares.service'; @Injectable() export class SharesAccountViewResolver { /** - * @param {SharesService} SharesService Shares service. + * @param {ShareAccountService} ShareAccountService Shares account service. */ - constructor(private sharesService: SharesService) {} + constructor(private shareAccountService: ShareAccountService) {} /** * Returns the Shares Account data. @@ -25,6 +25,9 @@ export class SharesAccountViewResolver { */ resolve(route: ActivatedRouteSnapshot): Observable { const shareAccountId = route.paramMap.get('shareAccountId') || route.parent.paramMap.get('shareAccountId'); - return this.sharesService.getSharesAccountData(shareAccountId, false); + return this.shareAccountService.retrieveAccount({ + accountId: Number(shareAccountId), + type: 'default' + }); } } diff --git a/src/app/shares/common-resolvers/shares-account-template.resolver.ts b/src/app/shares/common-resolvers/shares-account-template.resolver.ts index cf61532e0b..a5b9c318f6 100644 --- a/src/app/shares/common-resolvers/shares-account-template.resolver.ts +++ b/src/app/shares/common-resolvers/shares-account-template.resolver.ts @@ -6,7 +6,7 @@ import { ActivatedRouteSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; /** * Shares Account Template resolver. @@ -14,9 +14,9 @@ import { SharesService } from '../shares.service'; @Injectable() export class SharesAccountTemplateResolver { /** - * @param {SharesService} SharesService Shares service. + * @param {ShareAccountService} ShareAccountService Shares account service. */ - constructor(private sharesService: SharesService) {} + constructor(private shareAccountService: ShareAccountService) {} /** * Returns the Shares Account Template. @@ -25,6 +25,6 @@ export class SharesAccountTemplateResolver { */ resolve(route: ActivatedRouteSnapshot): Observable { const clientId = route.parent.parent.paramMap.get('clientId'); - return this.sharesService.getSharesAccountTemplate(clientId); + return this.shareAccountService.template7({ type: 'client', clientId: clientId ? +clientId : undefined }); } } diff --git a/src/app/shares/create-shares-account/create-shares-account.component.ts b/src/app/shares/create-shares-account/create-shares-account.component.ts index eb599490ba..63d5cdf72c 100644 --- a/src/app/shares/create-shares-account/create-shares-account.component.ts +++ b/src/app/shares/create-shares-account/create-shares-account.component.ts @@ -8,7 +8,7 @@ import { SharesAccountTermsStepComponent } from '../shares-account-stepper/share import { SharesAccountChargesStepComponent } from '../shares-account-stepper/shares-account-charges-step/shares-account-charges-step.component'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { MatStepper, MatStepperIcon, MatStep, MatStepLabel } from '@angular/material/stepper'; @@ -56,14 +56,14 @@ export class CreateSharesAccountComponent { * @param {ActivatedRoute} route Activated Route * @param {Router} router Router * @param {Dates} dateUtils Date Utils - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} ShareAccountService Shares Account Service * @param {SettingsService} settingsService Settings Service */ constructor( private route: ActivatedRoute, private router: Router, private dateUtils: Dates, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private settingsService: SettingsService ) { this.route.data.subscribe((data: { sharesAccountTemplate: any }) => { @@ -121,14 +121,15 @@ export class CreateSharesAccountComponent { const sharesAccount = { ...this.sharesAccount, clientId: this.sharesAccountTemplate.clientId, - charges: this.sharesAccount.charges.map((charge: any) => ({ chargeId: charge.id, amount: charge.amount })), + charges: this.sharesAccount.charges?.map((charge: any) => ({ chargeId: charge.id, amount: charge.amount })) || [], applicationDate: this.dateUtils.formatDate(this.sharesAccount.applicationDate, dateFormat), submittedDate: this.dateUtils.formatDate(this.sharesAccount.submittedDate, dateFormat), unitPrice: this.sharesAccountTermsForm.get('unitPrice').value, dateFormat, - locale + locale, + type: this.sharesAccount.type || 'client' }; - this.sharesService.createSharesAccount(sharesAccount).subscribe((response: any) => { + this.shareAccountService.createAccount(sharesAccount).subscribe((response: any) => { this.router.navigate( [ '../', diff --git a/src/app/shares/edit-shares-account/edit-shares-account.component.ts b/src/app/shares/edit-shares-account/edit-shares-account.component.ts index 8c45a7268c..e85d13bfda 100644 --- a/src/app/shares/edit-shares-account/edit-shares-account.component.ts +++ b/src/app/shares/edit-shares-account/edit-shares-account.component.ts @@ -8,7 +8,7 @@ import { SharesAccountTermsStepComponent } from '../shares-account-stepper/share import { SharesAccountChargesStepComponent } from '../shares-account-stepper/shares-account-charges-step/shares-account-charges-step.component'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { MatStepper, MatStepperIcon, MatStep, MatStepLabel } from '@angular/material/stepper'; @@ -56,14 +56,14 @@ export class EditSharesAccountComponent { * @param {ActivatedRoute} route Activated Route * @param {Router} router Router * @param {Dates} dateUtils Date Utils - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Shares Account Service * @param {SettingsService} settingsService Settings Service */ constructor( private route: ActivatedRoute, private router: Router, private dateUtils: Dates, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private settingsService: SettingsService ) { this.route.data.subscribe((data: { sharesAccountAndTemplate: any }) => { @@ -134,8 +134,8 @@ export class EditSharesAccountComponent { dateFormat, locale }; - this.sharesService - .updateSharesAccount(this.sharesAccountAndTemplate.id, sharesAccount) + this.shareAccountService + .updateAccount(this.sharesAccountAndTemplate.id, sharesAccount) .subscribe((response: any) => { this.router.navigate(['../'], { relativeTo: this.route }); }); diff --git a/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts b/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts index 5de245df72..5b9a347bc9 100644 --- a/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/activate-shares-account/activate-shares-account.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -32,7 +32,7 @@ export class ActivateSharesAccountComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Shares Account Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -40,7 +40,7 @@ export class ActivateSharesAccountComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -86,7 +86,13 @@ export class ActivateSharesAccountComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'activate', data).subscribe(() => { + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'activate' + }; + this.shareAccountService.handleCommands2(params).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts index 304ae1d50b..4f8131cc5b 100644 --- a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -35,7 +35,7 @@ export class ApplySharesComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Shares Account Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -43,7 +43,7 @@ export class ApplySharesComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -101,7 +101,13 @@ export class ApplySharesComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'applyadditionalshares', data).subscribe(() => { + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'applyadditionalshares' + }; + this.shareAccountService.handleCommands2(params).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts b/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts index a7be399614..b2e7c729a8 100644 --- a/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/approve-shares-account/approve-shares-account.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { CdkTextareaAutosize } from '@angular/cdk/text-field'; @@ -34,7 +34,7 @@ export class ApproveSharesAccountComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} ShareAccountService Shares Account Service. * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -42,7 +42,7 @@ export class ApproveSharesAccountComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -89,7 +89,13 @@ export class ApproveSharesAccountComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'approve', data).subscribe(() => { + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'approve' + }; + this.shareAccountService.handleCommands2(params).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts index cf0c2eeb8a..83e0a36f70 100644 --- a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts +++ b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts @@ -22,7 +22,7 @@ import { MatTable } from '@angular/material/table'; import { ApproveShareDialogComponent } from './approve-share-dialog/approve-share-dialog.component'; /** Custom Serices */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { NgClass } from '@angular/common'; import { MatTooltip } from '@angular/material/tooltip'; @@ -85,13 +85,13 @@ export class ApproveSharesComponent implements OnInit { @ViewChild('sharesTable', { static: true }) sharesTableRef: MatTable; /** - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} ShareAccountService Shares account service. * @param {ActivatedRoute} route Activated Route * @param {MatDialog} dialog Dialog reference. * @param {SettingsService} settingsService Settings Service */ constructor( - private sharesService: SharesService, + private sharesAccountService: ShareAccountService, private route: ActivatedRoute, public dialog: MatDialog, private settingsService: SettingsService @@ -134,19 +134,23 @@ export class ApproveSharesComponent implements OnInit { const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; const data = { - requestedShares: [{ id }], + requestedShares: new Set([{ id }]), dateFormat, locale }; - this.sharesService - .executeSharesAccountCommand(this.accountId, 'approveadditionalshares', data) - .subscribe(() => { - const share = this.sharesData.find((element) => element.id === id); - const index = this.sharesData.indexOf(share); - this.sharesData.splice(index, 1); - this.dataSource.data = this.sharesData; - this.sharesTableRef.renderRows(); - }); + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'approveadditionalshares' + }; + this.sharesAccountService.handleCommands2(params).subscribe(() => { + const share = this.sharesData.find((element) => element.id === id); + const index = this.sharesData.indexOf(share); + this.sharesData.splice(index, 1); + this.dataSource.data = this.sharesData; + this.sharesTableRef.renderRows(); + }); } }); } diff --git a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts index 81eabd3665..efd3a67643 100644 --- a/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/close-shares-account/close-shares-account.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { CdkTextareaAutosize } from '@angular/cdk/text-field'; @@ -34,7 +34,7 @@ export class CloseSharesAccountComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Share Account Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -42,7 +42,7 @@ export class CloseSharesAccountComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -89,7 +89,13 @@ export class CloseSharesAccountComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'close', data).subscribe(() => { + const requestParams = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'close' + }; + this.shareAccountService.handleCommands2(requestParams).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts b/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts index c3c8606472..666246d3d8 100644 --- a/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts +++ b/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -35,7 +35,7 @@ export class RedeemSharesComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Share Account Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -43,7 +43,7 @@ export class RedeemSharesComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -101,7 +101,13 @@ export class RedeemSharesComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'redeemshares', data).subscribe(() => { + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'redeemshares' + }; + this.shareAccountService.handleCommands2(params).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts b/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts index 7a68cacb68..31023f1f82 100644 --- a/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/reject-shares-account/reject-shares-account.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { CdkTextareaAutosize } from '@angular/cdk/text-field'; @@ -34,7 +34,7 @@ export class RejectSharesAccountComponent implements OnInit { /** * @param {FormBuilder} formBuilder Form Builder - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService} shareAccountService Share Account Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router @@ -42,7 +42,7 @@ export class RejectSharesAccountComponent implements OnInit { */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private dateUtils: Dates, private route: ActivatedRoute, private router: Router, @@ -89,7 +89,13 @@ export class RejectSharesAccountComponent implements OnInit { dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'reject', data).subscribe(() => { + const requestParams = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'reject' + }; + this.shareAccountService.handleCommands2(requestParams).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } diff --git a/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts b/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts index 8ba2310205..316e7cee46 100644 --- a/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts +++ b/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts @@ -22,7 +22,7 @@ import { MatTable } from '@angular/material/table'; import { RejectShareDialogComponent } from './reject-share-dialog/reject-share-dialog.component'; /** Custom Serices */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { SettingsService } from 'app/settings/settings.service'; import { NgClass } from '@angular/common'; import { MatTooltip } from '@angular/material/tooltip'; @@ -85,13 +85,13 @@ export class RejectSharesComponent implements OnInit { @ViewChild('sharesTable', { static: true }) sharesTableRef: MatTable; /** - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService } ShareAccountService Shares account service. * @param {ActivatedRoute} route Activated Route * @param {MatDialog} dialog Mat Dialog * @param {SettingsService} settingsService Settings Service. */ constructor( - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private route: ActivatedRoute, public dialog: MatDialog, private settingsService: SettingsService @@ -134,11 +134,17 @@ export class RejectSharesComponent implements OnInit { const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; const data = { - requestedShares: [{ id }], + requestedShares: new Set([{ id }]), dateFormat, locale }; - this.sharesService.executeSharesAccountCommand(this.accountId, 'rejectadditionalshares', data).subscribe(() => { + const params = { + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: data, + command: 'rejectadditionalshares' + }; + this.shareAccountService.handleCommands2(params).subscribe(() => { const share = this.sharesData.find((element) => element.id === id); const index = this.sharesData.indexOf(share); this.sharesData.splice(index, 1); diff --git a/src/app/shares/shares-account-actions/shares-account-actions.component.ts b/src/app/shares/shares-account-actions/shares-account-actions.component.ts index 0f5bc984fe..f1b105ebef 100644 --- a/src/app/shares/shares-account-actions/shares-account-actions.component.ts +++ b/src/app/shares/shares-account-actions/shares-account-actions.component.ts @@ -3,7 +3,6 @@ import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; /** Custom Services */ -import { SharesService } from '../shares.service'; import { ApproveSharesAccountComponent } from './approve-shares-account/approve-shares-account.component'; import { RejectSharesAccountComponent } from './reject-shares-account/reject-shares-account.component'; import { CloseSharesAccountComponent } from './close-shares-account/close-shares-account.component'; diff --git a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts index d32cd9f30e..ecd41b3dcf 100644 --- a/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts +++ b/src/app/shares/shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component.ts @@ -3,7 +3,7 @@ import { Component } from '@angular/core'; import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { ReactiveFormsModule, FormsModule } from '@angular/forms'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -24,12 +24,12 @@ export class UndoApprovalSharesAccountComponent { accountId: any; /** - * @param {SharesService} sharesService Shares Service + * @param {ShareAccountService } ShareAccountService Shares Account Service * @param {ActivatedRoute} route Activated Route * @param {Router} router Router */ constructor( - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private route: ActivatedRoute, private router: Router ) { @@ -41,8 +41,15 @@ export class UndoApprovalSharesAccountComponent { * if successful redirects to the share account. */ submit() { - this.sharesService.executeSharesAccountCommand(this.accountId, 'undoapproval', {}).subscribe(() => { - this.router.navigate(['../../'], { relativeTo: this.route }); - }); + this.shareAccountService + .handleCommands2({ + type: 'shares', + accountId: this.accountId, + postAccountsTypeAccountIdRequest: {}, + command: 'undoapproval' + }) + .subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); } } diff --git a/src/app/shares/shares-account-stepper/shares-account-details-step/shares-account-details-step.component.ts b/src/app/shares/shares-account-stepper/shares-account-details-step/shares-account-details-step.component.ts index b904b9a7c1..17d1073919 100644 --- a/src/app/shares/shares-account-stepper/shares-account-details-step/shares-account-details-step.component.ts +++ b/src/app/shares/shares-account-stepper/shares-account-details-step/shares-account-details-step.component.ts @@ -4,7 +4,7 @@ import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } import { SettingsService } from 'app/settings/settings.service'; /** Custom Services */ -import { SharesService } from 'app/shares/shares.service'; +import { ShareAccountService } from '@fineract/client'; import { MatStepperPrevious, MatStepperNext } from '@angular/material/stepper'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -42,12 +42,12 @@ export class SharesAccountDetailsStepComponent implements OnInit { /** * Sets share account details form. * @param {FormBuilder} formBuilder Form Builder. - * @param {SharesService} sharesService Shares Service. + * @param {ShareAccountService} shareAccountService Share Account Service. * @param {SettingsService} settingsService Settings Service */ constructor( private formBuilder: UntypedFormBuilder, - private sharesService: SharesService, + private shareAccountService: ShareAccountService, private settingsService: SettingsService ) { this.createSharesAccountDetailsForm(); @@ -93,9 +93,11 @@ export class SharesAccountDetailsStepComponent implements OnInit { buildDependencies() { const clientId = this.sharesAccountTemplate.clientId; this.sharesAccountDetailsForm.get('productId').valueChanges.subscribe((productId: string) => { - this.sharesService.getSharesAccountTemplate(clientId, productId).subscribe((response: any) => { - this.sharesAccountProductTemplate.emit(response); - }); + this.shareAccountService + .template7({ clientId: Number(clientId), productId: Number(productId), type: 'client' }) + .subscribe((response: any) => { + this.sharesAccountProductTemplate.emit(response); + }); }); } diff --git a/src/app/shares/shares-account-view/shares-account-view.component.ts b/src/app/shares/shares-account-view/shares-account-view.component.ts index 51b3b9527c..85eb860ab0 100644 --- a/src/app/shares/shares-account-view/shares-account-view.component.ts +++ b/src/app/shares/shares-account-view/shares-account-view.component.ts @@ -7,7 +7,7 @@ import { MatDialog } from '@angular/material/dialog'; import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; /** Custom Services */ -import { SharesService } from '../shares.service'; +import { SharesService } from 'app/customApis.service'; /** Custom Buttons Configuration */ import { SharesButtonsConfiguration } from './shares-buttons.config'; diff --git a/src/app/shares/shares.service.ts b/src/app/shares/shares.service.ts deleted file mode 100644 index bffbe39d37..0000000000 --- a/src/app/shares/shares.service.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** Angular Imports */ -import { Injectable } from '@angular/core'; -import { HttpClient, HttpParams } from '@angular/common/http'; - -/** rxjs Imports */ -import { Observable } from 'rxjs'; - -/** - * Shares Service. - */ -@Injectable({ - providedIn: 'root' -}) -export class SharesService { - /** - * @param {HttpClient} http Http Client - */ - constructor(private http: HttpClient) {} - - /** - * @param {string} accountId Shares Account Id of account to get data for. - * @param {boolean} template Shares account template required?. - * @returns {Observable} Shares data. - */ - getSharesAccountData(accountId: string, template: boolean): Observable { - const httpParams = new HttpParams().set('template', template.toString()); - return this.http.get(`/accounts/share/${accountId}`, { params: httpParams }); - } - - /** - * @param {string} clientId Client Id assosciated with shares account. - * @param {string} productId Product Id - * @returns {Observable} Shares account template. - */ - getSharesAccountTemplate(clientId: string, productId?: string): Observable { - let httpParams = new HttpParams().set('clientId', clientId); - httpParams = productId ? httpParams.set('productId', productId) : httpParams; - return this.http.get('/accounts/share/template', { params: httpParams }); - } - - /** - * @param {any} sharesAccount Shares Account - * @returns {Observable} - */ - createSharesAccount(sharesAccount: any): Observable { - return this.http.post('/accounts/share', sharesAccount); - } - - /** - * @param {string} accountId: Shares account Id. - * @param {any} sharesAccount Shares Account - * @returns {Observable} - */ - updateSharesAccount(accountId: string, sharesAccount: any): Observable { - return this.http.put(`/accounts/share/${accountId}`, sharesAccount); - } - - /** - * @param {string} accountId shares account Id - * @returns {Observable} - */ - deleteSharesAccount(accountId: string): Observable { - return this.http.delete(`/accounts/share/${accountId}`); - } - - /** - * @param {string} accountId Shares Account Id - * @param {string} command Command - * @param {any} data Data - * @returns {Observable} Shares data. - */ - executeSharesAccountCommand(accountId: string, command: string, data: any): Observable { - const httpParams = new HttpParams().set('command', command); - return this.http.post(`/accounts/share/${accountId}`, data, { params: httpParams }); - } -}