move notifications to red-domain

This commit is contained in:
Dan Percic 2021-10-22 00:08:09 +03:00
parent 1784141b62
commit 41f5cc37bf
14 changed files with 72 additions and 96 deletions

View File

@ -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';

View File

@ -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;

View File

@ -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<NotificationResponse> {
export class NotificationsService extends GenericService<unknown> {
constructor(
protected readonly _injector: Injector,
private readonly _translateService: TranslateService,
@ -32,16 +30,9 @@ export class NotificationsService extends GenericService<NotificationResponse> {
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<NotificationResponse> {
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<NotificationResponse> {
private _getUsername(userId: string | undefined) {
return this._userService.getNameForId(userId) || this._translateService.instant(_('unknown'));
}
private _isSupportedType(notification: INotification) {
return Object.values(NotificationTypeEnum).includes(<NotificationType>notification.notificationType);
}
}

View File

@ -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;

@ -1 +1 @@
Subproject commit df3a8957c80c89ca4348d4b6b8818e0398c7bf19
Subproject commit 9461df16f71186ea40b365622900b03d7f7bb387

View File

@ -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';

View File

@ -0,0 +1,3 @@
export * from './notification.interface';
export * from './notification.model';
export * from './types';

View File

@ -0,0 +1,6 @@
export interface INotificationTarget {
fileId: string;
dossierId: string;
[key: string]: unknown;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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';

View File

@ -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;
}

View File

@ -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<INotification>;
}