From 41f5cc37bf186c13f760eca67be65cd13c2fa47f Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 22 Oct 2021 00:08:09 +0300 Subject: [PATCH] move notifications to red-domain --- .../notifications/notifications.component.ts | 2 +- .../src/app/models/notification-types.ts | 16 ---------- .../src/app/services/notifications.service.ts | 29 +++++++------------ .../notifications-translations.ts | 26 ++++++++--------- libs/common-ui | 2 +- libs/red-domain/src/index.ts | 1 + .../red-domain/src/lib/notifications/index.ts | 3 ++ .../notification-target.interface.ts | 6 ++++ .../notifications/notification.interface.ts | 14 +++++++++ .../lib/notifications/notification.model.ts | 11 +++---- .../red-domain/src/lib/notifications/types.ts | 16 ++++++++++ libs/red-ui-http/src/lib/model/models.ts | 2 -- .../src/lib/model/notification.model.ts | 24 --------------- .../src/lib/model/notificationResponse.ts | 16 ---------- 14 files changed, 72 insertions(+), 96 deletions(-) delete mode 100644 apps/red-ui/src/app/models/notification-types.ts create mode 100644 libs/red-domain/src/lib/notifications/index.ts create mode 100644 libs/red-domain/src/lib/notifications/notification-target.interface.ts create mode 100644 libs/red-domain/src/lib/notifications/notification.interface.ts rename apps/red-ui/src/app/components/notifications/notification.ts => libs/red-domain/src/lib/notifications/notification.model.ts (78%) create mode 100644 libs/red-domain/src/lib/notifications/types.ts delete mode 100644 libs/red-ui-http/src/lib/model/notification.model.ts delete mode 100644 libs/red-ui-http/src/lib/model/notificationResponse.ts diff --git a/apps/red-ui/src/app/components/notifications/notifications.component.ts b/apps/red-ui/src/app/components/notifications/notifications.component.ts index 931eb9f4d..11a22c6e9 100644 --- a/apps/red-ui/src/app/components/notifications/notifications.component.ts +++ b/apps/red-ui/src/app/components/notifications/notifications.component.ts @@ -5,7 +5,7 @@ import { AppStateService } from '@state/app-state.service'; import { UserService } from '@services/user.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { NotificationsService } from '@services/notifications.service'; -import { Notification } from '@components/notifications/notification'; +import { Notification } from '@red/domain'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { BehaviorSubject, Observable } from 'rxjs'; diff --git a/apps/red-ui/src/app/models/notification-types.ts b/apps/red-ui/src/app/models/notification-types.ts deleted file mode 100644 index b1c7823ac..000000000 --- a/apps/red-ui/src/app/models/notification-types.ts +++ /dev/null @@ -1,16 +0,0 @@ -export enum NotificationTypeEnum { - ASSIGN_REVIEWER = 'ASSIGN_REVIEWER', - ASSIGN_APPROVER = 'ASSIGN_APPROVER', - UNASSIGNED_FROM_FILE = 'UNASSIGNED_FROM_FILE', - DOCUMENT_APPROVED = 'DOCUMENT_APPROVED', - DOSSIER_OWNER_SET = 'DOSSIER_OWNER_SET', - DOSSIER_OWNER_REMOVED = 'DOSSIER_OWNER_REMOVED', - USER_BECOMES_DOSSIER_MEMBER = 'USER_BECOMES_DOSSIER_MEMBER', - DOSSIER_DELETED = 'DOSSIER_DELETED', - USER_REMOVED_AS_DOSSIER_MEMBER = 'USER_REMOVED_AS_DOSSIER_MEMBER', - USER_PROMOTED_TO_APPROVER = 'USER_PROMOTED_TO_APPROVER', - USER_DEGRADED_TO_REVIEWER = 'USER_DEGRADED_TO_REVIEWER', - DOSSIER_OWNER_DELETED = 'DOSSIER_OWNER_DELETED', -} - -export type NotificationType = NotificationTypeEnum; diff --git a/apps/red-ui/src/app/services/notifications.service.ts b/apps/red-ui/src/app/services/notifications.service.ts index 7f90d19b2..16e0f747a 100644 --- a/apps/red-ui/src/app/services/notifications.service.ts +++ b/apps/red-ui/src/app/services/notifications.service.ts @@ -1,21 +1,19 @@ import { Injectable, Injector } from '@angular/core'; import { GenericService, List, mapEach, QueryParam, RequiredParam, Validate } from '@iqser/common-ui'; -import { INotification, NotificationResponse } from '@redaction/red-ui-http'; import * as moment from 'moment'; import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; -import { Notification } from '@components/notifications/notification'; +import { INotification, Notification, NotificationTypes } from '@red/domain'; import { map } from 'rxjs/operators'; import { notificationsTranslations } from '../translations/notifications-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { UserService } from '@services/user.service'; -import { NotificationType, NotificationTypeEnum } from '@models/notification-types'; @Injectable({ providedIn: 'root', }) -export class NotificationsService extends GenericService { +export class NotificationsService extends GenericService { constructor( protected readonly _injector: Injector, private readonly _translateService: TranslateService, @@ -32,16 +30,9 @@ export class NotificationsService extends GenericService { queryParam = { key: 'includeSeen', value: includeSeen }; } - return this._getOne([], this._defaultModelPath, [queryParam]).pipe( - map(response => response.notifications.filter(notification => this._isSupportedType(notification))), - mapEach( - notification => - new Notification( - notification, - this._translate(notification, notificationsTranslations[notification.notificationType]), - this._getTime(notification.creationDate), - ), - ), + return this._getOne<{ notifications: INotification[] }>([], this._defaultModelPath, [queryParam]).pipe( + map(response => response.notifications.filter(n => n.notificationType in NotificationTypes)), + mapEach(notification => this._new(notification)), ); } @@ -55,6 +46,12 @@ export class NotificationsService extends GenericService { return this._post(body, `${this._defaultModelPath}/toggle-read`, [queryParam]); } + private _new(notification: INotification) { + const message = this._translate(notification, notificationsTranslations[notification.notificationType]); + const time = this._getTime(notification.creationDate); + return new Notification(notification, message, time); + } + private _getTime(date: string): string { moment.locale(this._translateService.currentLang); return moment(date).format('hh:mm A'); @@ -78,8 +75,4 @@ export class NotificationsService extends GenericService { private _getUsername(userId: string | undefined) { return this._userService.getNameForId(userId) || this._translateService.instant(_('unknown')); } - - private _isSupportedType(notification: INotification) { - return Object.values(NotificationTypeEnum).includes(notification.notificationType); - } } diff --git a/apps/red-ui/src/app/translations/notifications-translations.ts b/apps/red-ui/src/app/translations/notifications-translations.ts index 4da77e00f..04d9977ea 100644 --- a/apps/red-ui/src/app/translations/notifications-translations.ts +++ b/apps/red-ui/src/app/translations/notifications-translations.ts @@ -1,17 +1,17 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { NotificationType, NotificationTypeEnum } from '@models/notification-types'; +import { NotificationType, NotificationTypes } from '@red/domain'; export const notificationsTranslations: { [key in NotificationType]: string } = { - [NotificationTypeEnum.ASSIGN_APPROVER]: _('notification.assign-approver'), - [NotificationTypeEnum.ASSIGN_REVIEWER]: _('notification.assign-reviewer'), - [NotificationTypeEnum.DOCUMENT_APPROVED]: _('notification.document-approved'), - [NotificationTypeEnum.DOSSIER_OWNER_DELETED]: _('notification.dossier-owner-deleted'), - [NotificationTypeEnum.DOSSIER_OWNER_REMOVED]: _('notification.dossier-owner-removed'), - [NotificationTypeEnum.DOSSIER_OWNER_SET]: _('notification.dossier-owner-set'), - [NotificationTypeEnum.UNASSIGNED_FROM_FILE]: _('notification.unassigned-from-file'), - [NotificationTypeEnum.USER_BECOMES_DOSSIER_MEMBER]: _('notification.user-becomes-dossier-member'), - [NotificationTypeEnum.DOSSIER_DELETED]: _('notification.dossier-deleted'), - [NotificationTypeEnum.USER_DEGRADED_TO_REVIEWER]: _('notification.user-demoted-to-reviewer'), - [NotificationTypeEnum.USER_PROMOTED_TO_APPROVER]: _('notification.user-promoted-to-approver'), - [NotificationTypeEnum.USER_REMOVED_AS_DOSSIER_MEMBER]: _('notification.user-removed-as-dossier-member'), + [NotificationTypes.ASSIGN_APPROVER]: _('notification.assign-approver'), + [NotificationTypes.ASSIGN_REVIEWER]: _('notification.assign-reviewer'), + [NotificationTypes.DOCUMENT_APPROVED]: _('notification.document-approved'), + [NotificationTypes.DOSSIER_OWNER_DELETED]: _('notification.dossier-owner-deleted'), + [NotificationTypes.DOSSIER_OWNER_REMOVED]: _('notification.dossier-owner-removed'), + [NotificationTypes.DOSSIER_OWNER_SET]: _('notification.dossier-owner-set'), + [NotificationTypes.UNASSIGNED_FROM_FILE]: _('notification.unassigned-from-file'), + [NotificationTypes.USER_BECOMES_DOSSIER_MEMBER]: _('notification.user-becomes-dossier-member'), + [NotificationTypes.DOSSIER_DELETED]: _('notification.dossier-deleted'), + [NotificationTypes.USER_DEGRADED_TO_REVIEWER]: _('notification.user-demoted-to-reviewer'), + [NotificationTypes.USER_PROMOTED_TO_APPROVER]: _('notification.user-promoted-to-approver'), + [NotificationTypes.USER_REMOVED_AS_DOSSIER_MEMBER]: _('notification.user-removed-as-dossier-member'), } as const; diff --git a/libs/common-ui b/libs/common-ui index df3a8957c..9461df16f 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit df3a8957c80c89ca4348d4b6b8818e0398c7bf19 +Subproject commit 9461df16f71186ea40b365622900b03d7f7bb387 diff --git a/libs/red-domain/src/index.ts b/libs/red-domain/src/index.ts index c8bc53208..8b393ebc1 100644 --- a/libs/red-domain/src/index.ts +++ b/libs/red-domain/src/index.ts @@ -5,3 +5,4 @@ export * from './lib/dossier-attributes'; export * from './lib/users'; export * from './lib/pages'; export * from './lib/audit'; +export * from './lib/notifications'; diff --git a/libs/red-domain/src/lib/notifications/index.ts b/libs/red-domain/src/lib/notifications/index.ts new file mode 100644 index 000000000..5738aa93a --- /dev/null +++ b/libs/red-domain/src/lib/notifications/index.ts @@ -0,0 +1,3 @@ +export * from './notification.interface'; +export * from './notification.model'; +export * from './types'; diff --git a/libs/red-domain/src/lib/notifications/notification-target.interface.ts b/libs/red-domain/src/lib/notifications/notification-target.interface.ts new file mode 100644 index 000000000..262d32f9f --- /dev/null +++ b/libs/red-domain/src/lib/notifications/notification-target.interface.ts @@ -0,0 +1,6 @@ +export interface INotificationTarget { + fileId: string; + dossierId: string; + + [key: string]: unknown; +} diff --git a/libs/red-domain/src/lib/notifications/notification.interface.ts b/libs/red-domain/src/lib/notifications/notification.interface.ts new file mode 100644 index 000000000..e65021bdf --- /dev/null +++ b/libs/red-domain/src/lib/notifications/notification.interface.ts @@ -0,0 +1,14 @@ +import { INotificationTarget } from './notification-target.interface'; + +export interface INotification { + creationDate: string; + id: string; + issuerId?: string; + notificationDetails?: string; + notificationType: string; + readDate?: string; + seenDate?: string; + softDeleted?: string; + target: INotificationTarget; + userId: string; +} diff --git a/apps/red-ui/src/app/components/notifications/notification.ts b/libs/red-domain/src/lib/notifications/notification.model.ts similarity index 78% rename from apps/red-ui/src/app/components/notifications/notification.ts rename to libs/red-domain/src/lib/notifications/notification.model.ts index dcd879a1d..5423f4563 100644 --- a/apps/red-ui/src/app/components/notifications/notification.ts +++ b/libs/red-domain/src/lib/notifications/notification.model.ts @@ -1,16 +1,17 @@ -import { INotification } from '@redaction/red-ui-http'; import { IListable } from '@iqser/common-ui'; +import { INotification } from './notification.interface'; +import { INotificationTarget } from './notification-target.interface'; export class Notification implements INotification, IListable { - readonly creationDate?: string; + readonly creationDate: string; readonly issuerId?: string; readonly notificationDetails?: string; - readonly notificationType?: string; + readonly notificationType: string; readonly readDate?: string; readonly seenDate?: string; readonly softDeleted?: string; - readonly target?: any; - readonly userId?: string; + readonly target: INotificationTarget; + readonly userId: string; readonly id: string; constructor(notification: INotification, readonly message: string, readonly time: string) { diff --git a/libs/red-domain/src/lib/notifications/types.ts b/libs/red-domain/src/lib/notifications/types.ts new file mode 100644 index 000000000..e9788ca3d --- /dev/null +++ b/libs/red-domain/src/lib/notifications/types.ts @@ -0,0 +1,16 @@ +export const NotificationTypes = { + ASSIGN_REVIEWER: 'ASSIGN_REVIEWER', + ASSIGN_APPROVER: 'ASSIGN_APPROVER', + UNASSIGNED_FROM_FILE: 'UNASSIGNED_FROM_FILE', + DOCUMENT_APPROVED: 'DOCUMENT_APPROVED', + DOSSIER_OWNER_SET: 'DOSSIER_OWNER_SET', + DOSSIER_OWNER_REMOVED: 'DOSSIER_OWNER_REMOVED', + USER_BECOMES_DOSSIER_MEMBER: 'USER_BECOMES_DOSSIER_MEMBER', + DOSSIER_DELETED: 'DOSSIER_DELETED', + USER_REMOVED_AS_DOSSIER_MEMBER: 'USER_REMOVED_AS_DOSSIER_MEMBER', + USER_PROMOTED_TO_APPROVER: 'USER_PROMOTED_TO_APPROVER', + USER_DEGRADED_TO_REVIEWER: 'USER_DEGRADED_TO_REVIEWER', + DOSSIER_OWNER_DELETED: 'DOSSIER_OWNER_DELETED', +} as const; + +export type NotificationType = keyof typeof NotificationTypes; diff --git a/libs/red-ui-http/src/lib/model/models.ts b/libs/red-ui-http/src/lib/model/models.ts index d0851ff00..ac8c3dc45 100644 --- a/libs/red-ui-http/src/lib/model/models.ts +++ b/libs/red-ui-http/src/lib/model/models.ts @@ -30,8 +30,6 @@ export * from './licenseReport'; export * from './licenseReportRequest'; export * from './manualAddResponse'; export * from './manualRedactionEntry'; -export * from './notification.model'; -export * from './notificationResponse'; export * from './placeholdersResponse'; export * from './point'; export * from './prepareDownloadRequest'; diff --git a/libs/red-ui-http/src/lib/model/notification.model.ts b/libs/red-ui-http/src/lib/model/notification.model.ts deleted file mode 100644 index a4712ce1b..000000000 --- a/libs/red-ui-http/src/lib/model/notification.model.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * API Documentation for Redaction Gateway - * Description for redaction - * - * OpenAPI spec version: 1.0 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - -export interface INotification { - creationDate?: string; - id?: string; - issuerId?: string; - notificationDetails?: string; - notificationType?: string; - readDate?: string; - seenDate?: string; - softDeleted?: string; - target?: any; - userId?: string; -} diff --git a/libs/red-ui-http/src/lib/model/notificationResponse.ts b/libs/red-ui-http/src/lib/model/notificationResponse.ts deleted file mode 100644 index 161b9213e..000000000 --- a/libs/red-ui-http/src/lib/model/notificationResponse.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * API Documentation for Redaction Gateway - * Description for redaction - * - * OpenAPI spec version: 1.0 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ -import { INotification } from './notification.model'; - -export interface NotificationResponse { - notifications?: Array; -}