Skip to content

Commit

Permalink
refactor: Passing Observer instead of several
Browse files Browse the repository at this point in the history
Deprecation message: Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments

This deprecation was introduced in RxJS 6.4. (https://github.com/ng-docs/rxjs.dev/blob/master/CHANGELOG.md#640-2019-01-30)
  • Loading branch information
bzhn committed Oct 30, 2024
1 parent 63874e4 commit 7bfe54c
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 105 deletions.
10 changes: 5 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ export function appInitializerFactory(translate: TranslateService, injector: Inj

const selectedLanguage = languageService.getCurrentLanguage();

translate.use(selectedLanguage).subscribe(
() => {
translate.use(selectedLanguage).subscribe({
next: () => {
console.log(`Successfully initialized '${selectedLanguage}' language.`);
},
(err) => {
error: (err) => {
console.error(`Problem with '${selectedLanguage}' language initialization.`, { err });
},
() => {
complete: () => {
resolve(null);
}
);
});
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ export class ConfirmRestorePasswordComponent implements OnInit {
this.restoreDto.password = this.confirmRestorePasswordForm.value.password;
this.restoreDto.token = this.token;
this.restoreDto.isUbs = this.isUbs;
this.changePasswordService.restorePassword(this.restoreDto).subscribe(
(data) => {
this.changePasswordService.restorePassword(this.restoreDto).subscribe({
next: (data) => {
this.form = data;
this.router.navigate(this.isUbs ? ['ubs'] : ['']);
this.snackBar.openSnackBar(this.isUbs ? 'successConfirmPasswordUbs' : 'successConfirmPassword');
},
(error) => {
error: (error) => {
this.form = error;
this.snackBar.openSnackBar('sendNewLetter');
}
);
});
}

setPasswordBackendErr(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ export class SignUpComponent implements OnInit, OnDestroy, OnChanges {
this.userOwnSignUpService
.signUp(userOwnRegister, this.currentLanguage)
.pipe(takeUntil(this.destroy))
.subscribe(
(data: SuccessSignUpDto) => {
.subscribe({
next: (data: SuccessSignUpDto) => {
this.onSubmitSuccess(data);
},
(error: HttpErrorResponse) => {
error: (error: HttpErrorResponse) => {
this.onSubmitError(error);
}
);
});
}

signUpWithGoogle(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export class EcoEventsComponent implements OnInit {
}

private loadLatestNews(): void {
this.newsService.loadLatestNews().subscribe(
(data: NewsDto[]) => {
this.newsService.loadLatestNews().subscribe({
next: (data: NewsDto[]) => {
this.latestNews = data;
},
(error) => {
error: (error) => {
throw error;
}
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy {
inviteFriends(event: Event) {
event.preventDefault();
if (this.habitId && this.selectedFriends.length) {
this.userFriendsService.inviteFriendsToHabit(this.habitId, this.selectedFriends).subscribe(
() => {
this.userFriendsService.inviteFriendsToHabit(this.habitId, this.selectedFriends).subscribe({
next: () => {
this.invitationSent = true;
this.setAddedFriends();
},
(error) => {
error: (error) => {
this.snackBar.openSnackBar('snack-bar.error.default');
}
);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ export class UserLogComponent implements OnInit {
}

private retrieveUserLog() {
this.$userLog = this.habitStatisticService.getUserLog().subscribe(
(data) => {
this.$userLog = this.habitStatisticService.getUserLog().subscribe({
next: (data) => {
this.hasStatistic = true;
this.$creationDate = data.creationDate;
this.initializeNotTakenItemsStatistics(data);
},
(error) => {
error: (error) => {
this.hasStatistic = false;
console.log('Error!', error);
}
);
});
}

private initializeNotTakenItemsStatistics(data: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ export class AllFriendsComponent implements OnInit, OnDestroy {
this.userFriendsService
.getFriendsByName(value)
.pipe(takeUntil(this.destroy$))
.subscribe(
(data: FriendArrayModel) => {
.subscribe({
next: (data: FriendArrayModel) => {
this.emptySearchList = !data.page.length;
this.friends = data.page;
this.isFetching = false;
this.searchMode = false;
},
(error) => {
error: (error) => {
this.matSnackBar.openSnackBar('snack-bar.error.default');
this.isFetching = false;
this.searchMode = false;
}
);
});
} else {
this.searchMode = false;
this.emptySearchList = false;
Expand Down
48 changes: 24 additions & 24 deletions src/app/main/service/habit-statistic/habit-statistic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ export class HabitStatisticService implements OnLogout {
}

loadHabitStatistics(language: string) {
this.http.get<HabitDto[]>(`${userLink}/${this.userId}/habits?language=${language}`).subscribe(
(data) => {
this.http.get<HabitDto[]>(`${userLink}/${this.userId}/habits?language=${language}`).subscribe({
next: (data) => {
this.dataStore.habitStatistics = data;
this.$habitStatistics.next({ ...this.dataStore }.habitStatistics);
},
() => console.log('Can not load habit statistic.')
);
error: () => console.log('Can not load habit statistic.')
});
}

loadAvailableHabits(language: string) {
this.http.get<AvailableHabitDto[]>(`${userLink}/${this.userId}/habit-dictionary/available?language=${language}`).subscribe(
(data) => {
this.http.get<AvailableHabitDto[]>(`${userLink}/${this.userId}/habit-dictionary/available?language=${language}`).subscribe({
next: (data) => {
this.dataStore.availableHabits = data;
this.$availableHabits.next({ ...this.dataStore }.availableHabits);
},
() => console.log('Can not load available habits.')
);
error: () => console.log('Can not load available habits.')
});
}

setNewHabitsState(args) {
Expand All @@ -62,27 +62,27 @@ export class HabitStatisticService implements OnLogout {
}

createHabits(language: string) {
this.http.post<any>(`${userLink}/${this.userId}/habit?language=${language}`, this.dataStore.newHabits).subscribe(
() => {
this.http.post<any>(`${userLink}/${this.userId}/habit?language=${language}`, this.dataStore.newHabits).subscribe({
next: () => {
this.clearDataStore(language);
},
() => console.log('Can not assign new habit for this user')
);
error: () => console.log('Can not assign new habit for this user')
});
}

deleteHabit(habitId: number, language: string) {
this.http.delete<any>(`${userLink}/${this.userId}/habit/${habitId}`).subscribe(
() => {
this.http.delete<any>(`${userLink}/${this.userId}/habit/${habitId}`).subscribe({
next: () => {
this.loadAvailableHabits(language);
this.loadHabitStatistics(language);
},
() => console.log('Can not remove habit for this user')
);
error: () => console.log('Can not remove habit for this user')
});
}

updateHabitStatistic(habitStatisticDto: HabitStatisticsDto) {
this.http.patch<HabitStatisticsDto>(`${habitStatisticLink}${habitStatisticDto.id}`, habitStatisticDto).subscribe(
(data) => {
this.http.patch<HabitStatisticsDto>(`${habitStatisticLink}${habitStatisticDto.id}`, habitStatisticDto).subscribe({
next: (data) => {
let index: number;

this.dataStore.habitStatistics.forEach((item, i) => {
Expand All @@ -100,15 +100,15 @@ export class HabitStatisticService implements OnLogout {
}
});
},
() => console.log('Can not update habit statistic')
);
error: () => console.log('Can not update habit statistic')
});
}

createHabitStatistic(habitStatistics: HabitStatisticsDto) {
const toSend: any = habitStatistics;
toSend.createdOn = new Date().toISOString();
this.http.post<HabitStatisticsDto>(`${habitStatisticLink}`, toSend).subscribe(
(data) => {
this.http.post<HabitStatisticsDto>(`${habitStatisticLink}`, toSend).subscribe({
next: (data) => {
this.dataStore.habitStatistics.forEach((habit, habitIndex) => {
if (habit.id === habitStatistics.habitId) {
habit.habitStatistics.forEach((stat, statIndex) => {
Expand All @@ -126,8 +126,8 @@ export class HabitStatisticService implements OnLogout {
}
});
},
() => console.log('Can not create habit statistic')
);
error: () => console.log('Can not create habit statistic')
});
}

getUserLog(): Observable<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,16 @@ export class AddPaymentComponent implements OnInit, OnDestroy {
),
takeUntil(this.destroySub)
)
.subscribe(
(data: IPaymentInfoDto) => {
.subscribe({
next: (data: IPaymentInfoDto) => {
data.amount /= 100;
this.dialogRef.close(data);
},
(err) => {
error: (err) => {
console.error('error', err);
this.isUploading = false;
}
);
});
}

filesDropped(files: FileHandle[]): void {
Expand Down Expand Up @@ -342,14 +342,14 @@ export class AddPaymentComponent implements OnInit, OnDestroy {
this.orderService
.deleteManualPayment(this.payment.id)
.pipe(takeUntil(this.destroySub))
.subscribe(
() => {
.subscribe({
next: () => {
this.dialogRef.close(this.payment.id);
},
() => {
error: () => {
this.isDeleting = false;
}
);
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ export class UbsAdminEmployeeEditFormComponent implements OnInit, OnDestroy {
}

ngOnInit() {
this.employeeService.getAllPositions().subscribe(
(roles) => {
this.employeeService.getAllPositions().subscribe({
next: (roles) => {
this.roles = roles;
},
(error) => console.error('Observer for role got an error: ' + error)
);
error: (error) => console.error('Observer for role got an error: ' + error)
});
this.store
.select((state: IAppState): Employees => state.employees.employees)
.pipe(skip(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ export class UbsAdminEmployeePermissionsFormComponent implements OnInit, OnDestr
.filter(([, selected]) => selected)
.map(([perm]) => perm);

this.employeeService.updatePermissions(this.employee.email, selectedPermissions).subscribe(
() => {
this.employeeService.updatePermissions(this.employee.email, selectedPermissions).subscribe({
next: () => {
this.isUpdating = false;
this.snackBar.openSnackBar('successUpdateUbsData');
this.dialogRef.close(true);
},
(error) => {
error: (error) => {
this.snackBar.openSnackBar('error', error);
this.dialogRef.close(false);
}
);
});
}

managePermissionSettings(actionType: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ export class UbsAdminEmployeeComponent implements OnInit, OnDestroy {
this.ubsAdminEmployeeService
.getAllPositions()
.pipe(takeUntil(this.destroy$))
.subscribe(
(roles) => {
.subscribe({
next: (roles) => {
this.employeePositions = roles;
this.positionName = this.employeePositions.map((position: EmployeePositions) =>
this.languageService.getLangValue(position.name, position.nameEn)
);
},
(error) => console.error('Observer for role got an error: ' + error)
);
error: (error) => console.error('Observer for role got an error: ' + error)
});
}

getContacts(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ export class UbsAdminNotificationComponent implements OnInit, OnDestroy {
this.notificationsService
.getNotificationTemplate(id)
.pipe(take(1))
.subscribe(
(notification: NotificationTemplate) => {
.subscribe({
next: (notification: NotificationTemplate) => {
this.notification = formatUnixCron(notification);
},
() => this.navigateToNotificationList()
);
error: () => this.navigateToNotificationList()
});
}

navigateToNotificationList(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ export class UbsUserBonusesComponent implements OnInit, OnDestroy {
this.bonusesService
.getUserBonusesWithPaymentHistory()
.pipe(takeUntil(this.destroy))
.subscribe(
(res: BonusesModel) => {
.subscribe({
next: (res: BonusesModel) => {
this.bonusesList = res.ubsUserBonuses;
this.dataSource.data = res.ubsUserBonuses;
this.totalBonuses = res.userBonuses;
this.isLoading = false;
},
(error) => {
error: (error) => {
this.isLoading = false;
this.snackBar.openSnackBar('error');
return throwError(error);
}
);
});
}

sortData(sort: Sort) {
Expand Down
Loading

0 comments on commit 7bfe54c

Please sign in to comment.