@neohm/nestend 3.3.6 → 3.3.8

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 (116) hide show
  1. package/README.md +69 -11
  2. package/dist/admin/controllers/admin.tenant.user.controller.js +1 -1
  3. package/dist/admin/controllers/admin.tenant.user.controller.js.map +1 -1
  4. package/dist/admin/libraries/bulk.user.data.processor.js +1 -1
  5. package/dist/admin/libraries/bulk.user.data.processor.js.map +1 -1
  6. package/dist/admin/libraries/client.user.data.processor.js +1 -1
  7. package/dist/admin/libraries/client.user.data.processor.js.map +1 -1
  8. package/dist/admin/libraries/tenant.delete.processor.js +1 -1
  9. package/dist/admin/libraries/tenant.delete.processor.js.map +1 -1
  10. package/dist/auth/controllers/auth.controller.d.ts +1 -0
  11. package/dist/auth/controllers/auth.controller.d.ts.map +1 -1
  12. package/dist/auth/controllers/auth.controller.js +5 -1
  13. package/dist/auth/controllers/auth.controller.js.map +1 -1
  14. package/dist/auth/entities/user.entity.d.ts +2 -2
  15. package/dist/auth/entities/user.entity.d.ts.map +1 -1
  16. package/dist/auth/entities/user.entity.js +3 -3
  17. package/dist/auth/entities/user.entity.js.map +1 -1
  18. package/dist/auth/enums/tenant.role.enum.d.ts +4 -0
  19. package/dist/auth/enums/tenant.role.enum.d.ts.map +1 -0
  20. package/dist/auth/enums/tenant.role.enum.js +8 -0
  21. package/dist/auth/enums/tenant.role.enum.js.map +1 -0
  22. package/dist/auth/services/auth.service.d.ts +1 -0
  23. package/dist/auth/services/auth.service.d.ts.map +1 -1
  24. package/dist/auth/services/auth.service.js +8 -2
  25. package/dist/auth/services/auth.service.js.map +1 -1
  26. package/dist/auth/services/impersonation.service.js +1 -1
  27. package/dist/auth/services/impersonation.service.js.map +1 -1
  28. package/dist/auth/types/auth.types.d.ts +1 -0
  29. package/dist/auth/types/auth.types.d.ts.map +1 -1
  30. package/dist/common/enums/queue.enum.d.ts +9 -0
  31. package/dist/common/enums/queue.enum.d.ts.map +1 -1
  32. package/dist/common/enums/queue.enum.js +11 -1
  33. package/dist/common/enums/queue.enum.js.map +1 -1
  34. package/dist/common/queue.module.d.ts.map +1 -1
  35. package/dist/common/queue.module.js +1 -1
  36. package/dist/common/queue.module.js.map +1 -1
  37. package/dist/common/services/queue.service.d.ts +1 -0
  38. package/dist/common/services/queue.service.d.ts.map +1 -1
  39. package/dist/common/services/queue.service.js +15 -0
  40. package/dist/common/services/queue.service.js.map +1 -1
  41. package/dist/common/subscribers/common.subscriber.d.ts +3 -5
  42. package/dist/common/subscribers/common.subscriber.d.ts.map +1 -1
  43. package/dist/common/subscribers/common.subscriber.js +13 -25
  44. package/dist/common/subscribers/common.subscriber.js.map +1 -1
  45. package/dist/constants/entity.constants.d.ts +1 -0
  46. package/dist/constants/entity.constants.d.ts.map +1 -1
  47. package/dist/constants/entity.constants.js +1 -0
  48. package/dist/constants/entity.constants.js.map +1 -1
  49. package/dist/constants/entity.maps.d.ts +3 -1
  50. package/dist/constants/entity.maps.d.ts.map +1 -1
  51. package/dist/constants/entity.maps.js +3 -1
  52. package/dist/constants/entity.maps.js.map +1 -1
  53. package/dist/document/controllers/document.controller.d.ts +15 -0
  54. package/dist/document/controllers/document.controller.d.ts.map +1 -0
  55. package/dist/document/controllers/document.controller.js +88 -0
  56. package/dist/document/controllers/document.controller.js.map +1 -0
  57. package/dist/document/document.module.d.ts.map +1 -1
  58. package/dist/document/document.module.js +23 -1
  59. package/dist/document/document.module.js.map +1 -1
  60. package/dist/document/dtos/set.document.dto.d.ts +6 -0
  61. package/dist/document/dtos/set.document.dto.d.ts.map +1 -0
  62. package/dist/document/dtos/set.document.dto.js +43 -0
  63. package/dist/document/dtos/set.document.dto.js.map +1 -0
  64. package/dist/document/dtos/upload.document.dto.d.ts +4 -0
  65. package/dist/document/dtos/upload.document.dto.d.ts.map +1 -0
  66. package/dist/document/dtos/upload.document.dto.js +31 -0
  67. package/dist/document/dtos/upload.document.dto.js.map +1 -0
  68. package/dist/document/entities/document.entity.d.ts +10 -0
  69. package/dist/document/entities/document.entity.d.ts.map +1 -0
  70. package/dist/document/entities/document.entity.js +43 -0
  71. package/dist/document/entities/document.entity.js.map +1 -0
  72. package/dist/{common/entities/document.entity.d.ts → document/entities/document.upload.entity.d.ts} +6 -7
  73. package/dist/document/entities/document.upload.entity.d.ts.map +1 -0
  74. package/dist/{common/entities/document.entity.js → document/entities/document.upload.entity.js} +24 -28
  75. package/dist/document/entities/document.upload.entity.js.map +1 -0
  76. package/dist/document/enums/document.default.enum.d.ts +8 -1
  77. package/dist/document/enums/document.default.enum.d.ts.map +1 -1
  78. package/dist/document/enums/document.default.enum.js +9 -1
  79. package/dist/document/enums/document.default.enum.js.map +1 -1
  80. package/dist/document/es6.classes.d.ts +8 -3
  81. package/dist/document/es6.classes.d.ts.map +1 -1
  82. package/dist/document/es6.classes.js +8 -3
  83. package/dist/document/es6.classes.js.map +1 -1
  84. package/dist/document/services/document.service.d.ts +17 -11
  85. package/dist/document/services/document.service.d.ts.map +1 -1
  86. package/dist/document/services/document.service.js +91 -50
  87. package/dist/document/services/document.service.js.map +1 -1
  88. package/dist/document/subscribers/document.subscriber.d.ts +9 -0
  89. package/dist/document/subscribers/document.subscriber.d.ts.map +1 -0
  90. package/dist/document/subscribers/document.subscriber.js +31 -0
  91. package/dist/document/subscribers/document.subscriber.js.map +1 -0
  92. package/dist/document/subscribers/document.upload.subscriber.d.ts +9 -0
  93. package/dist/document/subscribers/document.upload.subscriber.d.ts.map +1 -0
  94. package/dist/document/subscribers/document.upload.subscriber.js +31 -0
  95. package/dist/document/subscribers/document.upload.subscriber.js.map +1 -0
  96. package/dist/document/types/document.types.d.ts +0 -11
  97. package/dist/document/types/document.types.d.ts.map +1 -1
  98. package/dist/index.d.ts +6 -3
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +11 -4
  101. package/dist/index.js.map +1 -1
  102. package/dist/migrations/{1749600000013.CreateSysDocumentDetailsTable.d.ts → 1749600000013.CreateSysDocumentUploadsTable.d.ts} +2 -2
  103. package/dist/migrations/1749600000013.CreateSysDocumentUploadsTable.d.ts.map +1 -0
  104. package/dist/migrations/{1749600000013.CreateSysDocumentDetailsTable.js → 1749600000013.CreateSysDocumentUploadsTable.js} +9 -10
  105. package/dist/migrations/1749600000013.CreateSysDocumentUploadsTable.js.map +1 -0
  106. package/dist/migrations/1749600000028.CreateSysDocumentsTable.d.ts +6 -0
  107. package/dist/migrations/1749600000028.CreateSysDocumentsTable.d.ts.map +1 -0
  108. package/dist/migrations/1749600000028.CreateSysDocumentsTable.js +29 -0
  109. package/dist/migrations/1749600000028.CreateSysDocumentsTable.js.map +1 -0
  110. package/dist/tenant/entities/tenant.entity.js +3 -3
  111. package/dist/tenant/entities/tenant.entity.js.map +1 -1
  112. package/package.json +1 -1
  113. package/dist/common/entities/document.entity.d.ts.map +0 -1
  114. package/dist/common/entities/document.entity.js.map +0 -1
  115. package/dist/migrations/1749600000013.CreateSysDocumentDetailsTable.d.ts.map +0 -1
  116. package/dist/migrations/1749600000013.CreateSysDocumentDetailsTable.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.document.dto.js","sourceRoot":"","sources":["../../../src/document/dtos/set.document.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA0E;AAC1E,6CAA8C;AAG9C,MAAa,cAAc;CAsB1B;AAtBD,wCAsBC;AAfC;IANC,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,0CAA0C;KACxD,CAAC;IACD,IAAA,wBAAM,GAAE;IACR,IAAA,4BAAU,GAAE;;iDACK;AASlB;IAPC,IAAA,qBAAW,EAAC;QACX,OAAO,EAAE,SAAS;QAClB,WAAW,EAAE,qBAAqB;KACnC,CAAC;IACD,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,EAAC,GAAG,CAAC;;mDACK;AAKpB;IAHC,IAAA,qBAAW,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;IACnE,IAAA,wBAAM,GAAE;IACR,IAAA,4BAAU,GAAE;;iDACK"}
@@ -0,0 +1,4 @@
1
+ export declare class UploadDocumentDto {
2
+ path_identifier: string;
3
+ }
4
+ //# sourceMappingURL=upload.document.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.document.dto.d.ts","sourceRoot":"","sources":["../../../src/document/dtos/upload.document.dto.ts"],"names":[],"mappings":"AAOA,qBAAa,iBAAiB;IAa5B,eAAe,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UploadDocumentDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ const swagger_1 = require("@nestjs/swagger");
15
+ class UploadDocumentDto {
16
+ }
17
+ exports.UploadDocumentDto = UploadDocumentDto;
18
+ __decorate([
19
+ (0, swagger_1.ApiProperty)({
20
+ example: 'invoice',
21
+ description: 'Names the destination: the key prefix is read from the "document.path.<path_identifier>" system property.',
22
+ }),
23
+ (0, class_validator_1.IsString)(),
24
+ (0, class_validator_1.IsNotEmpty)(),
25
+ (0, class_validator_1.MaxLength)(100),
26
+ (0, class_validator_1.Matches)(/^[a-z0-9._-]+$/, {
27
+ message: 'path_identifier may only contain lowercase letters, digits, dots, hyphens and underscores',
28
+ }),
29
+ __metadata("design:type", String)
30
+ ], UploadDocumentDto.prototype, "path_identifier", void 0);
31
+ //# sourceMappingURL=upload.document.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.document.dto.js","sourceRoot":"","sources":["../../../src/document/dtos/upload.document.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA2E;AAC3E,6CAA8C;AAM9C,MAAa,iBAAiB;CAc7B;AAdD,8CAcC;AADC;IAZC,IAAA,qBAAW,EAAC;QACX,OAAO,EAAE,SAAS;QAClB,WAAW,EACT,2GAA2G;KAC9G,CAAC;IACD,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,EAAC,GAAG,CAAC;IACd,IAAA,yBAAO,EAAC,gBAAgB,EAAE;QACzB,OAAO,EACL,2FAA2F;KAC9F,CAAC;;0DACsB"}
@@ -0,0 +1,10 @@
1
+ import { CommonEntity } from '../../common/entities/common.entity';
2
+ import { DocumentUploadEntity } from './document.upload.entity';
3
+ export declare class DocumentEntity extends CommonEntity {
4
+ upload_id: string;
5
+ source_type: string;
6
+ source_id: string;
7
+ attributes: Record<string, any>;
8
+ upload: DocumentUploadEntity;
9
+ }
10
+ //# sourceMappingURL=document.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.entity.d.ts","sourceRoot":"","sources":["../../../src/document/entities/document.entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,qBACa,cAAe,SAAQ,YAAY;IAE9C,SAAS,EAAE,MAAM,CAAC;IAGlB,WAAW,EAAE,MAAM,CAAC;IAGpB,SAAS,EAAE,MAAM,CAAC;IAGlB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAKhC,MAAM,EAAE,oBAAoB,CAAC;CAC9B"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DocumentEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const common_entity_1 = require("../../common/entities/common.entity");
15
+ const document_upload_entity_1 = require("./document.upload.entity");
16
+ let DocumentEntity = class DocumentEntity extends common_entity_1.CommonEntity {
17
+ };
18
+ exports.DocumentEntity = DocumentEntity;
19
+ __decorate([
20
+ (0, typeorm_1.Column)({ type: 'uuid' }),
21
+ __metadata("design:type", String)
22
+ ], DocumentEntity.prototype, "upload_id", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)({ type: 'varchar' }),
25
+ __metadata("design:type", String)
26
+ ], DocumentEntity.prototype, "source_type", void 0);
27
+ __decorate([
28
+ (0, typeorm_1.Column)({ type: 'uuid' }),
29
+ __metadata("design:type", String)
30
+ ], DocumentEntity.prototype, "source_id", void 0);
31
+ __decorate([
32
+ (0, typeorm_1.Column)({ type: 'jsonb' }),
33
+ __metadata("design:type", Object)
34
+ ], DocumentEntity.prototype, "attributes", void 0);
35
+ __decorate([
36
+ (0, typeorm_1.ManyToOne)(() => document_upload_entity_1.DocumentUploadEntity, { onDelete: 'CASCADE' }),
37
+ (0, typeorm_1.JoinColumn)({ name: 'upload_id' }),
38
+ __metadata("design:type", document_upload_entity_1.DocumentUploadEntity)
39
+ ], DocumentEntity.prototype, "upload", void 0);
40
+ exports.DocumentEntity = DocumentEntity = __decorate([
41
+ (0, typeorm_1.Entity)({ name: 'sys_documents' })
42
+ ], DocumentEntity);
43
+ //# sourceMappingURL=document.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.entity.js","sourceRoot":"","sources":["../../../src/document/entities/document.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgE;AAChE,uEAAmE;AACnE,qEAAgE;AAIzD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,4BAAY;CAiB/C,CAAA;AAjBY,wCAAc;AAEzB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDACP;AAGlB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;mDACR;AAGpB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDACP;AAGlB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;kDACM;AAKhC;IAFC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,6CAAoB,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC9D,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;8BAC1B,6CAAoB;8CAAC;yBAhBlB,cAAc;IAD1B,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;GACrB,cAAc,CAiB1B"}
@@ -1,14 +1,13 @@
1
- import { CommonEntity } from './common.entity';
2
- export declare class DocumentEntity extends CommonEntity {
3
- source_id: string;
4
- size_bytes: number;
5
- is_public: boolean;
1
+ import { CommonEntity } from '../../common/entities/common.entity';
2
+ export declare class DocumentUploadEntity extends CommonEntity {
6
3
  original_name: string;
7
4
  stored_name: string;
8
5
  mime_type: string;
6
+ size_bytes: number;
9
7
  storage_driver: string;
10
8
  path: string;
11
- source_type: string;
9
+ url: string;
10
+ is_public: boolean;
12
11
  attributes: Record<string, any>;
13
12
  }
14
- //# sourceMappingURL=document.entity.d.ts.map
13
+ //# sourceMappingURL=document.upload.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.upload.entity.d.ts","sourceRoot":"","sources":["../../../src/document/entities/document.upload.entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAGnE,qBACa,oBAAqB,SAAQ,YAAY;IAEpD,aAAa,EAAE,MAAM,CAAC;IAGtB,WAAW,EAAE,MAAM,CAAC;IAGpB,SAAS,EAAE,MAAM,CAAC;IAGlB,UAAU,EAAE,MAAM,CAAC;IAGnB,cAAc,EAAE,MAAM,CAAC;IAGvB,IAAI,EAAE,MAAM,CAAC;IAIb,GAAG,EAAE,MAAM,CAAC;IAGZ,SAAS,EAAE,OAAO,CAAC;IAGnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC"}
@@ -9,53 +9,49 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DocumentEntity = void 0;
12
+ exports.DocumentUploadEntity = void 0;
13
13
  const typeorm_1 = require("typeorm");
14
- const common_entity_1 = require("./common.entity");
15
- let DocumentEntity = class DocumentEntity extends common_entity_1.CommonEntity {
14
+ const common_entity_1 = require("../../common/entities/common.entity");
15
+ let DocumentUploadEntity = class DocumentUploadEntity extends common_entity_1.CommonEntity {
16
16
  };
17
- exports.DocumentEntity = DocumentEntity;
18
- __decorate([
19
- (0, typeorm_1.Column)({ type: 'uuid' }),
20
- __metadata("design:type", String)
21
- ], DocumentEntity.prototype, "source_id", void 0);
22
- __decorate([
23
- (0, typeorm_1.Column)({ type: 'bigint' }),
24
- __metadata("design:type", Number)
25
- ], DocumentEntity.prototype, "size_bytes", void 0);
26
- __decorate([
27
- (0, typeorm_1.Column)({ type: 'boolean', default: false }),
28
- __metadata("design:type", Boolean)
29
- ], DocumentEntity.prototype, "is_public", void 0);
17
+ exports.DocumentUploadEntity = DocumentUploadEntity;
30
18
  __decorate([
31
19
  (0, typeorm_1.Column)({ type: 'varchar' }),
32
20
  __metadata("design:type", String)
33
- ], DocumentEntity.prototype, "original_name", void 0);
21
+ ], DocumentUploadEntity.prototype, "original_name", void 0);
34
22
  __decorate([
35
23
  (0, typeorm_1.Column)({ type: 'varchar' }),
36
24
  __metadata("design:type", String)
37
- ], DocumentEntity.prototype, "stored_name", void 0);
25
+ ], DocumentUploadEntity.prototype, "stored_name", void 0);
38
26
  __decorate([
39
27
  (0, typeorm_1.Column)({ type: 'varchar' }),
40
28
  __metadata("design:type", String)
41
- ], DocumentEntity.prototype, "mime_type", void 0);
29
+ ], DocumentUploadEntity.prototype, "mime_type", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ type: 'bigint' }),
32
+ __metadata("design:type", Number)
33
+ ], DocumentUploadEntity.prototype, "size_bytes", void 0);
42
34
  __decorate([
43
35
  (0, typeorm_1.Column)({ type: 'varchar' }),
44
36
  __metadata("design:type", String)
45
- ], DocumentEntity.prototype, "storage_driver", void 0);
37
+ ], DocumentUploadEntity.prototype, "storage_driver", void 0);
46
38
  __decorate([
47
39
  (0, typeorm_1.Column)({ type: 'text' }),
48
40
  __metadata("design:type", String)
49
- ], DocumentEntity.prototype, "path", void 0);
41
+ ], DocumentUploadEntity.prototype, "path", void 0);
50
42
  __decorate([
51
- (0, typeorm_1.Column)({ type: 'varchar' }),
43
+ (0, typeorm_1.Column)({ type: 'text' }),
52
44
  __metadata("design:type", String)
53
- ], DocumentEntity.prototype, "source_type", void 0);
45
+ ], DocumentUploadEntity.prototype, "url", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.Column)({ type: 'boolean', default: false }),
48
+ __metadata("design:type", Boolean)
49
+ ], DocumentUploadEntity.prototype, "is_public", void 0);
54
50
  __decorate([
55
51
  (0, typeorm_1.Column)({ type: 'jsonb' }),
56
52
  __metadata("design:type", Object)
57
- ], DocumentEntity.prototype, "attributes", void 0);
58
- exports.DocumentEntity = DocumentEntity = __decorate([
59
- (0, typeorm_1.Entity)({ name: 'sys_document_details' })
60
- ], DocumentEntity);
61
- //# sourceMappingURL=document.entity.js.map
53
+ ], DocumentUploadEntity.prototype, "attributes", void 0);
54
+ exports.DocumentUploadEntity = DocumentUploadEntity = __decorate([
55
+ (0, typeorm_1.Entity)({ name: 'sys_document_uploads' })
56
+ ], DocumentUploadEntity);
57
+ //# sourceMappingURL=document.upload.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.upload.entity.js","sourceRoot":"","sources":["../../../src/document/entities/document.upload.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyC;AACzC,uEAAmE;AAI5D,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,4BAAY;CA4BrD,CAAA;AA5BY,oDAAoB;AAE/B;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;2DACN;AAGtB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;yDACR;AAGpB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uDACV;AAGlB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;wDACR;AAGnB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;4DACL;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kDACZ;AAIb;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDACb;AAGZ;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;uDACzB;AAGnB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;wDACM;+BA3BrB,oBAAoB;IADhC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;GAC5B,oBAAoB,CA4BhC"}
@@ -1,4 +1,11 @@
1
1
  export declare enum DocumentDefault {
2
- PRESIGNED_URL_EXPIRY_SECONDS = 3600
2
+ PRESIGNED_URL_EXPIRY_SECONDS = 3600,
3
+ MAX_UPLOAD_FILES = 10,
4
+ MAX_UPLOAD_SIZE_MB = 25,
5
+ BYTES_PER_MB = 1048576
6
+ }
7
+ export declare enum DocumentConstant {
8
+ UPLOAD_FIELD_NAME = "files",
9
+ PATH_PROPERTY_PREFIX = "document.path."
3
10
  }
4
11
  //# sourceMappingURL=document.default.enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.default.enum.d.ts","sourceRoot":"","sources":["../../../src/document/enums/document.default.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,4BAA4B,OAAO;CACpC"}
1
+ {"version":3,"file":"document.default.enum.d.ts","sourceRoot":"","sources":["../../../src/document/enums/document.default.enum.ts"],"names":[],"mappings":"AACA,oBAAY,eAAe;IACzB,4BAA4B,OAAO;IAEnC,gBAAgB,KAAK;IAErB,kBAAkB,KAAK;IACvB,YAAY,UAAU;CACvB;AAGD,oBAAY,gBAAgB;IAE1B,iBAAiB,UAAU;IAE3B,oBAAoB,mBAAmB;CACxC"}
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentDefault = void 0;
3
+ exports.DocumentConstant = exports.DocumentDefault = void 0;
4
4
  var DocumentDefault;
5
5
  (function (DocumentDefault) {
6
6
  DocumentDefault[DocumentDefault["PRESIGNED_URL_EXPIRY_SECONDS"] = 3600] = "PRESIGNED_URL_EXPIRY_SECONDS";
7
+ DocumentDefault[DocumentDefault["MAX_UPLOAD_FILES"] = 10] = "MAX_UPLOAD_FILES";
8
+ DocumentDefault[DocumentDefault["MAX_UPLOAD_SIZE_MB"] = 25] = "MAX_UPLOAD_SIZE_MB";
9
+ DocumentDefault[DocumentDefault["BYTES_PER_MB"] = 1048576] = "BYTES_PER_MB";
7
10
  })(DocumentDefault || (exports.DocumentDefault = DocumentDefault = {}));
11
+ var DocumentConstant;
12
+ (function (DocumentConstant) {
13
+ DocumentConstant["UPLOAD_FIELD_NAME"] = "files";
14
+ DocumentConstant["PATH_PROPERTY_PREFIX"] = "document.path.";
15
+ })(DocumentConstant || (exports.DocumentConstant = DocumentConstant = {}));
8
16
  //# sourceMappingURL=document.default.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.default.enum.js","sourceRoot":"","sources":["../../../src/document/enums/document.default.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAEX;AAFD,WAAY,eAAe;IACzB,wGAAmC,CAAA;AACrC,CAAC,EAFW,eAAe,+BAAf,eAAe,QAE1B"}
1
+ {"version":3,"file":"document.default.enum.js","sourceRoot":"","sources":["../../../src/document/enums/document.default.enum.ts"],"names":[],"mappings":";;;AACA,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,wGAAmC,CAAA;IAEnC,8EAAqB,CAAA;IAErB,kFAAuB,CAAA;IACvB,2EAAsB,CAAA;AACxB,CAAC,EAPW,eAAe,+BAAf,eAAe,QAO1B;AAGD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAE1B,+CAA2B,CAAA;IAE3B,2DAAuC,CAAA;AACzC,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B"}
@@ -1,13 +1,18 @@
1
+ import { DocumentController } from './controllers/document.controller';
1
2
  import { DocumentService } from './services/document.service';
2
3
  import { MinioBucketDocumentService } from './services/minio.bucket.document.service';
3
4
  import { PdfService } from './services/pdf.service';
4
5
  import { S3BucketDocumentService } from './services/s3.bucket.document.service';
6
+ import { DocumentSubscriber } from './subscribers/document.subscriber';
7
+ import { DocumentUploadSubscriber } from './subscribers/document.upload.subscriber';
8
+ import { SetDocumentDto } from './dtos/set.document.dto';
9
+ import { UploadDocumentDto } from './dtos/upload.document.dto';
5
10
  export declare const es6Classes: {
6
- controllers: any[];
11
+ controllers: (typeof DocumentController)[];
7
12
  services: readonly [typeof DocumentService, typeof MinioBucketDocumentService, typeof S3BucketDocumentService, typeof PdfService];
8
13
  libraries: any[];
9
- dtos: any[];
14
+ dtos: (typeof SetDocumentDto | typeof UploadDocumentDto)[];
10
15
  jobs: any[];
11
- subscribers: any[];
16
+ subscribers: readonly [typeof DocumentSubscriber, typeof DocumentUploadSubscriber];
12
17
  };
13
18
  //# sourceMappingURL=es6.classes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"es6.classes.d.ts","sourceRoot":"","sources":["../../src/document/es6.classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,eAAO,MAAM,UAAU;;;;;;;CAYtB,CAAC"}
1
+ {"version":3,"file":"es6.classes.d.ts","sourceRoot":"","sources":["../../src/document/es6.classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,eAAO,MAAM,UAAU;;;;;;;CAYtB,CAAC"}
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.es6Classes = void 0;
4
+ const document_controller_1 = require("./controllers/document.controller");
4
5
  const document_service_1 = require("./services/document.service");
5
6
  const minio_bucket_document_service_1 = require("./services/minio.bucket.document.service");
6
7
  const pdf_service_1 = require("./services/pdf.service");
7
8
  const s3_bucket_document_service_1 = require("./services/s3.bucket.document.service");
9
+ const document_subscriber_1 = require("./subscribers/document.subscriber");
10
+ const document_upload_subscriber_1 = require("./subscribers/document.upload.subscriber");
11
+ const set_document_dto_1 = require("./dtos/set.document.dto");
12
+ const upload_document_dto_1 = require("./dtos/upload.document.dto");
8
13
  exports.es6Classes = {
9
- controllers: [],
14
+ controllers: [document_controller_1.DocumentController],
10
15
  services: [
11
16
  document_service_1.DocumentService,
12
17
  minio_bucket_document_service_1.MinioBucketDocumentService,
@@ -14,8 +19,8 @@ exports.es6Classes = {
14
19
  pdf_service_1.PdfService,
15
20
  ],
16
21
  libraries: [],
17
- dtos: [],
22
+ dtos: [set_document_dto_1.SetDocumentDto, upload_document_dto_1.UploadDocumentDto],
18
23
  jobs: [],
19
- subscribers: [],
24
+ subscribers: [document_subscriber_1.DocumentSubscriber, document_upload_subscriber_1.DocumentUploadSubscriber],
20
25
  };
21
26
  //# sourceMappingURL=es6.classes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"es6.classes.js","sourceRoot":"","sources":["../../src/document/es6.classes.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAC9D,4FAAsF;AACtF,wDAAoD;AACpD,sFAAgF;AAEnE,QAAA,UAAU,GAAG;IACxB,WAAW,EAAE,EAAE;IACf,QAAQ,EAAE;QACR,kCAAe;QACf,0DAA0B;QAC1B,oDAAuB;QACvB,wBAAU;KACF;IACV,SAAS,EAAE,EAAE;IACb,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,WAAW,EAAE,EAAE;CAChB,CAAC"}
1
+ {"version":3,"file":"es6.classes.js","sourceRoot":"","sources":["../../src/document/es6.classes.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,kEAA8D;AAC9D,4FAAsF;AACtF,wDAAoD;AACpD,sFAAgF;AAChF,2EAAuE;AACvE,yFAAoF;AACpF,8DAAyD;AACzD,oEAA+D;AAElD,QAAA,UAAU,GAAG;IACxB,WAAW,EAAE,CAAC,wCAAkB,CAAC;IACjC,QAAQ,EAAE;QACR,kCAAe;QACf,0DAA0B;QAC1B,oDAAuB;QACvB,wBAAU;KACF;IACV,SAAS,EAAE,EAAE;IACb,IAAI,EAAE,CAAC,iCAAc,EAAE,uCAAiB,CAAC;IACzC,IAAI,EAAE,EAAE;IACR,WAAW,EAAE,CAAC,wCAAkB,EAAE,qDAAwB,CAAU;CACrE,CAAC"}
@@ -1,32 +1,38 @@
1
1
  import { Logger } from '@nestjs/common';
2
2
  import { Readable } from 'stream';
3
3
  import { DataSource } from 'typeorm';
4
- import { DocumentEntity } from '../../common/entities/document.entity';
4
+ import { SetDocumentDto } from '../dtos/set.document.dto';
5
+ import { DocumentEntity } from '../entities/document.entity';
6
+ import { DocumentUploadEntity } from '../entities/document.upload.entity';
7
+ import { SystemPropertyService } from '../../common/services/system.property.service';
5
8
  import { MinioBucketDocumentService } from './minio.bucket.document.service';
6
9
  import { S3BucketDocumentService } from './s3.bucket.document.service';
7
- import { BucketDocumentStorage, DocumentLinkOptions, PresignedUrlOptions, StoredDocument, UploadDocumentOptions, UploadableFile } from '../types/document.types';
10
+ import { BucketDocumentStorage, DocumentLinkOptions, PresignedUrlOptions, UploadDocumentOptions, UploadableFile } from '../types/document.types';
8
11
  export declare class DocumentService {
9
12
  private readonly s3BucketDocumentService;
10
13
  private readonly minioBucketDocumentService;
14
+ private readonly systemPropertyService;
11
15
  private readonly dataSource;
12
16
  protected readonly logger: Logger;
13
- constructor(s3BucketDocumentService: S3BucketDocumentService, minioBucketDocumentService: MinioBucketDocumentService, dataSource: DataSource);
17
+ constructor(s3BucketDocumentService: S3BucketDocumentService, minioBucketDocumentService: MinioBucketDocumentService, systemPropertyService: SystemPropertyService, dataSource: DataSource);
18
+ resolvePathPrefix(pathIdentifier: string): Promise<string>;
19
+ assertUploadable(files: UploadableFile[]): void;
14
20
  uploadDocument(files: UploadableFile[], options?: UploadDocumentOptions): Promise<string[]>;
15
- uploadDocuments(files: UploadableFile[], options?: UploadDocumentOptions): Promise<StoredDocument[]>;
16
- uploadSingleDocument(file: UploadableFile, options?: UploadDocumentOptions): Promise<StoredDocument>;
17
- persistDocumentRecord(storedDocument: StoredDocument, options: Pick<UploadDocumentOptions, 'createdBy' | 'sourceType' | 'sourceId' | 'isPublic'>): Promise<DocumentEntity>;
18
- deleteDocument(documentUuid: string, options?: {
19
- hard?: boolean;
20
- }): Promise<void>;
21
- getDocumentLink(document: DocumentEntity, options?: DocumentLinkOptions): Promise<string>;
21
+ uploadDocuments(files: UploadableFile[], options?: UploadDocumentOptions): Promise<DocumentUploadEntity[]>;
22
+ uploadSingleDocument(file: UploadableFile, options?: UploadDocumentOptions): Promise<DocumentUploadEntity>;
23
+ setDocument(dto: SetDocumentDto): Promise<DocumentEntity>;
24
+ deleteUpload(uploadUuid: string): Promise<void>;
25
+ getDocumentLink(upload: DocumentUploadEntity, options?: DocumentLinkOptions): Promise<string>;
22
26
  getPresignedUrl(objectPath: string, options?: PresignedUrlOptions): Promise<string>;
23
27
  documentExists(objectPath: string): Promise<boolean>;
24
- getDocumentStream(document: DocumentEntity): Promise<Readable>;
28
+ getDocumentStream(upload: DocumentUploadEntity): Promise<Readable>;
25
29
  findDocumentsBySource(sourceType: string, sourceId: string): Promise<DocumentEntity[]>;
26
30
  getActiveStorage(): BucketDocumentStorage;
27
31
  getStorageByDriver(driver: string): BucketDocumentStorage;
28
32
  generateStoredName(originalName: string): string;
33
+ private envNumber;
29
34
  private buildObjectPath;
30
35
  private get documentRepository();
36
+ private get uploadRepository();
31
37
  }
32
38
  //# sourceMappingURL=document.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.service.d.ts","sourceRoot":"","sources":["../../../src/document/services/document.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAKvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAOjC,qBACa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAL7B,SAAS,CAAC,QAAQ,CAAC,MAAM,SAAoC;gBAG1C,uBAAuB,EAAE,uBAAuB,EAChD,0BAA0B,EAAE,0BAA0B,EACtD,UAAU,EAAE,UAAU;IAInC,cAAc,CAClB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,MAAM,EAAE,CAAC;IAMd,eAAe,CACnB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,cAAc,EAAE,CAAC;IAMtB,oBAAoB,CACxB,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,cAAc,CAAC;IAsBpB,qBAAqB,CACzB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,IAAI,CACX,qBAAqB,EACrB,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,CACrD,GACA,OAAO,CAAC,cAAc,CAAC;IAuBpB,cAAc,CAClB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,OAAO,CAAC,IAAI,CAAC;IAgBV,eAAe,CACnB,QAAQ,EAAE,cAAc,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC;IAOZ,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC;IAIZ,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpD,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAM9D,qBAAqB,CACzB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,EAAE,CAAC;IAQ5B,gBAAgB,IAAI,qBAAqB;IAOzC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAezD,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAOhD,OAAO,CAAC,eAAe;IAKvB,OAAO,KAAK,kBAAkB,GAE7B;CACF"}
1
+ {"version":3,"file":"document.service.d.ts","sourceRoot":"","sources":["../../../src/document/services/document.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAItF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAKvE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAOjC,qBACa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN7B,SAAS,CAAC,QAAQ,CAAC,MAAM,SAAoC;gBAG1C,uBAAuB,EAAE,uBAAuB,EAChD,0BAA0B,EAAE,0BAA0B,EACtD,qBAAqB,EAAE,qBAAqB,EAC5C,UAAU,EAAE,UAAU;IASnC,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBhE,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI;IA4BzC,cAAc,CAClB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,MAAM,EAAE,CAAC;IAMd,eAAe,CACnB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAW5B,oBAAoB,CACxB,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,CAAC;IA6B1B,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IA2BzD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB/C,eAAe,CACnB,MAAM,EAAE,oBAAoB,EAC5B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC;IAQZ,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC;IAIZ,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpD,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOlE,qBAAqB,CACzB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,EAAE,CAAC;IAS5B,gBAAgB,IAAI,qBAAqB;IAOzC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAezD,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAOhD,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,eAAe;IAKvB,OAAO,KAAK,kBAAkB,GAE7B;IAED,OAAO,KAAK,gBAAgB,GAE3B;CACF"}
@@ -15,23 +15,48 @@ const common_1 = require("@nestjs/common");
15
15
  const crypto_1 = require("crypto");
16
16
  const path_1 = require("path");
17
17
  const typeorm_1 = require("typeorm");
18
- const document_entity_1 = require("../../common/entities/document.entity");
18
+ const document_entity_1 = require("../entities/document.entity");
19
+ const document_upload_entity_1 = require("../entities/document.upload.entity");
19
20
  const storage_driver_enum_1 = require("../../common/enums/storage.driver.enum");
21
+ const system_property_service_1 = require("../../common/services/system.property.service");
20
22
  const bad_request_exception_1 = require("../../global/exceptions/bad.request.exception");
21
23
  const not_found_exception_1 = require("../../global/exceptions/not.found.exception");
22
24
  const operation_exception_1 = require("../../global/exceptions/operation.exception");
23
25
  const minio_bucket_document_service_1 = require("./minio.bucket.document.service");
24
26
  const s3_bucket_document_service_1 = require("./s3.bucket.document.service");
27
+ const document_default_enum_1 = require("../enums/document.default.enum");
25
28
  let DocumentService = DocumentService_1 = class DocumentService {
26
- constructor(s3BucketDocumentService, minioBucketDocumentService, dataSource) {
29
+ constructor(s3BucketDocumentService, minioBucketDocumentService, systemPropertyService, dataSource) {
27
30
  this.s3BucketDocumentService = s3BucketDocumentService;
28
31
  this.minioBucketDocumentService = minioBucketDocumentService;
32
+ this.systemPropertyService = systemPropertyService;
29
33
  this.dataSource = dataSource;
30
34
  this.logger = new common_1.Logger(DocumentService_1.name);
31
35
  }
36
+ async resolvePathPrefix(pathIdentifier) {
37
+ const property = `${document_default_enum_1.DocumentConstant.PATH_PROPERTY_PREFIX}${pathIdentifier}`;
38
+ const pathPrefix = await this.systemPropertyService.get(property);
39
+ if (!pathPrefix)
40
+ throw new bad_request_exception_1.BadRequestException(`Unknown path_identifier "${pathIdentifier}": system property "${property}" is not set.`);
41
+ if (!/^(?!.*\.\.)[a-zA-Z0-9][a-zA-Z0-9._\-/]*$/.test(pathPrefix))
42
+ throw new operation_exception_1.OperationException(`System property "${property}" is not a usable key prefix.`);
43
+ return pathPrefix;
44
+ }
45
+ assertUploadable(files) {
46
+ if (!files?.length)
47
+ throw new bad_request_exception_1.BadRequestException(`At least one file is required under the "${document_default_enum_1.DocumentConstant.UPLOAD_FIELD_NAME}" field.`);
48
+ const maxFiles = this.envNumber('DOCUMENT_MAX_UPLOAD_FILES', document_default_enum_1.DocumentDefault.MAX_UPLOAD_FILES);
49
+ if (files.length > maxFiles)
50
+ throw new bad_request_exception_1.BadRequestException(`At most ${maxFiles} files can be uploaded at once.`);
51
+ const maxSizeMb = this.envNumber('DOCUMENT_MAX_UPLOAD_SIZE_MB', document_default_enum_1.DocumentDefault.MAX_UPLOAD_SIZE_MB);
52
+ const maxBytes = maxSizeMb * document_default_enum_1.DocumentDefault.BYTES_PER_MB;
53
+ const oversized = files.find((file) => file.size > maxBytes);
54
+ if (oversized)
55
+ throw new bad_request_exception_1.BadRequestException(`"${oversized.originalname}" exceeds the ${maxSizeMb} MB per-file limit.`);
56
+ }
32
57
  async uploadDocument(files, options) {
33
- const storedDocuments = await this.uploadDocuments(files, options);
34
- return storedDocuments.map((storedDocument) => storedDocument.link);
58
+ const uploads = await this.uploadDocuments(files, options);
59
+ return Promise.all(uploads.map((upload) => this.getDocumentLink(upload)));
35
60
  }
36
61
  async uploadDocuments(files, options) {
37
62
  return Promise.all(files.map((file) => this.uploadSingleDocument(file, options)));
@@ -40,54 +65,61 @@ let DocumentService = DocumentService_1 = class DocumentService {
40
65
  const storage = this.getActiveStorage();
41
66
  const storedName = this.generateStoredName(file.originalname);
42
67
  const objectPath = this.buildObjectPath(storedName, options?.pathPrefix);
43
- const link = await storage.upload(objectPath, file.buffer, file.mimetype);
44
- const storedDocument = {
45
- link,
68
+ const url = await storage.upload(objectPath, file.buffer, file.mimetype);
69
+ const upload = await this.uploadRepository.save(this.uploadRepository.create({
70
+ original_name: file.originalname,
71
+ stored_name: storedName,
72
+ mime_type: file.mimetype,
73
+ size_bytes: file.size,
74
+ storage_driver: storage.driver,
46
75
  path: objectPath,
47
- storedName,
48
- originalName: file.originalname,
49
- mimeType: file.mimetype,
50
- sizeBytes: file.size,
51
- storageDriver: storage.driver,
52
- };
53
- if (options?.persist)
54
- await this.persistDocumentRecord(storedDocument, options);
55
- return storedDocument;
56
- }
57
- async persistDocumentRecord(storedDocument, options) {
58
- if (!options.createdBy || !options.sourceType || !options.sourceId) {
59
- throw new bad_request_exception_1.BadRequestException('Persisting a document record requires createdBy, sourceType and sourceId options.');
60
- }
61
- return this.documentRepository.save(this.documentRepository.create({
62
- original_name: storedDocument.originalName,
63
- stored_name: storedDocument.storedName,
64
- mime_type: storedDocument.mimeType,
65
- size_bytes: storedDocument.sizeBytes,
66
- storage_driver: storedDocument.storageDriver,
67
- path: storedDocument.path,
68
- is_public: options.isPublic ?? false,
69
- source_type: options.sourceType,
70
- source_id: options.sourceId,
71
- created_by: options.createdBy,
76
+ url,
77
+ is_public: options?.isPublic ?? false,
72
78
  }));
79
+ if (options?.sourceType && options?.sourceId)
80
+ await this.setDocument({
81
+ upload_id: upload.id,
82
+ source_type: options.sourceType,
83
+ source_id: options.sourceId,
84
+ });
85
+ return upload;
86
+ }
87
+ async setDocument(dto) {
88
+ const upload = await this.uploadRepository.findOne({
89
+ where: { id: dto.upload_id },
90
+ });
91
+ if (!upload)
92
+ throw new not_found_exception_1.NotFoundException(`Upload "${dto.upload_id}" was not found.`);
93
+ const existing = await this.documentRepository.findOne({
94
+ where: {
95
+ upload_id: dto.upload_id,
96
+ source_type: dto.source_type,
97
+ source_id: dto.source_id,
98
+ },
99
+ });
100
+ if (existing)
101
+ return existing;
102
+ return this.documentRepository.save(this.documentRepository.create({ ...dto }));
73
103
  }
74
- async deleteDocument(documentUuid, options) {
75
- const document = await this.documentRepository.findOne({
76
- where: { id: documentUuid },
104
+ async deleteUpload(uploadUuid) {
105
+ const upload = await this.uploadRepository.findOne({
106
+ where: { id: uploadUuid },
107
+ });
108
+ if (!upload)
109
+ throw new not_found_exception_1.NotFoundException(`Upload "${uploadUuid}" was not found.`);
110
+ const attachedCount = await this.documentRepository.count({
111
+ where: { upload_id: uploadUuid },
112
+ withDeleted: true,
77
113
  });
78
- if (!document)
79
- throw new not_found_exception_1.NotFoundException(`Document "${documentUuid}" was not found.`);
80
- await this.getStorageByDriver(document.storage_driver).delete(document.path);
81
- if (options?.hard)
82
- await this.documentRepository.delete({ id: documentUuid });
83
- else
84
- await this.documentRepository.softDelete({ id: documentUuid });
85
- }
86
- async getDocumentLink(document, options) {
87
- const storage = this.getStorageByDriver(document.storage_driver);
88
- if (document.is_public && !options?.signed)
89
- return storage.getPublicUrl(document.path);
90
- return storage.getPresignedUrl(document.path, options);
114
+ if (attachedCount)
115
+ throw new operation_exception_1.OperationException(`Upload "${uploadUuid}" is attached to ${attachedCount} document record(s) and cannot be deleted.`);
116
+ await this.getStorageByDriver(upload.storage_driver).delete(upload.path);
117
+ await this.uploadRepository.softDelete({ id: uploadUuid });
118
+ }
119
+ async getDocumentLink(upload, options) {
120
+ if (upload.is_public && !options?.signed)
121
+ return upload.url;
122
+ return this.getStorageByDriver(upload.storage_driver).getPresignedUrl(upload.path, options);
91
123
  }
92
124
  async getPresignedUrl(objectPath, options) {
93
125
  return this.getActiveStorage().getPresignedUrl(objectPath, options);
@@ -95,12 +127,13 @@ let DocumentService = DocumentService_1 = class DocumentService {
95
127
  async documentExists(objectPath) {
96
128
  return this.getActiveStorage().exists(objectPath);
97
129
  }
98
- async getDocumentStream(document) {
99
- return this.getStorageByDriver(document.storage_driver).getStream(document.path);
130
+ async getDocumentStream(upload) {
131
+ return this.getStorageByDriver(upload.storage_driver).getStream(upload.path);
100
132
  }
101
133
  async findDocumentsBySource(sourceType, sourceId) {
102
134
  return this.documentRepository.find({
103
135
  where: { source_type: sourceType, source_id: sourceId },
136
+ relations: { upload: true },
104
137
  order: { created_at: 'DESC' },
105
138
  });
106
139
  }
@@ -126,6 +159,10 @@ let DocumentService = DocumentService_1 = class DocumentService {
126
159
  .replace(/[^.a-z0-9]/g, '');
127
160
  return `${(0, crypto_1.randomUUID)()}${extension}`;
128
161
  }
162
+ envNumber(variable, fallback) {
163
+ const parsed = Number(process.env[variable]);
164
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
165
+ }
129
166
  buildObjectPath(storedName, pathPrefix) {
130
167
  if (!pathPrefix)
131
168
  return storedName;
@@ -134,12 +171,16 @@ let DocumentService = DocumentService_1 = class DocumentService {
134
171
  get documentRepository() {
135
172
  return this.dataSource.getRepository(document_entity_1.DocumentEntity);
136
173
  }
174
+ get uploadRepository() {
175
+ return this.dataSource.getRepository(document_upload_entity_1.DocumentUploadEntity);
176
+ }
137
177
  };
138
178
  exports.DocumentService = DocumentService;
139
179
  exports.DocumentService = DocumentService = DocumentService_1 = __decorate([
140
180
  (0, common_1.Injectable)(),
141
181
  __metadata("design:paramtypes", [s3_bucket_document_service_1.S3BucketDocumentService,
142
182
  minio_bucket_document_service_1.MinioBucketDocumentService,
183
+ system_property_service_1.SystemPropertyService,
143
184
  typeorm_1.DataSource])
144
185
  ], DocumentService);
145
186
  //# sourceMappingURL=document.service.js.map