cat-documents-ng 0.1.28 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/ng-package.json +11 -0
  2. package/package.json +20 -25
  3. package/{Shared/constant/ERROR.d.ts → src/Shared/constant/ERROR.ts} +38 -36
  4. package/src/Shared/constant/PERMISSIONS.ts +16 -0
  5. package/src/Shared/constant/SHARED.ts +312 -0
  6. package/{Shared/constant/URLS.d.ts → src/Shared/constant/URLS.ts} +65 -60
  7. package/src/Shared/services/app-config.service.spec.ts +19 -0
  8. package/src/Shared/services/app-config.service.ts +73 -0
  9. package/{Shared/services/global-error.handler.d.ts → src/Shared/services/global-error.handler.ts} +29 -27
  10. package/src/Shared/services/session.service.spec.ts +16 -0
  11. package/src/Shared/services/session.service.ts +76 -0
  12. package/src/assets/config/api.config.json +20 -0
  13. package/src/lib/document/components/document-container/document-container.component.html +14 -0
  14. package/src/lib/document/components/document-container/document-container.component.scss +8 -0
  15. package/src/lib/document/components/document-container/document-container.component.spec.ts +110 -0
  16. package/src/lib/document/components/document-container/document-container.component.ts +173 -0
  17. package/src/lib/document/components/document-list/document-list.component.html +81 -0
  18. package/src/lib/document/components/document-list/document-list.component.scss +82 -0
  19. package/src/lib/document/components/document-list/document-list.component.spec.ts +96 -0
  20. package/src/lib/document/components/document-list/document-list.component.ts +244 -0
  21. package/src/lib/document/components/document-list-item/document-list-item.component.html +36 -0
  22. package/src/lib/document/components/document-list-item/document-list-item.component.scss +34 -0
  23. package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +75 -0
  24. package/src/lib/document/components/document-list-item/document-list-item.component.ts +40 -0
  25. package/src/lib/document/components/document-upload/document-upload.component.html +56 -0
  26. package/src/lib/document/components/document-upload/document-upload.component.scss +32 -0
  27. package/src/lib/document/components/document-upload/document-upload.component.spec.ts +95 -0
  28. package/src/lib/document/components/document-upload/document-upload.component.ts +162 -0
  29. package/src/lib/document/components/document-viewer/document-viewer.component.html +98 -0
  30. package/src/lib/document/components/document-viewer/document-viewer.component.scss +54 -0
  31. package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +79 -0
  32. package/src/lib/document/components/document-viewer/document-viewer.component.ts +106 -0
  33. package/src/lib/document/components/folder-block/folder-block.component.html +46 -0
  34. package/src/lib/document/components/folder-block/folder-block.component.scss +9 -0
  35. package/src/lib/document/components/folder-block/folder-block.component.spec.ts +70 -0
  36. package/{lib/document/components/folder-block/folder-block.component.d.ts → src/lib/document/components/folder-block/folder-block.component.ts} +53 -37
  37. package/src/lib/document/components/folder-container/folder-container.component.html +2 -0
  38. package/src/lib/document/components/folder-container/folder-container.component.scss +0 -0
  39. package/src/lib/document/components/folder-container/folder-container.component.spec.ts +27 -0
  40. package/src/lib/document/components/folder-container/folder-container.component.ts +37 -0
  41. package/src/lib/document/components/linked-document/linked-document.component.html +23 -0
  42. package/src/lib/document/components/linked-document/linked-document.component.scss +10 -0
  43. package/src/lib/document/components/linked-document/linked-document.component.spec.ts +61 -0
  44. package/src/lib/document/components/linked-document/linked-document.component.ts +49 -0
  45. package/src/lib/document/directives/document.directive.ts +32 -0
  46. package/src/lib/document/directives/permission.directive.spec.ts +0 -0
  47. package/src/lib/document/directives/permission.directive.ts +66 -0
  48. package/src/lib/document/document.module.ts +241 -0
  49. package/{lib/document/models/document-alert.model.d.ts → src/lib/document/models/document-alert.model.ts} +45 -38
  50. package/src/lib/document/models/document-type.model.ts +44 -0
  51. package/src/lib/document/models/document.model.ts +53 -0
  52. package/{lib/document/models/folder.model.d.ts → src/lib/document/models/folder.model.ts} +35 -29
  53. package/src/lib/document/services/document-http.service.spec.ts +119 -0
  54. package/src/lib/document/services/document-http.service.ts +125 -0
  55. package/src/lib/document/services/document-upload.service.spec.ts +99 -0
  56. package/src/lib/document/services/document-upload.service.ts +127 -0
  57. package/src/lib/document/services/document.service.ts +29 -0
  58. package/src/lib/document/services/file-format.service.spec.ts +16 -0
  59. package/src/lib/document/services/file-format.service.ts +41 -0
  60. package/src/lib/document/state/document.query.ts +52 -0
  61. package/{lib/document/state/document.service.d.ts → src/lib/document/state/document.service.ts} +95 -64
  62. package/{lib/document/state/document.state.d.ts → src/lib/document/state/document.state.ts} +52 -36
  63. package/src/lib/document/state/document.store.ts +51 -0
  64. package/{public-api.d.ts → src/public-api.ts} +10 -6
  65. package/tsconfig.lib.json +15 -0
  66. package/tsconfig.lib.prod.json +11 -0
  67. package/tsconfig.spec.json +15 -0
  68. package/Shared/constant/PERMISSIONS.d.ts +0 -15
  69. package/Shared/constant/SHARED.d.ts +0 -209
  70. package/Shared/services/app-config.service.d.ts +0 -51
  71. package/Shared/services/session.service.d.ts +0 -46
  72. package/fesm2022/cat-documents-ng.mjs +0 -2538
  73. package/fesm2022/cat-documents-ng.mjs.map +0 -1
  74. package/index.d.ts +0 -5
  75. package/lib/document/components/document-container/document-container.component.d.ts +0 -85
  76. package/lib/document/components/document-list/document-list.component.d.ts +0 -160
  77. package/lib/document/components/document-list-item/document-list-item.component.d.ts +0 -28
  78. package/lib/document/components/document-upload/document-upload.component.d.ts +0 -120
  79. package/lib/document/components/document-viewer/document-viewer.component.d.ts +0 -73
  80. package/lib/document/components/folder-container/folder-container.component.d.ts +0 -29
  81. package/lib/document/components/linked-document/linked-document.component.d.ts +0 -38
  82. package/lib/document/directives/document.directive.d.ts +0 -20
  83. package/lib/document/directives/permission.directive.d.ts +0 -38
  84. package/lib/document/document.module.d.ts +0 -40
  85. package/lib/document/models/document-type.model.d.ts +0 -37
  86. package/lib/document/models/document.model.d.ts +0 -44
  87. package/lib/document/services/document-http.service.d.ts +0 -69
  88. package/lib/document/services/document-upload.service.d.ts +0 -67
  89. package/lib/document/services/document.service.d.ts +0 -20
  90. package/lib/document/services/file-format.service.d.ts +0 -23
  91. package/lib/document/state/document.query.d.ts +0 -42
  92. package/lib/document/state/document.store.d.ts +0 -29
@@ -0,0 +1,125 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { catchError, EMPTY, Observable, tap, throwError } from 'rxjs';
3
+ import { URLS } from '../../../Shared/constant/URLS';
4
+ import { AppConfigService } from '../../../Shared/services/app-config.service';
5
+ import { DocumentStore } from '../state/document.store';
6
+ import { HttpClient } from '@angular/common/http';
7
+ import { DocumentTypeModel } from '../models/document-type.model';
8
+ import { DocumentAlertModel } from '../models/document-alert.model';
9
+ import { DocumentModel } from '../models/document.model';
10
+ import { FolderBlockModel } from '../models/folder.model';
11
+
12
+ /**
13
+ * Service for making HTTP requests related to documents.
14
+ * @class DocumentHttpService
15
+ * @typedef {DocumentHttpService}
16
+ */
17
+ @Injectable({
18
+ providedIn: 'root'
19
+ })
20
+
21
+ export class DocumentHttpService {
22
+
23
+ /**
24
+ * Creates an instance of DocumentService.
25
+ * @param {DocumentStore} documentStore - Store managing the state of documents.
26
+ * @param {HttpClient} http - Angular HTTP client for making API requests.
27
+ * @param {AppConfigService} appConfigService - Service for retrieving application configuration, such as API base URL.
28
+ */
29
+ constructor(
30
+ public documentStore: DocumentStore,
31
+ private http: HttpClient,
32
+ public appConfigService: AppConfigService
33
+ ) { }
34
+
35
+ /**
36
+ * Get api url from appConfigService.
37
+ * @readonly
38
+ * @type {string}
39
+ */
40
+ get apiUrl(): string {
41
+ return this.appConfigService.apiBaseUrl;
42
+ }
43
+
44
+ /**
45
+ * Fetches a document by its path name and transforms the response for dropdown options.
46
+ * Includes error handling for failed API requests.
47
+ * @param {string} contextId - The context ID to fetch the document.
48
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
49
+ */
50
+ getFoldersData(contextId:string | undefined): Observable<FolderBlockModel[]> {
51
+ if(!contextId) return EMPTY;
52
+ return this.http.get<FolderBlockModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}${URLS.FOLDERS}${contextId}`).pipe(
53
+ tap((folders: FolderBlockModel[]) => {
54
+ this.documentStore.setFolders(folders);
55
+ }),
56
+ catchError((error) => {
57
+ return throwError(() => new Error(error));
58
+ })
59
+ );
60
+ }
61
+ /**
62
+ * Fetches a document by its path name and transforms the response for dropdown options.
63
+ * Includes error handling for failed API requests.
64
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
65
+ */
66
+ getDocumentTypes(): Observable<DocumentTypeModel[]> {
67
+ return this.http.get<DocumentTypeModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${URLS.DOCUMENT_TYPES}`).pipe(
68
+ tap((documentTypes: DocumentTypeModel[]) => {
69
+ this.documentStore.setDocumentTypes(documentTypes);
70
+ }),
71
+ catchError((error) => {
72
+ return throwError(() => new Error(error));
73
+ })
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Fetches a document by its path name and transforms the response for dropdown options.
79
+ * @param {string} documentId - The document ID to fetch the document.
80
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
81
+ */
82
+ getAlertsByDocumentID(documentId:string): Observable<DocumentAlertModel> {
83
+ return this.http.get<DocumentAlertModel>(`${this.apiUrl}${URLS.ALERT_BY_DOCUMENT_ID}${documentId}`).pipe(
84
+ tap((documentAlert: DocumentAlertModel) => {
85
+ this.documentStore.setDocumentAlert(documentAlert);
86
+ }),
87
+ catchError((error) => {
88
+ return throwError(() => new Error(error));
89
+ })
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Fetches a document by its folder ID and transforms the response for dropdown options.
95
+ * @param {string} folderId - The folder ID to fetch the document.
96
+ * @param {string} contextId - The context ID to fetch the document.
97
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
98
+ */
99
+ getDocumentByFolderID(folderId:string, contextId:string): Observable<DocumentModel[]> {
100
+ return this.http.get<DocumentModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${URLS.PARENT_DOCUMENT_TYPE_ID}${folderId}${URLS.CONTEXT_ID}${contextId}`).pipe(
101
+ tap((records: DocumentModel[]) => {
102
+ this.documentStore.set(records);
103
+ }),
104
+ catchError((error) => {
105
+ return throwError(() => new Error(error));
106
+ })
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Updates the name of a document.
112
+ * This method sends an HTTP PUT request to update the document's file name using the provided document ID and payload.
113
+ * In case of an error, it will return an observable that throws an Error.
114
+ * @param {string} documentId - The unique identifier of the document to update.
115
+ * @param {any} payload - The payload containing the updated document data (e.g., fileName).
116
+ * @returns {Observable<DocumentModel>} An observable that emits the updated DocumentModel.
117
+ */
118
+ updateDocumentName(documentId: string, payload: any): Observable<DocumentModel> {
119
+ return this.http.put<DocumentModel>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${documentId}`, payload).pipe(
120
+ catchError((error) => {
121
+ return throwError(() => new Error(error));
122
+ })
123
+ );
124
+ }
125
+ }
@@ -0,0 +1,99 @@
1
+ import { fakeAsync, TestBed, tick } from '@angular/core/testing';
2
+ import { DocumentUploadService } from './document-upload.service';
3
+ import { DocumentService } from '../state/document.service';
4
+ import { DocumentStore } from '../state/document.store';
5
+ import { MessageService } from 'primeng/api';
6
+ import { of, throwError } from 'rxjs';
7
+ import { SHARED } from '../../../Shared/constant/SHARED';
8
+
9
+ describe('DocumentUploadService', () => {
10
+ let service: DocumentUploadService;
11
+ let mockDocumentService: jasmine.SpyObj<DocumentService>;
12
+ let mockDocumentStore: jasmine.SpyObj<DocumentStore>;
13
+ let mockMessageService: jasmine.SpyObj<MessageService>;
14
+
15
+ beforeEach(() => {
16
+ mockDocumentService = jasmine.createSpyObj('DocumentService', ['create']);
17
+ mockDocumentStore = jasmine.createSpyObj('DocumentStore', ['setUploadedDocumentFiles', 'setMessage']);
18
+ mockMessageService = jasmine.createSpyObj('MessageService', ['add']);
19
+
20
+ TestBed.configureTestingModule({
21
+ providers: [
22
+ DocumentUploadService,
23
+ { provide: DocumentService, useValue: mockDocumentService },
24
+ { provide: DocumentStore, useValue: mockDocumentStore },
25
+ { provide: MessageService, useValue: mockMessageService }
26
+ ]
27
+ });
28
+
29
+ service = TestBed.inject(DocumentUploadService);
30
+ });
31
+
32
+ it('should be created', () => {
33
+ expect(service).toBeTruthy();
34
+ });
35
+
36
+ it('should set uploadedFile, contextId, docName, and docTypeId when getUploadFileData is called', () => {
37
+ const mockFile = new File(['test content'], 'test.pdf', { type: 'application/pdf' });
38
+ const contextId = '1234';
39
+
40
+ service.getUploadFileData(mockFile, contextId);
41
+
42
+ expect(service.uploadedFile).toBe(mockFile);
43
+ expect(service.contextId).toBe(contextId);
44
+ });
45
+
46
+ it('should set document name and type when getDocumentNameAndType is called', () => {
47
+ const documentName = 'Test Document';
48
+ const documentTypeId = '5678';
49
+
50
+ service.getDocumentNameAndType(documentTypeId);
51
+
52
+ expect(service.docName).toBe(SHARED.EMPTY);
53
+ expect(service.docTypeId).toBe(documentTypeId);
54
+ });
55
+
56
+
57
+
58
+ it('should handle null formData in handleTemplatedUpload', () => {
59
+ const mockFile = new File(['test content'], 'test.pdf', { type: 'application/pdf' });
60
+ const contextId = '1234';
61
+ const documentName = 'Test Document';
62
+ const documentTypeId = '5678';
63
+ service.getUploadFileData(mockFile, contextId);
64
+ service.getDocumentNameAndType(documentTypeId);
65
+ spyOn(service, 'handleCreateFormData').and.returnValue(null);
66
+ service.handleTemplatedUpload();
67
+ expect(mockMessageService.add).toHaveBeenCalledWith({
68
+ severity: 'error',
69
+ summary: 'Form Data Missing',
70
+ detail: 'Required form data is missing. Please ensure the document and all required fields are provided.'
71
+ });
72
+ });
73
+
74
+
75
+ it('should return null from handleCreateFormData if data is incomplete', () => {
76
+ const formData = service.handleCreateFormData();
77
+ expect(formData).toBeNull();
78
+ });
79
+
80
+ it('should call documentService.create and set uploaded files when handleTemplatedUpload is called', () => {
81
+ const mockFile = new File(['test content'], 'test.pdf', { type: 'application/pdf' });
82
+ const contextId = '1234';
83
+ const documentName = 'Test Document';
84
+ const documentTypeId = '5678';
85
+ const formData = new FormData();
86
+ formData.append(SHARED.FILE, mockFile);
87
+
88
+ service.getUploadFileData(mockFile, contextId);
89
+ service.getDocumentNameAndType(documentTypeId);
90
+
91
+ mockDocumentService.create.and.returnValue(of({ fileId: 'abcd1234' }));
92
+
93
+ service.handleTemplatedUpload();
94
+
95
+ expect(mockDocumentService.create).toHaveBeenCalledWith(formData);
96
+ expect(mockDocumentStore.setUploadedDocumentFiles).toHaveBeenCalled();
97
+ });
98
+
99
+ });
@@ -0,0 +1,127 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { SHARED } from '../../../Shared/constant/SHARED';
3
+ import { DocumentService } from '../state/document.service';
4
+ import { DocumentStore } from '../state/document.store';
5
+ import { MessageService } from 'primeng/api';
6
+
7
+ /**
8
+ * Service for handling document uploads.
9
+ * @class DocumentUploadService
10
+ * @typedef {DocumentUploadService}
11
+ */
12
+ @Injectable({
13
+ providedIn: 'root'
14
+ })
15
+ export class DocumentUploadService {
16
+
17
+
18
+ /**
19
+ * The file to upload.
20
+ * @type {*}
21
+ */
22
+ uploadedFile: any;
23
+
24
+ /**
25
+ * Represent contextId
26
+ * @type {string}
27
+ */
28
+ contextId: string = SHARED.EMPTY
29
+
30
+
31
+ /**
32
+ * Represent document name
33
+ * @type {string}
34
+ */
35
+ docName: string = SHARED.EMPTY
36
+
37
+ /**
38
+ * Represent document id
39
+ * @type {string}
40
+ */
41
+ docTypeId: string = SHARED.EMPTY
42
+
43
+ /**
44
+ * Creates an instance of DocumentUploadService.
45
+ * @param {DocumentService} documentService - Service for handling document uploads.
46
+ * @param {DocumentStore} documentUploadStore - Store for managing uploaded documents.
47
+ * @param {MessageService} messageService - Service for displaying messages.
48
+ * @returns {void}
49
+ */
50
+ constructor(public documentService: DocumentService, public documentUploadStore: DocumentStore, public messageService: MessageService) { }
51
+
52
+ /**
53
+ * Prepares the files for upload by creating a FormData object.
54
+ * This method appends each file to the FormData for submission.
55
+ * @returns {void}
56
+ */
57
+ handleTemplatedUpload() {
58
+ let formsData = this.handleCreateFormData()
59
+ if (!formsData) {
60
+ this.messageService.add({severity: SHARED.SEVERITY,summary: SHARED.UPLOAD_ERROR_SUMMERY,detail: SHARED.UPLOAD_ERROR_DETAILS});
61
+ return;
62
+ }
63
+ this.documentService.create(formsData)
64
+ .subscribe({
65
+ /**
66
+ * Handles the successful upload event.
67
+ * Updates the list of uploaded files and emits the file ID.
68
+ * @param {any} event - The event emitted by the upload service on success.
69
+ */
70
+ next: (event) => {
71
+ this.documentUploadStore.setUploadedDocumentFiles(event)
72
+ this.documentUploadStore.setMessage([{
73
+ severity: SHARED.SUCCESS_SEVERITY,
74
+ detail : SHARED.UPLOAD_SUCCESS
75
+ }]);
76
+ },
77
+ /**
78
+ * Handles the error event during file upload.
79
+ * Updates the progress of the file to indicate failure.
80
+ * @param {any} error - The error object returned by the upload service.
81
+ */
82
+ error: (error) => {
83
+ this.documentUploadStore.setMessage([{severity: SHARED.SEVERITY,summary: SHARED.UPLOAD_SUMMERY,detail: error?.message}]);
84
+ },
85
+ });
86
+ }
87
+
88
+ /**
89
+ * Get the file and contextId
90
+ * @param file - The file to upload.
91
+ * @param contextId - The contextId to upload.
92
+ */
93
+ getUploadFileData(file: File, contextId: string) {
94
+ if (file && contextId) {
95
+ this.uploadedFile = file;
96
+ this.contextId = contextId
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Get the document name and document type id
102
+ * @param documentName - The document name to upload.
103
+ * @param documentTypeId - The document type id to upload.
104
+ */
105
+ getDocumentNameAndType(documentTypeId: string) {
106
+ if (documentTypeId) {
107
+ this.docTypeId = documentTypeId
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Handle the creation of formdata.
113
+ * @returns {*} - The formdata object.
114
+ */
115
+ handleCreateFormData() {
116
+ if (this.uploadedFile && this.contextId && this.docTypeId) {
117
+ let formData = new FormData();
118
+ formData.append(SHARED.FILE, this.uploadedFile, this.uploadedFile.name);
119
+ formData.append(SHARED.CONTEXT_ID, this.contextId)
120
+ formData.append(SHARED.DOCUMENT_TYPE_ID, this.docTypeId)
121
+ return formData;
122
+ }else{
123
+ return null;
124
+ }
125
+
126
+ }
127
+ }
@@ -0,0 +1,29 @@
1
+ import { Injectable } from "@angular/core";
2
+ import { BehaviorSubject } from "rxjs";
3
+ import { DocumentModel } from "../models/document.model";
4
+
5
+ /**
6
+ * Service to manage the document data
7
+ */
8
+ @Injectable({
9
+ providedIn: 'root',
10
+ })
11
+ export class DocumentService {
12
+ private documentSubject$ = new BehaviorSubject<DocumentModel | null>(null);
13
+
14
+ /**
15
+ * Set the document data
16
+ * @param document the document data
17
+ */
18
+ set(document: DocumentModel | null) {
19
+ this.documentSubject$.next(document);
20
+ }
21
+
22
+ /**
23
+ * Get the document data
24
+ * @returns the document data
25
+ */
26
+ get() {
27
+ return this.documentSubject$.asObservable();
28
+ }
29
+ }
@@ -0,0 +1,16 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { FileFormatService } from './file-format.service';
4
+
5
+ describe('FileFormatService', () => {
6
+ let service: FileFormatService;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(FileFormatService);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,41 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { SHARED } from '../../../Shared/constant/SHARED';
3
+ import { PrimeNGConfig } from 'primeng/api';
4
+
5
+ /**
6
+ * Description placeholder
7
+ * @class FileFormatService
8
+ * @typedef {FileFormatService}
9
+ */
10
+ @Injectable({
11
+ providedIn: 'root'
12
+ })
13
+ export class FileFormatService {
14
+
15
+ /**
16
+ * Creates an instance of FileFormatService.
17
+ * @constructor
18
+ */
19
+ constructor() { }
20
+
21
+ /**
22
+ * Description placeholder
23
+ * @param {number} bytes
24
+ * @param {PrimeNGConfig} config
25
+ * @returns {string}
26
+ */
27
+ formatFileSize(bytes: number, config:PrimeNGConfig): string {
28
+ const kilobyte = 1024;
29
+ const decimalPlaces = SHARED.ONE;
30
+ const sizes = config.translation.fileSizeTypes || SHARED.FILE_SIZE_UNITS;
31
+ if (bytes < kilobyte) {
32
+ return `${bytes} ${sizes[SHARED.INITIAL_COUNT]}`;
33
+ } else if (bytes < kilobyte * kilobyte) {
34
+ const kbSize = bytes / kilobyte;
35
+ return `${parseFloat(kbSize.toFixed(decimalPlaces))} ${sizes[SHARED.ONE]}`;
36
+ } else {
37
+ const mbSize = bytes / (kilobyte * kilobyte);
38
+ return `${parseFloat(mbSize.toFixed(decimalPlaces))} ${sizes[SHARED.TWO]}`;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,52 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { QueryEntity } from '@datorama/akita';
3
+ import { DocumentStore } from './document.store';
4
+ import { DocumentState } from './document.state';
5
+ import { Observable } from 'rxjs';
6
+ import { Message } from 'primeng/api';
7
+ import { DocumentModel } from '../models/document.model';
8
+
9
+
10
+ /**
11
+ * Query service for managing document state.
12
+ * This class extends Akita's `QueryEntity` to provide additional functionality for querying document data.
13
+ * @class DocumentQuery
14
+ * @typedef {DocumentQuery}
15
+ * @augments {QueryEntity<DocumentState>}
16
+ */
17
+ @Injectable({ providedIn: 'root' })
18
+ export class DocumentQuery extends QueryEntity<DocumentState> {
19
+ constructor(protected override store: DocumentStore) {
20
+ super(store);
21
+ }
22
+
23
+ /**
24
+ * Selects the currently selected folder ID from the document state.
25
+ * @returns {Observable<string | null>} Observable that emits the currently selected folder ID.
26
+ */
27
+ getParentDocumentTypeId() : string | null {
28
+ return this.getValue()['parentDocumentTypeId'];
29
+ }
30
+
31
+ /**
32
+ * Selects the currently selected folder ID from the document state.
33
+ * @returns {Observable<string | null>} Observable that emits the currently selected folder ID.
34
+ */
35
+ selectParentDocumentTypeId():Observable<string | null> {
36
+ return this.select((state) => state['parentDocumentTypeId']);
37
+ }
38
+ /**
39
+ * Selects the set messages.
40
+ * @returns {Observable<Message>} Observable that emits the current Message.
41
+ */
42
+ selectMessages():Observable<Message[]> {
43
+ return this.select((state) => state.messages);
44
+ }
45
+ /**
46
+ * Selects the set documents.
47
+ * @returns {Observable<DocumentModel[]>} Observable that emits the documets.
48
+ */
49
+ selectDocumets():Observable<DocumentModel[]> {
50
+ return this.select((state) => state.documentList);
51
+ }
52
+ }
@@ -1,64 +1,95 @@
1
- import { HttpClient } from '@angular/common/http';
2
- import { DocumentStore } from './document.store';
3
- import { Observable } from 'rxjs';
4
- import { AppConfigService } from '../../../Shared/services/app-config.service';
5
- import { DocumentModel } from '../models/document.model';
6
- import * as i0 from "@angular/core";
7
- /**
8
- * Service for managing document-related operations.
9
- * The `DocumentService` acts as a bridge between the application and the backend API for handling document-related data.
10
- * It interacts with the `DocumentStore` for state management and uses `HttpClient` for making HTTP requests.
11
- * Creates an instance of `DocumentService`.
12
- * @param {DocumentStore} documentStore - The store that manages the state of documents.
13
- * @param {HttpClient} http - The Angular HTTP client for making API requests.
14
- */
15
- export declare class DocumentService {
16
- documentStore: DocumentStore;
17
- private http;
18
- appConfigService: AppConfigService;
19
- /**
20
- * Creates an instance of DocumentService.
21
- * @param {DocumentStore} documentStore - Store managing the state of documents.
22
- * @param {HttpClient} http - Angular HTTP client for making API requests.
23
- * @param {AppConfigService} appConfigService - Service for retrieving application configuration, such as API base URL.
24
- */
25
- constructor(documentStore: DocumentStore, http: HttpClient, appConfigService: AppConfigService);
26
- /**
27
- * Get api url from appConfigService.
28
- * @readonly
29
- * @type {string}
30
- */
31
- get apiUrl(): string;
32
- /**
33
- * Sends a request to create a new document.
34
- * @param {*} entity - The data of the document to be created.
35
- * @returns {Observable<any>} Observable that emits the newly created document.
36
- */
37
- create(entity: any): Observable<any>;
38
- /**
39
- * Fetches all documents from the backend.
40
- * @returns {Observable<DocumentModel[]>} Observable that emits an array of documents.
41
- */
42
- getAll(): Observable<DocumentModel[]>;
43
- /**
44
- * Fetches a document by its ID.
45
- * @param {string} id - The unique identifier of the document.
46
- * @returns {Observable<any>} Observable that emits the retrieved document.
47
- */
48
- getById(id: string): Observable<any>;
49
- /**
50
- * Updates an existing document by its ID.
51
- * @param {string} id - The unique identifier of the document.
52
- * @param {DocumentModel} entity - The updated data of the document.
53
- * @returns {Observable<DocumentModel>} Observable that emits the updated document.
54
- */
55
- update(id: string, entity: DocumentModel): Observable<DocumentModel>;
56
- /**
57
- * Deletes a document by its ID.
58
- * @param {string} id - The unique identifier of the document to be deleted.
59
- * @returns {Observable<void>} Observable that completes when the document is deleted.
60
- */
61
- delete(id: string): Observable<void>;
62
- static ɵfac: i0.ɵɵFactoryDeclaration<DocumentService, never>;
63
- static ɵprov: i0.ɵɵInjectableDeclaration<DocumentService>;
64
- }
1
+ import { Injectable } from '@angular/core';
2
+ import { HttpClient } from '@angular/common/http';
3
+ import { DocumentStore } from './document.store';
4
+ import { Observable, tap } from 'rxjs';
5
+ import { AppConfigService } from '../../../Shared/services/app-config.service';
6
+ import { URLS } from '../../../Shared/constant/URLS';
7
+ import { DocumentModel } from '../models/document.model';
8
+
9
+ /**
10
+ * Service for managing document-related operations.
11
+ * The `DocumentService` acts as a bridge between the application and the backend API for handling document-related data.
12
+ * It interacts with the `DocumentStore` for state management and uses `HttpClient` for making HTTP requests.
13
+ * Creates an instance of `DocumentService`.
14
+ * @param {DocumentStore} documentStore - The store that manages the state of documents.
15
+ * @param {HttpClient} http - The Angular HTTP client for making API requests.
16
+ */
17
+ @Injectable({ providedIn: 'root' })
18
+ export class DocumentService {
19
+
20
+ /**
21
+ * Creates an instance of DocumentService.
22
+ * @param {DocumentStore} documentStore - Store managing the state of documents.
23
+ * @param {HttpClient} http - Angular HTTP client for making API requests.
24
+ * @param {AppConfigService} appConfigService - Service for retrieving application configuration, such as API base URL.
25
+ */
26
+ constructor(
27
+ public documentStore: DocumentStore,
28
+ private http: HttpClient,
29
+ public appConfigService: AppConfigService
30
+ ) { }
31
+
32
+ /**
33
+ * Get api url from appConfigService.
34
+ * @readonly
35
+ * @type {string}
36
+ */
37
+ get apiUrl(): string {
38
+ return this.appConfigService.apiBaseUrl;
39
+ }
40
+
41
+ /**
42
+ * Sends a request to create a new document.
43
+ * @param {*} entity - The data of the document to be created.
44
+ * @returns {Observable<any>} Observable that emits the newly created document.
45
+ */
46
+ create(entity: any): Observable<any> {
47
+ return this.http.post<any>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}`, entity).pipe(
48
+ tap((newEntity: any) => this.documentStore.add(newEntity))
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Fetches all documents from the backend.
54
+ * @returns {Observable<DocumentModel[]>} Observable that emits an array of documents.
55
+ */
56
+ getAll(): Observable<DocumentModel[]> {
57
+ return this.http.get<DocumentModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}`).pipe(
58
+ tap((entities: DocumentModel[]) => this.documentStore.set(entities))
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Fetches a document by its ID.
64
+ * @param {string} id - The unique identifier of the document.
65
+ * @returns {Observable<any>} Observable that emits the retrieved document.
66
+ */
67
+ getById(id: string): Observable<any> {
68
+ return this.http.get<any>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`).pipe(
69
+ tap((entity: any) => this.documentStore.upsert(id, entity))
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Updates an existing document by its ID.
75
+ * @param {string} id - The unique identifier of the document.
76
+ * @param {DocumentModel} entity - The updated data of the document.
77
+ * @returns {Observable<DocumentModel>} Observable that emits the updated document.
78
+ */
79
+ update(id: string, entity: DocumentModel): Observable<DocumentModel> {
80
+ return this.http.put<DocumentModel>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`, entity).pipe(
81
+ tap((updatedEntity: DocumentModel) => this.documentStore.update(id, updatedEntity))
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Deletes a document by its ID.
87
+ * @param {string} id - The unique identifier of the document to be deleted.
88
+ * @returns {Observable<void>} Observable that completes when the document is deleted.
89
+ */
90
+ delete(id: string): Observable<void> {
91
+ return this.http.delete<void>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`).pipe(
92
+ tap(() => this.documentStore.remove(id))
93
+ );
94
+ }
95
+ }