underpost 2.8.878 → 2.8.881

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 (49) hide show
  1. package/.env.development +35 -3
  2. package/.env.production +40 -3
  3. package/.env.test +35 -3
  4. package/.github/workflows/release.cd.yml +2 -1
  5. package/README.md +44 -36
  6. package/bin/deploy.js +40 -0
  7. package/cli.md +88 -86
  8. package/conf.js +28 -3
  9. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  10. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  11. package/package.json +1 -2
  12. package/src/api/document/document.controller.js +66 -0
  13. package/src/api/document/document.model.js +51 -0
  14. package/src/api/document/document.router.js +24 -0
  15. package/src/api/document/document.service.js +125 -0
  16. package/src/cli/deploy.js +1 -1
  17. package/src/cli/index.js +2 -0
  18. package/src/cli/run.js +27 -1
  19. package/src/client/Default.index.js +46 -1
  20. package/src/client/components/core/Account.js +8 -1
  21. package/src/client/components/core/AgGrid.js +18 -9
  22. package/src/client/components/core/BtnIcon.js +3 -2
  23. package/src/client/components/core/Content.js +2 -1
  24. package/src/client/components/core/CssCore.js +4 -0
  25. package/src/client/components/core/Docs.js +0 -3
  26. package/src/client/components/core/Input.js +34 -19
  27. package/src/client/components/core/Modal.js +29 -7
  28. package/src/client/components/core/ObjectLayerEngine.js +370 -0
  29. package/src/client/components/core/ObjectLayerEngineModal.js +1 -0
  30. package/src/client/components/core/Panel.js +7 -2
  31. package/src/client/components/core/PanelForm.js +187 -63
  32. package/src/client/components/core/VanillaJs.js +3 -0
  33. package/src/client/components/default/MenuDefault.js +94 -41
  34. package/src/client/components/default/RoutesDefault.js +2 -0
  35. package/src/client/services/default/default.management.js +1 -0
  36. package/src/client/services/document/document.service.js +97 -0
  37. package/src/client/services/file/file.service.js +2 -0
  38. package/src/client/ssr/Render.js +1 -1
  39. package/src/client/ssr/head/DefaultScripts.js +2 -0
  40. package/src/client/ssr/head/Seo.js +1 -0
  41. package/src/index.js +1 -1
  42. package/src/mailer/EmailRender.js +1 -1
  43. package/src/server/client-build.js +2 -3
  44. package/src/server/client-formatted.js +40 -12
  45. package/src/server/conf.js +5 -1
  46. package/src/server/object-layer.js +196 -0
  47. package/src/server/runtime.js +10 -13
  48. package/src/server/ssr.js +52 -10
  49. package/src/server/valkey.js +89 -1
package/cli.md CHANGED
@@ -1,46 +1,47 @@
1
- ## underpost ci/cd cli v2.8.878
1
+ ## underpost ci/cd cli v2.8.881
2
2
 
3
3
  ### Usage: `underpost [options] [command]`
4
- ```
5
- Options:
6
- -V, --version output the version number
7
- -h, --help display help for command
4
+
5
+ ```
6
+ Options:
7
+ -V, --version output the version number
8
+ -h, --help display help for command
8
9
 
9
10
  Commands:
10
- new [options] <app-name> Initializes a new Underpost project with a predefined structure.
11
- start [options] <deploy-id> [env] Initiates application servers, build pipelines, or other defined services based on the deployment ID.
12
- clone [options] <uri> Clones a specified GitHub repository into the current directory.
13
- pull [options] <path> <uri> Pulls the latest changes from a specified GitHub repository.
14
- cmt [options] <path> <commit-type> [module-tag] [message] Manages commits to a GitHub repository, supporting various commit types and options.
15
- push [options] <path> <uri> Pushes committed changes from a local repository to a remote GitHub repository.
16
- env <deploy-id> [env] Sets environment variables and configurations related to a specific deployment ID.
17
- config [options] <operator> [key] [value] Manages Underpost configurations using various operators.
18
- root Displays the root path of the npm installation.
19
- cluster [options] [pod-name] Manages Kubernetes clusters, defaulting to Kind cluster initialization.
20
- deploy [options] [deploy-list] [env] Manages application deployments, defaulting to deploying development pods.
21
- secret [options] <platform> Manages secrets for various platforms.
22
- dockerfile-image-build [options] Builds a Docker image from a specified Dockerfile with various options for naming, saving, and loading.
23
- dockerfile-pull-base-images [options] Pulls required Underpost Dockerfile base images and optionally loads them into clusters.
24
- install Quickly imports Underpost npm dependencies by copying them.
25
- db [options] <deploy-list> Manages database operations, including import, export, and collection management.
26
- metadata [options] [deploy-id] [host] [path] Manages cluster metadata operations, including import and export.
27
- script [options] <operator> <script-name> [script-value] Supports a variety of built-in Underpost global scripts, their preset lifecycle events, and arbitrary custom scripts.
28
- cron [options] [deploy-list] [job-list] Manages cron jobs, including initialization, execution, and configuration updates.
29
- fs [options] [path] Manages file storage, defaulting to file upload operations.
30
- test [options] [deploy-list] Manages and runs tests, defaulting to the current Underpost default test suite.
31
- monitor [options] <deploy-id> [env] Manages health server monitoring for specified deployments.
32
- ssh [options] Import and start ssh server and client based on current default deployment ID.
33
- run [options] <runner-id> [path] Runs a script from the specified path.
34
- lxd [options] Manages LXD containers and virtual machines.
35
- baremetal [options] [workflow-id] [hostname] [ip-address] Manages baremetal server operations, including installation, database setup, commissioning, and user management.
36
- help [command] display help for command
37
-
11
+ new [options] <app-name> Initializes a new Underpost project with a predefined structure.
12
+ start [options] <deploy-id> [env] Initiates application servers, build pipelines, or other defined services based on the deployment ID.
13
+ clone [options] <uri> Clones a specified GitHub repository into the current directory.
14
+ pull [options] <path> <uri> Pulls the latest changes from a specified GitHub repository.
15
+ cmt [options] <path> <commit-type> [module-tag] [message] Manages commits to a GitHub repository, supporting various commit types and options.
16
+ push [options] <path> <uri> Pushes committed changes from a local repository to a remote GitHub repository.
17
+ env <deploy-id> [env] Sets environment variables and configurations related to a specific deployment ID.
18
+ config [options] <operator> [key] [value] Manages Underpost configurations using various operators.
19
+ root Displays the root path of the npm installation.
20
+ cluster [options] [pod-name] Manages Kubernetes clusters, defaulting to Kind cluster initialization.
21
+ deploy [options] [deploy-list] [env] Manages application deployments, defaulting to deploying development pods.
22
+ secret [options] <platform> Manages secrets for various platforms.
23
+ dockerfile-image-build [options] Builds a Docker image from a specified Dockerfile with various options for naming, saving, and loading.
24
+ dockerfile-pull-base-images [options] Pulls required Underpost Dockerfile base images and optionally loads them into clusters.
25
+ install Quickly imports Underpost npm dependencies by copying them.
26
+ db [options] <deploy-list> Manages database operations, including import, export, and collection management.
27
+ metadata [options] [deploy-id] [host] [path] Manages cluster metadata operations, including import and export.
28
+ script [options] <operator> <script-name> [script-value] Supports a variety of built-in Underpost global scripts, their preset lifecycle events, and arbitrary custom scripts.
29
+ cron [options] [deploy-list] [job-list] Manages cron jobs, including initialization, execution, and configuration updates.
30
+ fs [options] [path] Manages file storage, defaulting to file upload operations.
31
+ test [options] [deploy-list] Manages and runs tests, defaulting to the current Underpost default test suite.
32
+ monitor [options] <deploy-id> [env] Manages health server monitoring for specified deployments.
33
+ ssh [options] Import and start ssh server and client based on current default deployment ID.
34
+ run [options] <runner-id> [path] Runs a script from the specified path.
35
+ lxd [options] Manages LXD containers and virtual machines.
36
+ baremetal [options] [workflow-id] [hostname] [ip-address] Manages baremetal server operations, including installation, database setup, commissioning, and user management.
37
+ help [command] display help for command
38
+
38
39
  ```
39
40
 
40
41
  ## Commands:
41
-
42
42
 
43
43
  ### `new` :
44
+
44
45
  ```
45
46
  Usage: underpost new [options] <app-name>
46
47
 
@@ -54,11 +55,11 @@ Options:
54
55
  --cluster Create deploy ID cluster files and sync to current cluster
55
56
  --dev Sets the development cli context
56
57
  -h, --help display help for command
57
-
58
+
58
59
  ```
59
-
60
60
 
61
61
  ### `start` :
62
+
62
63
  ```
63
64
  Usage: underpost start [options] <deploy-id> [env]
64
65
 
@@ -74,11 +75,11 @@ Options:
74
75
  --run Starts application servers and monitors their health.
75
76
  --build Triggers the client-side application build process.
76
77
  -h, --help display help for command
77
-
78
+
78
79
  ```
79
-
80
80
 
81
81
  ### `clone` :
82
+
82
83
  ```
83
84
  Usage: underpost clone [options] <uri>
84
85
 
@@ -91,11 +92,11 @@ Options:
91
92
  --bare Performs a bare clone, downloading only the .git files.
92
93
  -g8 Uses the g8 repository extension for cloning.
93
94
  -h, --help display help for command
94
-
95
+
95
96
  ```
96
-
97
97
 
98
98
  ### `pull` :
99
+
99
100
  ```
100
101
  Usage: underpost pull [options] <path> <uri>
101
102
 
@@ -109,11 +110,11 @@ Arguments:
109
110
  Options:
110
111
  -g8 Uses the g8 repository extension for pulling.
111
112
  -h, --help display help for command
112
-
113
+
113
114
  ```
114
-
115
115
 
116
116
  ### `cmt` :
117
+
117
118
  ```
118
119
  Usage: underpost cmt [options] <path> <commit-type> [module-tag] [message]
119
120
 
@@ -133,11 +134,11 @@ Options:
133
134
  --copy Copies the generated commit message to the clipboard.
134
135
  --info Displays information about available commit types.
135
136
  -h, --help display help for command
136
-
137
+
137
138
  ```
138
-
139
139
 
140
140
  ### `push` :
141
+
141
142
  ```
142
143
  Usage: underpost push [options] <path> <uri>
143
144
 
@@ -151,11 +152,11 @@ Options:
151
152
  -f Forces the push, overwriting the remote repository history.
152
153
  -g8 Uses the g8 repository extension for pushing.
153
154
  -h, --help display help for command
154
-
155
+
155
156
  ```
156
-
157
157
 
158
158
  ### `env` :
159
+
159
160
  ```
160
161
  Usage: underpost env [options] <deploy-id> [env]
161
162
 
@@ -170,11 +171,11 @@ Arguments:
170
171
 
171
172
  Options:
172
173
  -h, --help display help for command
173
-
174
+
174
175
  ```
175
-
176
176
 
177
177
  ### `config` :
178
+
178
179
  ```
179
180
  Usage: underpost config [options] <operator> [key] [value]
180
181
 
@@ -189,11 +190,11 @@ Arguments:
189
190
  Options:
190
191
  --plain Prints the configuration value in plain text.
191
192
  -h, --help display help for command
192
-
193
+
193
194
  ```
194
-
195
195
 
196
196
  ### `root` :
197
+
197
198
  ```
198
199
  Usage: underpost root [options]
199
200
 
@@ -201,11 +202,11 @@ Displays the root path of the npm installation.
201
202
 
202
203
  Options:
203
204
  -h, --help display help for command
204
-
205
+
205
206
  ```
206
-
207
207
 
208
208
  ### `cluster` :
209
+
209
210
  ```
210
211
  Usage: underpost cluster [options] [pod-name]
211
212
 
@@ -262,11 +263,11 @@ Options:
262
263
  --k3s Initializes the cluster using K3s (Lightweight
263
264
  Kubernetes).
264
265
  -h, --help display help for command
265
-
266
+
266
267
  ```
267
-
268
268
 
269
269
  ### `deploy` :
270
+
270
271
  ```
271
272
  Usage: underpost deploy [options] [deploy-list] [env]
272
273
 
@@ -315,11 +316,11 @@ Options:
315
316
  deployment operations.
316
317
  --restore-hosts Restores default `/etc/hosts` entries.
317
318
  -h, --help display help for command
318
-
319
+
319
320
  ```
320
-
321
321
 
322
322
  ### `secret` :
323
+
323
324
  ```
324
325
  Usage: underpost secret [options] <platform>
325
326
 
@@ -337,11 +338,11 @@ Options:
337
338
  --list Lists all available secrets for the
338
339
  platform.
339
340
  -h, --help display help for command
340
-
341
+
341
342
  ```
342
-
343
343
 
344
344
  ### `dockerfile-image-build` :
345
+
345
346
  ```
346
347
  Usage: underpost dockerfile-image-build [options]
347
348
 
@@ -368,11 +369,11 @@ Options:
368
369
  cache.
369
370
  --k3s-load Loads the image into a K3s cluster.
370
371
  -h, --help display help for command
371
-
372
+
372
373
  ```
373
-
374
374
 
375
375
  ### `dockerfile-pull-base-images` :
376
+
376
377
  ```
377
378
  Usage: underpost dockerfile-pull-base-images [options]
378
379
 
@@ -386,11 +387,11 @@ Options:
386
387
  --version Sets a custom version for the base images.
387
388
  --k3s-load Loads the image into a K3s cluster.
388
389
  -h, --help display help for command
389
-
390
+
390
391
  ```
391
-
392
392
 
393
393
  ### `install` :
394
+
394
395
  ```
395
396
  Usage: underpost install [options]
396
397
 
@@ -398,11 +399,11 @@ Quickly imports Underpost npm dependencies by copying them.
398
399
 
399
400
  Options:
400
401
  -h, --help display help for command
401
-
402
+
402
403
  ```
403
-
404
404
 
405
405
  ### `db` :
406
+
406
407
  ```
407
408
  Usage: underpost db [options] <deploy-list>
408
409
 
@@ -432,11 +433,11 @@ Options:
432
433
  --ns <ns-name> Optional: Specifies the namespace context for
433
434
  database operations.
434
435
  -h, --help display help for command
435
-
436
+
436
437
  ```
437
-
438
438
 
439
439
  ### `metadata` :
440
+
440
441
  ```
441
442
  Usage: underpost metadata [options] [deploy-id] [host] [path]
442
443
 
@@ -455,11 +456,11 @@ Options:
455
456
  --generate Generate cluster metadata
456
457
  --itc Apply under container execution context
457
458
  -h, --help display help for command
458
-
459
+
459
460
  ```
460
-
461
461
 
462
462
  ### `script` :
463
+
463
464
  ```
464
465
  Usage: underpost script [options] <operator> <script-name> [script-value]
465
466
 
@@ -481,11 +482,11 @@ Options:
481
482
  execution.
482
483
  --pod-name <pod-name> Optional: Specifies the pod name for script execution.
483
484
  -h, --help display help for command
484
-
485
+
485
486
  ```
486
-
487
487
 
488
488
  ### `cron` :
489
+
489
490
  ```
490
491
  Usage: underpost cron [options] [deploy-list] [job-list]
491
492
 
@@ -503,11 +504,11 @@ Options:
503
504
  --init Initializes cron jobs for the default deployment ID.
504
505
  --git Uploads cron job configurations to GitHub.
505
506
  -h, --help display help for command
506
-
507
+
507
508
  ```
508
-
509
509
 
510
510
  ### `fs` :
511
+
511
512
  ```
512
513
  Usage: underpost fs [options] [path]
513
514
 
@@ -525,11 +526,11 @@ Options:
525
526
  --force Forces the action, overriding any warnings or conflicts.
526
527
  --storage-file-path <storage-file-path> Specifies a custom file storage path.
527
528
  -h, --help display help for command
528
-
529
+
529
530
  ```
530
-
531
531
 
532
532
  ### `test` :
533
+
533
534
  ```
534
535
  Usage: underpost test [options] [deploy-list]
535
536
 
@@ -551,11 +552,11 @@ Options:
551
552
  --kind-type <kind-type> Optional: Specifies the Kind cluster type for
552
553
  tests.
553
554
  -h, --help display help for command
554
-
555
+
555
556
  ```
556
-
557
557
 
558
558
  ### `monitor` :
559
+
559
560
  ```
560
561
  Usage: underpost monitor [options] <deploy-id> [env]
561
562
 
@@ -578,11 +579,11 @@ Options:
578
579
  --sync Synchronizes with current proxy deployments and
579
580
  traffic configurations.
580
581
  -h, --help display help for command
581
-
582
+
582
583
  ```
583
-
584
584
 
585
585
  ### `ssh` :
586
+
586
587
  ```
587
588
  Usage: underpost ssh [options]
588
589
 
@@ -592,11 +593,11 @@ Options:
592
593
  --generate Generates new ssh credential and stores it in current private
593
594
  keys file storage.
594
595
  -h, --help display help for command
595
-
596
+
596
597
  ```
597
-
598
598
 
599
599
  ### `run` :
600
+
600
601
  ```
601
602
  Usage: underpost run [options] <runner-id> [path]
602
603
 
@@ -619,12 +620,14 @@ Options:
619
620
  --image-name <image-name> Optional: Specifies the image name for test execution.
620
621
  --container-name <container-name> Optional: Specifies the container name for test execution.
621
622
  --namespace <namespace> Optional: Specifies the namespace for test execution.
623
+ --kubeadm Flag to indicate Kubeadm cluster type context
624
+ --k3s Flag to indicate K3s cluster type context
622
625
  -h, --help display help for command
623
-
626
+
624
627
  ```
625
-
626
628
 
627
629
  ### `lxd` :
630
+
628
631
  ```
629
632
  Usage: underpost lxd [options]
630
633
 
@@ -665,11 +668,11 @@ Options:
665
668
  --auto-expose-k8s-ports <vm-id> Automatically exposes common Kubernetes
666
669
  ports for the specified VM.
667
670
  -h, --help display help for command
668
-
671
+
669
672
  ```
670
-
671
673
 
672
674
  ### `baremetal` :
675
+
673
676
  ```
674
677
  Usage: underpost baremetal [options] [workflow-id] [hostname] [ip-address]
675
678
 
@@ -703,6 +706,5 @@ Options:
703
706
  baremetal operations.
704
707
  --ls Lists available boot resources and machines.
705
708
  -h, --help display help for command
706
-
709
+
707
710
  ```
708
-
package/conf.js CHANGED
@@ -92,6 +92,16 @@ const DefaultConf = /**/ {
92
92
  { path: '/default-management', client: 'Default', ssr: 'Default' },
93
93
  { client: 'Default', ssr: 'Default', path: '/404', title: '404 Not Found' },
94
94
  { client: 'Default', ssr: 'Default', path: '/500', title: '500 Server Error' },
95
+ {
96
+ path: '/blog',
97
+ client: 'Default',
98
+ ssr: 'Default',
99
+ },
100
+ {
101
+ path: '/chat',
102
+ client: 'Default',
103
+ ssr: 'Default',
104
+ },
95
105
  ],
96
106
  dists: [
97
107
  {
@@ -108,7 +118,22 @@ const DefaultConf = /**/ {
108
118
  import_name_build: '/dist/sortablejs/sortable.complete.esm.js',
109
119
  },
110
120
  { folder: './node_modules/validator', public_folder: '/dist/validator' },
111
- { folder: './node_modules/@loadingio/css-spinner/entries', public_folder: '/dist/loadingio' },
121
+ {
122
+ folder: './node_modules/easymde/dist',
123
+ public_folder: '/dist/easymde',
124
+ },
125
+ {
126
+ folder: './node_modules/marked/lib',
127
+ public_folder: '/dist/marked',
128
+ import_name: 'marked',
129
+ import_name_build: '/dist/marked/marked.esm.js',
130
+ },
131
+ {
132
+ folder: './node_modules/vanilla-jsoneditor/standalone.js',
133
+ public_folder: '/dist/vanilla-jsoneditor/standalone.js',
134
+ import_name: 'vanilla-jsoneditor',
135
+ import_name_build: '/dist/vanilla-jsoneditor/standalone.js',
136
+ },
112
137
  {
113
138
  import_name: 'ag-grid-community',
114
139
  import_name_build: '/dist/ag-grid-community/ag-grid-community.min.js',
@@ -125,7 +150,7 @@ const DefaultConf = /**/ {
125
150
  },
126
151
  { folder: './node_modules/peerjs/dist', public_folder: '/dist/peerjs' },
127
152
  ],
128
- services: ['default', 'core', 'user', 'test', 'file'],
153
+ services: ['default', 'core', 'user', 'test', 'file', 'document'],
129
154
  },
130
155
  },
131
156
  ssr: {
@@ -145,7 +170,7 @@ const DefaultConf = /**/ {
145
170
  '/': {
146
171
  client: 'default',
147
172
  runtime: 'nodejs',
148
- apis: ['default', 'core', 'user', 'test', 'file'],
173
+ apis: ['default', 'core', 'user', 'test', 'file', 'document'],
149
174
  origins: [],
150
175
  minifyBuild: false,
151
176
  iconsBuild: false,
@@ -17,7 +17,7 @@ spec:
17
17
  spec:
18
18
  containers:
19
19
  - name: dd-default-development-blue
20
- image: localhost/rockylinux9-underpost:v2.8.878
20
+ image: localhost/rockylinux9-underpost:v2.8.881
21
21
  # resources:
22
22
  # requests:
23
23
  # memory: "124Ki"
@@ -100,7 +100,7 @@ spec:
100
100
  spec:
101
101
  containers:
102
102
  - name: dd-default-development-green
103
- image: localhost/rockylinux9-underpost:v2.8.878
103
+ image: localhost/rockylinux9-underpost:v2.8.881
104
104
  # resources:
105
105
  # requests:
106
106
  # memory: "124Ki"
@@ -17,7 +17,7 @@ spec:
17
17
  spec:
18
18
  containers:
19
19
  - name: dd-test-development-blue
20
- image: localhost/rockylinux9-underpost:v2.8.878
20
+ image: localhost/rockylinux9-underpost:v2.8.881
21
21
  # resources:
22
22
  # requests:
23
23
  # memory: "94Ki"
@@ -104,7 +104,7 @@ spec:
104
104
  spec:
105
105
  containers:
106
106
  - name: dd-test-development-green
107
- image: localhost/rockylinux9-underpost:v2.8.878
107
+ image: localhost/rockylinux9-underpost:v2.8.881
108
108
  # resources:
109
109
  # requests:
110
110
  # memory: "94Ki"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "main": "src/index.js",
4
4
  "name": "underpost",
5
- "version": "2.8.878",
5
+ "version": "2.8.881",
6
6
  "description": "pwa api rest template",
7
7
  "scripts": {
8
8
  "start": "env-cmd -f .env.production node --max-old-space-size=8192 src/server",
@@ -51,7 +51,6 @@
51
51
  "dependencies": {
52
52
  "@fortawesome/fontawesome-free": "^6.4.2",
53
53
  "@fullcalendar/rrule": "^6.1.15",
54
- "@loadingio/css-spinner": "^2.0.2",
55
54
  "@neodrag/vanilla": "^2.0.3",
56
55
  "adm-zip": "^0.5.10",
57
56
  "ag-grid-community": "^31.3.4",
@@ -0,0 +1,66 @@
1
+ import { loggerFactory } from '../../server/logger.js';
2
+ import { DocumentService } from './document.service.js';
3
+ const logger = loggerFactory(import.meta);
4
+
5
+ const DocumentController = {
6
+ post: async (req, res, options) => {
7
+ try {
8
+ return res.status(200).json({
9
+ status: 'success',
10
+ data: await DocumentService.post(req, res, options),
11
+ });
12
+ } catch (error) {
13
+ logger.error(error, error.stack);
14
+ return res.status(400).json({
15
+ status: 'error',
16
+ message: error.message,
17
+ });
18
+ }
19
+ },
20
+ get: async (req, res, options) => {
21
+ try {
22
+ return res.status(200).json({
23
+ status: 'success',
24
+ data: await DocumentService.get(req, res, options),
25
+ });
26
+ } catch (error) {
27
+ logger.error(error, error.stack);
28
+ return res.status(400).json({
29
+ status: 'error',
30
+ message: error.message,
31
+ });
32
+ }
33
+ },
34
+ delete: async (req, res, options) => {
35
+ try {
36
+ const result = await DocumentService.delete(req, res, options);
37
+ return res.status(200).json({
38
+ status: 'success',
39
+ data: result,
40
+ });
41
+ } catch (error) {
42
+ logger.error(error, error.stack);
43
+ return res.status(400).json({
44
+ status: 'error',
45
+ message: error.message,
46
+ });
47
+ }
48
+ },
49
+ put: async (req, res, options) => {
50
+ try {
51
+ const result = await DocumentService.put(req, res, options);
52
+ return res.status(200).json({
53
+ status: 'success',
54
+ data: result,
55
+ });
56
+ } catch (error) {
57
+ logger.error(error, error.stack);
58
+ return res.status(400).json({
59
+ status: 'error',
60
+ message: error.message,
61
+ });
62
+ }
63
+ },
64
+ };
65
+
66
+ export { DocumentController };
@@ -0,0 +1,51 @@
1
+ import { Schema, model, Types } from 'mongoose';
2
+
3
+ // https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
4
+
5
+ const DocumentSchema = new Schema(
6
+ {
7
+ userId: {
8
+ type: Schema.Types.ObjectId,
9
+ ref: 'User',
10
+ },
11
+ location: { type: String },
12
+ title: { type: String },
13
+ tags: [{ type: String }],
14
+ fileId: {
15
+ type: Schema.Types.ObjectId,
16
+ ref: 'File',
17
+ },
18
+ mdFileId: {
19
+ type: Schema.Types.ObjectId,
20
+ ref: 'File',
21
+ },
22
+ },
23
+ {
24
+ timestamps: true,
25
+ },
26
+ );
27
+
28
+ const DocumentModel = model('Document', DocumentSchema);
29
+
30
+ const ProviderSchema = DocumentSchema;
31
+
32
+ const DocumentDto = {
33
+ populate: {
34
+ file: () => {
35
+ return {
36
+ path: 'fileId',
37
+ model: 'File',
38
+ select: '_id name mimetype',
39
+ };
40
+ },
41
+ user: () => {
42
+ return {
43
+ path: 'userId',
44
+ model: 'User',
45
+ select: '_id email username',
46
+ };
47
+ },
48
+ },
49
+ };
50
+
51
+ export { DocumentSchema, DocumentModel, ProviderSchema, DocumentDto };
@@ -0,0 +1,24 @@
1
+ import { loggerFactory } from '../../server/logger.js';
2
+ import { DocumentController } from './document.controller.js';
3
+ import express from 'express';
4
+ import fs from 'fs-extra';
5
+ const logger = loggerFactory(import.meta);
6
+
7
+ const DocumentRouter = (options) => {
8
+ const router = express.Router();
9
+ const authMiddleware = options.authMiddleware;
10
+ router.post(`/:id`, authMiddleware, async (req, res) => await DocumentController.post(req, res, options));
11
+ router.post(`/`, authMiddleware, async (req, res) => await DocumentController.post(req, res, options));
12
+ router.get(`/public`, async (req, res) => await DocumentController.get(req, res, options));
13
+ router.get(`/:id`, authMiddleware, async (req, res) => await DocumentController.get(req, res, options));
14
+ router.get(`/`, authMiddleware, async (req, res) => await DocumentController.get(req, res, options));
15
+ router.put(`/:id`, authMiddleware, async (req, res) => await DocumentController.put(req, res, options));
16
+ router.put(`/`, authMiddleware, async (req, res) => await DocumentController.put(req, res, options));
17
+ router.delete(`/:id`, authMiddleware, async (req, res) => await DocumentController.delete(req, res, options));
18
+ router.delete(`/`, authMiddleware, async (req, res) => await DocumentController.delete(req, res, options));
19
+ return router;
20
+ };
21
+
22
+ const ApiRouter = DocumentRouter;
23
+
24
+ export { ApiRouter, DocumentRouter };