Skip to content

Commit 921927f

Browse files
IOhackerJaySoni1
authored andcommitted
Revert "WEB-(394)-fix: replace all direct JSON.parse usages with safe parsing utilities"
1 parent 0e1948b commit 921927f

File tree

6 files changed

+11
-47
lines changed

6 files changed

+11
-47
lines changed

src/app/core/utils/json.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/app/settings/settings.service.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Injectable } from '@angular/core';
33
import { AlertService } from 'app/core/alert/alert.service';
44
import { Dates } from 'app/core/utils/dates';
5-
import { safeParse, safeParseArray, safeParseObject } from 'app/core/utils/json';
65

76
/** Environment Imports */
87
import { environment } from '../../environments/environment';
@@ -109,9 +108,8 @@ export class SettingsService {
109108
/**
110109
* Returns date format setting.
111110
*/
112-
get dateFormat(): string {
113-
const parsed = safeParse<string | null>(localStorage.getItem('mifosXDateFormat'), null);
114-
return typeof parsed === 'string' && parsed.length > 0 ? parsed : 'dd MMMM yyyy';
111+
get dateFormat() {
112+
return JSON.parse(localStorage.getItem('mifosXDateFormat'));
115113
}
116114

117115
/**
@@ -121,10 +119,7 @@ export class SettingsService {
121119
if (!localStorage.getItem('mifosXLanguage')) {
122120
this.setDefaultLanguage();
123121
}
124-
return safeParseObject<{ name: string; code: string } | undefined>(
125-
localStorage.getItem('mifosXLanguage'),
126-
undefined
127-
);
122+
return JSON.parse(localStorage.getItem('mifosXLanguage'));
128123
}
129124

130125
get languageCode() {
@@ -152,7 +147,7 @@ export class SettingsService {
152147
* Returns list of default server
153148
*/
154149
get servers() {
155-
return safeParseArray<string>(localStorage.getItem('mifosXServers'), []);
150+
return JSON.parse(localStorage.getItem('mifosXServers'));
156151
}
157152

158153
/**
@@ -165,7 +160,7 @@ export class SettingsService {
165160
if (environment.baseApiUrl && environment.baseApiUrl !== '') {
166161
return environment.baseApiUrl;
167162
} else {
168-
return this.servers[0];
163+
return this.servers()[0];
169164
}
170165
}
171166

@@ -222,7 +217,7 @@ export class SettingsService {
222217
* Returns list of Tenant Identifiers
223218
*/
224219
get tenantIdentifiers(): any {
225-
return safeParseArray<string>(localStorage.getItem('mifosXTenantIdentifiers'), []);
220+
return JSON.parse(localStorage.getItem('mifosXTenantIdentifiers'));
226221
}
227222

228223
/**
@@ -265,6 +260,6 @@ export class SettingsService {
265260
}
266261

267262
get themeDarkEnabled(): boolean {
268-
return safeParse<boolean>(localStorage.getItem('mifosXThemeDarkEnabled'), false);
263+
return JSON.parse(localStorage.getItem('mifosXThemeDarkEnabled'));
269264
}
270265
}

src/app/shared/theme-picker/theme-storage.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Injectable, EventEmitter } from '@angular/core';
2-
import { safeParseObject } from 'app/core/utils/json';
32
import { Theme } from './theme.model';
43
import { ThemeManagerService } from './theme-manager.service';
54

@@ -20,7 +19,7 @@ export class ThemeStorageService {
2019
}
2120

2221
getTheme(): Theme {
23-
return safeParseObject<Theme | null>(localStorage.getItem(this.themeStorageKey), null);
22+
return JSON.parse(localStorage.getItem(this.themeStorageKey));
2423
}
2524

2625
clearTheme() {

src/app/system/configurations/business-date-tab/business-date-tab.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class BusinessDateTabComponent implements OnInit {
4646
businessDateData: any;
4747

4848
dateIndex = 0;
49-
userDateFormat: string = '';
49+
userDateFormat: '';
5050
isBusinessDateEnabled = false;
5151
isEditInProgress = false;
5252

src/app/tasks/view-checker-inbox/view-checker-inbox.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { MatDivider } from '@angular/material/divider';
1515
import { NgIf, NgFor, KeyValuePipe } from '@angular/common';
1616
import { DateFormatPipe } from '../../pipes/date-format.pipe';
1717
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
18-
import { safeParseObject } from 'app/core/utils/json';
1918

2019
@Component({
2120
selector: 'mifosx-view-checker-inbox',
@@ -53,7 +52,7 @@ export class ViewCheckerInboxComponent {
5352
) {
5453
this.route.data.subscribe((data: { checkerInboxDetail: any }) => {
5554
this.checkerInboxDetail = data.checkerInboxDetail;
56-
this.jsondata = safeParseObject<any>(this.checkerInboxDetail.commandAsJson, {});
55+
this.jsondata = JSON.parse(this.checkerInboxDetail.commandAsJson);
5756
this.displayJSONData = !_.isEmpty(this.jsondata);
5857
});
5958
}

src/app/web-app.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { Dates } from './core/utils/dates';
3131
import { animate, style, transition, trigger } from '@angular/animations';
3232
import { I18nService } from './core/i18n/i18n.service';
3333
import { ThemingService } from './shared/theme-toggle/theming.service';
34-
import { safeParseArray } from 'app/core/utils/json';
3534

3635
import { AuthService } from './zitadel/auth.service';
3736

@@ -196,7 +195,7 @@ export class WebAppComponent implements OnInit, OnDestroy {
196195
// Stores top 100 user activites as local storage object.
197196
let activities: string[] = [];
198197
if (localStorage.getItem('mifosXLocation')) {
199-
const activitiesArray = safeParseArray<string>(localStorage.getItem('mifosXLocation'), []);
198+
const activitiesArray: string[] = JSON.parse(localStorage.getItem('mifosXLocation'));
200199
const length = activitiesArray.length;
201200
activities = length > 100 ? activitiesArray.slice(length - 100) : activitiesArray;
202201
}

0 commit comments

Comments
 (0)