Merge pull request #2662 from JaySoni1/WEB-113-glim-application-fails-to-submit
WEB-113 GLIM Application Fails to Submit
This commit is contained in:
@@ -9,7 +9,7 @@ import { Observable } from 'rxjs';
|
||||
export class I18nService {
|
||||
constructor(private translateService: TranslateService) {}
|
||||
|
||||
public translate(key: string): Observable<string> {
|
||||
return this.translateService.get(key);
|
||||
public translate(key: string, params?: object): Observable<string> {
|
||||
return this.translateService.get(key, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** Angular Imports */
|
||||
import { Component, QueryList, ViewChild, ViewChildren } from '@angular/core';
|
||||
import { I18nService } from 'app/core/i18n/i18n.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
@@ -84,7 +85,8 @@ export class CreateGlimAccountComponent {
|
||||
private loansService: LoansService,
|
||||
private settingsService: SettingsService,
|
||||
private clientService: ClientsService,
|
||||
private dateUtils: Dates
|
||||
private dateUtils: Dates,
|
||||
private i18nService: I18nService
|
||||
) {
|
||||
this.route.data.subscribe((data: { loansAccountTemplate: any; groupsData: any }) => {
|
||||
this.loansAccountTemplate = data.loansAccountTemplate;
|
||||
@@ -212,7 +214,7 @@ export class CreateGlimAccountComponent {
|
||||
/** Request Body Data */
|
||||
buildRequestData(): any[] {
|
||||
const requestData = [];
|
||||
const memberSelected = this.selectedMembers.selectedMembers;
|
||||
const memberSelected = this.selectedMembers?.selectedMembers ?? [];
|
||||
const totalLoan = this.totalLoanAmount();
|
||||
for (let index = 0; index < memberSelected.length; index++) {
|
||||
requestData.push({
|
||||
@@ -227,7 +229,7 @@ export class CreateGlimAccountComponent {
|
||||
|
||||
totalLoanAmount(): number {
|
||||
let total = 0;
|
||||
const memberSelected = this.selectedMembers.selectedMembers;
|
||||
const memberSelected = this.selectedMembers?.selectedMembers ?? [];
|
||||
for (let index = 0; index < memberSelected.length; index++) {
|
||||
total += memberSelected[index].principal;
|
||||
}
|
||||
@@ -238,6 +240,30 @@ export class CreateGlimAccountComponent {
|
||||
* Creates a new GLIM account.
|
||||
*/
|
||||
submit() {
|
||||
this.selectedMembers = this.loansActiveClientMembers?.selectedClientMembers;
|
||||
const memberSelected = this.loansActiveClientMembers?.selectedClientMembers?.selectedMembers ?? [];
|
||||
if (!memberSelected.length) return;
|
||||
const gsimMemberIds = new Set(this.dataSource.map((m: any) => Number(m.id)));
|
||||
for (const member of memberSelected) {
|
||||
const memberId = Number(member.id);
|
||||
// Validate savings account ownership
|
||||
const ownerId = Number(member.linkAccountOwnerId);
|
||||
if (member.linkAccountId && member.linkAccountOwnerId && ownerId !== memberId) {
|
||||
this.i18nService.translate('errors.linkedSavingsAccountOwnership').subscribe((msg: string) => {
|
||||
this.notify({ defaultUserMessage: msg, errors: [] }, { memberId });
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Validate GSIM membership
|
||||
if (!gsimMemberIds.has(memberId)) {
|
||||
this.i18nService.translate('errors.clientNotInGSIM', { id: memberId }).subscribe((msg: string) => {
|
||||
this.notify({ defaultUserMessage: msg, errors: [] }, { memberId });
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Use date format from settingsService for interestChargedFromDate
|
||||
const data = this.buildRequestData();
|
||||
this.loansService.createGlimAccount(data).subscribe((response: any) => {
|
||||
const body = JSON.parse(response[0].body);
|
||||
@@ -250,15 +276,17 @@ export class CreateGlimAccountComponent {
|
||||
{ relativeTo: this.route }
|
||||
);
|
||||
} else {
|
||||
this.notify(body, data);
|
||||
this.notify(body, { batchSize: data.length });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
notify(body: any, data: any) {
|
||||
let message = body.defaultUserMessage + ' ';
|
||||
while (body.errors?.length > 0) message += body.errors.pop().developerMessage + ' ';
|
||||
message += 'Data: ' + JSON.stringify(data);
|
||||
console.error(message);
|
||||
notify(body: any, context?: { [k: string]: unknown }) {
|
||||
const parts: string[] = [String(body?.defaultUserMessage ?? '')];
|
||||
if (Array.isArray(body?.errors)) {
|
||||
for (const e of body.errors) parts.push(String(e?.developerMessage ?? ''));
|
||||
}
|
||||
if (context) parts.push(`Context: ${JSON.stringify(context)}`);
|
||||
console.error(parts.join(' ').trim());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user