added model

This commit is contained in:
Valentin 2021-11-05 10:13:18 +02:00
parent 5f03843e2c
commit dd0248e7f5
3 changed files with 18 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup } from '@angular/forms';
import { notificationsTranslations } from '../../translations/notifications-translations'; import { notificationsTranslations } from '../../translations/notifications-translations';
import { NotificationPreferencesService } from '../../../../services/notification-preferences.service'; import { NotificationPreferencesService } from '../../../../services/notification-preferences.service';
import { LoadingService } from '../../../../../../../../libs/common-ui/src';
@Component({ @Component({
selector: 'redaction-notifications-screen', selector: 'redaction-notifications-screen',
@ -23,6 +24,7 @@ export class NotificationsScreenComponent implements OnInit {
constructor( constructor(
private readonly _formBuilder: FormBuilder, private readonly _formBuilder: FormBuilder,
private readonly _loadingService: LoadingService,
private readonly _notificationPreferencesService: NotificationPreferencesService, private readonly _notificationPreferencesService: NotificationPreferencesService,
) {} ) {}
@ -60,11 +62,15 @@ export class NotificationsScreenComponent implements OnInit {
async save() { async save() {
console.log('formGroup: ', this.formGroup.value); console.log('formGroup: ', this.formGroup.value);
return; return;
this._loadingService.start();
await this._notificationPreferencesService.updateNotificationPreferences(this.formGroup.value).toPromise(); await this._notificationPreferencesService.updateNotificationPreferences(this.formGroup.value).toPromise();
this._loadingService.stop();
} }
private async _initializeForm() { private async _initializeForm() {
this._loadingService.start();
// const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise(); // const notificationPreferences = await this._notificationPreferencesService.getNotificationPreferences().toPromise();
this._loadingService.stop();
const notificationPreferences = { const notificationPreferences = {
emailNotificationType: 'DAILY', emailNotificationType: 'DAILY',

View File

@ -2,20 +2,21 @@ import { Injectable, Injector } from '@angular/core';
import { GenericService } from '../../../../../libs/common-ui/src'; import { GenericService } from '../../../../../libs/common-ui/src';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { INotificationPreferences } from '../../../../../libs/red-domain/src/lib/notifications-preferences/notification-preferences';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class NotificationPreferencesService extends GenericService<any> { export class NotificationPreferencesService extends GenericService<INotificationPreferences> {
constructor(protected readonly _injector: Injector, private readonly _userService: UserService) { constructor(protected readonly _injector: Injector, private readonly _userService: UserService) {
super(_injector, 'notification-preferences'); super(_injector, 'notification-preferences');
} }
getNotificationPreferences(): Observable<any> { getNotificationPreferences(): Observable<INotificationPreferences[]> {
return super.get(); return super.get();
} }
updateNotificationPreferences(body: any): Observable<any> { updateNotificationPreferences(notificationPreferences: INotificationPreferences): Observable<void> {
return super._post(body); return super._post(notificationPreferences);
} }
} }

View File

@ -0,0 +1,7 @@
export interface INotificationPreferences {
emailNotificationType: 'INSTANT' | 'DAILY' | 'WEEKLY';
emailNotifications: string[];
emailNotificationsEnabled: boolean;
inAppNotifications: string[];
inAppNotificationsEnabled: boolean;
}