remove api module, add notifications service

This commit is contained in:
Dan Percic 2021-10-14 23:01:03 +03:00
parent d9f5e10b7d
commit a7a81f48c4
5 changed files with 37 additions and 38 deletions

View File

@ -5,7 +5,6 @@ import { ActivatedRoute, Router } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http';
import { BaseScreenComponent } from '@components/base-screen/base-screen.component';
import { ApiModule } from '@redaction/red-ui-http';
import { ApiPathInterceptor } from '@utils/api-path-interceptor';
import { MissingTranslationHandler, TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { languageInitializer } from '@i18n/language.initializer';
@ -65,7 +64,6 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp
FileUploadDownloadModule,
HttpClientModule,
AuthModule,
ApiModule,
AppRoutingModule,
MonacoEditorModule,
IqserHelpModeModule,

View File

@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import * as moment from 'moment';
import { TranslateService } from '@ngx-translate/core';
import { Notification, NotificationControllerService, NotificationResponse } from '@redaction/red-ui-http';
import { Notification, NotificationResponse } from '@redaction/red-ui-http';
import { DatePipe } from '@shared/pipes/date.pipe';
import { AppStateService } from '@state/app-state.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -9,6 +9,7 @@ import { UserService } from '@services/user.service';
import { NotificationType, NotificationTypeEnum } from '@models/notification-types';
import { notificationsTranslations } from '../../translations/notifications-translations';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { NotificationsService } from '@services/notifications.service';
@Component({
selector: 'redaction-notifications',
@ -23,12 +24,12 @@ export class NotificationsComponent {
constructor(
private readonly _translateService: TranslateService,
private readonly _userService: UserService,
private readonly _notificationControllerService: NotificationControllerService,
private readonly _notificationsService: NotificationsService,
private readonly _appStateService: AppStateService,
private readonly _dossiersService: DossiersService,
private readonly _datePipe: DatePipe,
) {
this._notificationControllerService.getNotifications(false).subscribe((response: NotificationResponse) => {
this._notificationsService.getNotifications(false).subscribe((response: NotificationResponse) => {
this.notifications = response.notifications.filter(notification => this._isSupportedType(notification));
this._groupNotifications(this.notifications);
this.hasUnreadNotifications = this.notifications?.filter(n => !n.readDate).length > 0;
@ -47,7 +48,7 @@ export class NotificationsComponent {
async markRead(notification: Notification, $event, isRead: boolean = true) {
$event.stopPropagation();
const ids = [`${notification.id}`];
await this._notificationControllerService.toggleNotificationRead(ids, isRead).toPromise();
await this._notificationsService.toggleNotificationRead(ids, isRead).toPromise();
if (isRead) {
notification.readDate = moment().format('YYYY-MM-DDTHH:mm:ss Z');
} else {

View File

@ -0,0 +1,32 @@
import { Injectable, Injector } from '@angular/core';
import { GenericService, List, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
import { NotificationResponse } from '@redaction/red-ui-http';
@Injectable({
providedIn: 'root',
})
export class NotificationsService extends GenericService<NotificationResponse> {
constructor(protected readonly _injector: Injector) {
super(_injector, 'notification');
}
@Validate()
getNotifications(@RequiredParam() includeSeen: boolean) {
let queryParam: QueryParam;
if (includeSeen !== undefined && includeSeen !== null) {
queryParam = { key: 'includeSeen', value: includeSeen };
}
return this._getOne([], this._defaultModelPath, [queryParam]);
}
@Validate()
toggleNotificationRead(@RequiredParam() body: List, @RequiredParam() setRead: boolean) {
let queryParam: QueryParam;
if (setRead !== undefined && setRead !== null) {
queryParam = { key: 'setRead', value: setRead };
}
return this._post(body, `${this._defaultModelPath}/toggle-read`, [queryParam]);
}
}

View File

@ -1,31 +0,0 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { Configuration } from './configuration';
import { HttpClient } from '@angular/common/http';
import { NotificationControllerService } from './api/notificationController.service';
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: [NotificationControllerService],
})
export class ApiModule {
constructor(@Optional() @SkipSelf() parentModule: ApiModule, @Optional() http: HttpClient) {
if (parentModule) {
throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
}
if (!http) {
throw new Error(
'You need to import the HttpClientModule in your AppModule! \n' +
'See also https://github.com/angular/angular/issues/20575',
);
}
}
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<any> {
return {
ngModule: ApiModule,
providers: [{ provide: Configuration, useFactory: configurationFactory }],
};
}
}

View File

@ -2,5 +2,4 @@ export * from './api/api';
export * from './model/models';
export * from './variables';
export * from './configuration';
export * from './api.module';
export * from './red-types';