red-ui/libs/red-domain/src/lib/dossiers/dossier.model.ts
2021-10-21 14:31:59 +03:00

99 lines
3.6 KiB
TypeScript

import { File } from '@models/file/file';
import { IDictionary } from '@redaction/red-ui-http';
import { IListable, List } from '@iqser/common-ui';
import { IDossier } from './dossier.interface';
import { DossierStatus } from './types';
import { DownloadFileType } from '../shared/types';
export class Dossier implements IDossier, IListable {
readonly dossierId: string;
readonly dossierTemplateId: string;
readonly ownerId: string;
readonly memberIds: List;
readonly approverIds: List;
readonly reportTemplateIds: List;
readonly dossierName: string;
readonly date: string;
readonly dueDate?: string;
readonly description?: string;
readonly downloadFileTypes?: List<DownloadFileType>;
readonly hardDeletedTime?: string;
readonly softDeletedTime?: string;
readonly startDate?: string;
readonly status: DossierStatus;
readonly watermarkEnabled: boolean;
readonly hasReviewers: boolean;
readonly reanalysisRequired = this.files.some(file => file.analysisRequired);
readonly hasFiles = this.files.length > 0;
readonly filesLength = this.files.length;
readonly totalNumberOfPages: number;
readonly hintsOnly: boolean;
readonly hasRedactions: boolean;
readonly hasSuggestions: boolean;
readonly hasNone: boolean;
readonly hasPendingOrProcessing: boolean;
constructor(dossier: IDossier, readonly files: List<File> = [], public type?: IDictionary) {
this.dossierId = dossier.dossierId;
this.approverIds = dossier.approverIds;
this.date = dossier.date;
this.description = dossier.description;
this.dossierName = dossier.dossierName;
this.dossierTemplateId = dossier.dossierTemplateId;
this.downloadFileTypes = dossier.downloadFileTypes;
this.dueDate = dossier.dueDate;
this.hardDeletedTime = dossier.hardDeletedTime;
this.memberIds = dossier.memberIds;
this.ownerId = dossier.ownerId;
this.reportTemplateIds = dossier.reportTemplateIds;
this.softDeletedTime = dossier.softDeletedTime;
this.startDate = dossier.startDate;
this.status = dossier.status;
this.watermarkEnabled = dossier.watermarkEnabled;
this.hasReviewers = !!this.memberIds && this.memberIds.length > 1;
let hintsOnly = false;
let hasRedactions = false;
let hasSuggestions = false;
let totalNumberOfPages = 0;
let hasPendingOrProcessing = false;
this.files.forEach(f => {
hintsOnly = hintsOnly || f.hintsOnly;
hasRedactions = hasRedactions || f.hasRedactions;
hasSuggestions = hasSuggestions || f.hasSuggestions;
totalNumberOfPages += f.numberOfPages ?? 0;
hasPendingOrProcessing = hasPendingOrProcessing || f.isPending || f.isProcessing;
});
this.hintsOnly = hintsOnly;
this.hasRedactions = hasRedactions;
this.hasSuggestions = hasSuggestions;
this.totalNumberOfPages = totalNumberOfPages;
this.hasPendingOrProcessing = hasPendingOrProcessing;
this.hasNone = !this.hasSuggestions && !this.hasRedactions && !this.hintsOnly;
}
get id(): string {
return this.dossierId;
}
get routerLink(): string {
return `/main/dossiers/${this.dossierId}`;
}
get searchKey(): string {
return this.dossierName;
}
hasStatus(status: string): boolean {
return !!this.files.find(f => f.status === status);
}
hasMember(memberId: string): boolean {
return !!this.memberIds && this.memberIds.indexOf(memberId) >= 0;
}
}