@underpostnet/underpost 2.7.9
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.
- package/.dockerignore +14 -0
- package/.env.development +6 -0
- package/.env.production +6 -0
- package/.env.test +6 -0
- package/.github/workflows/ghpkg.yml +115 -0
- package/.github/workflows/publish.yml +84 -0
- package/.github/workflows/pwa-microservices-template.page.yml +54 -0
- package/.github/workflows/pwa-microservices-template.test.yml +30 -0
- package/.nycrc +9 -0
- package/.prettierignore +13 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +72 -0
- package/.vscode/settings.json +106 -0
- package/AUTHORS.md +10 -0
- package/CHANGELOG.md +85 -0
- package/Dockerfile +90 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/bin/cron.js +47 -0
- package/bin/db.js +180 -0
- package/bin/deploy.js +859 -0
- package/bin/file.js +109 -0
- package/bin/index.js +82 -0
- package/bin/ssl.js +55 -0
- package/bin/util.js +204 -0
- package/bin/vs.js +35 -0
- package/conf.js +265 -0
- package/docker-compose.yml +67 -0
- package/jsconfig.json +7 -0
- package/jsdoc.json +32 -0
- package/nodemon.json +6 -0
- package/package.json +134 -0
- package/prometheus.yml +36 -0
- package/src/api/core/core.controller.js +69 -0
- package/src/api/core/core.model.js +11 -0
- package/src/api/core/core.router.js +23 -0
- package/src/api/core/core.service.js +31 -0
- package/src/api/crypto/crypto.controller.js +51 -0
- package/src/api/crypto/crypto.model.js +23 -0
- package/src/api/crypto/crypto.router.js +20 -0
- package/src/api/crypto/crypto.service.js +64 -0
- package/src/api/default/default.controller.js +69 -0
- package/src/api/default/default.model.js +20 -0
- package/src/api/default/default.router.js +23 -0
- package/src/api/default/default.service.js +31 -0
- package/src/api/file/file.controller.js +53 -0
- package/src/api/file/file.model.js +19 -0
- package/src/api/file/file.router.js +21 -0
- package/src/api/file/file.service.js +80 -0
- package/src/api/instance/instance.controller.js +69 -0
- package/src/api/instance/instance.model.js +36 -0
- package/src/api/instance/instance.router.js +33 -0
- package/src/api/instance/instance.service.js +48 -0
- package/src/api/test/test.controller.js +59 -0
- package/src/api/test/test.model.js +14 -0
- package/src/api/test/test.router.js +21 -0
- package/src/api/test/test.service.js +35 -0
- package/src/api/user/user.build.js +16 -0
- package/src/api/user/user.controller.js +70 -0
- package/src/api/user/user.model.js +65 -0
- package/src/api/user/user.router.js +345 -0
- package/src/api/user/user.service.js +479 -0
- package/src/api.js +23 -0
- package/src/client/Default.index.js +40 -0
- package/src/client/components/core/Account.js +290 -0
- package/src/client/components/core/AgGrid.js +160 -0
- package/src/client/components/core/Auth.js +19 -0
- package/src/client/components/core/Badge.js +32 -0
- package/src/client/components/core/Blockchain.js +41 -0
- package/src/client/components/core/Blog.js +9 -0
- package/src/client/components/core/BtnIcon.js +101 -0
- package/src/client/components/core/CalendarCore.js +458 -0
- package/src/client/components/core/Chat.js +64 -0
- package/src/client/components/core/ColorPalette.js +5267 -0
- package/src/client/components/core/CommonJs.js +742 -0
- package/src/client/components/core/Content.js +193 -0
- package/src/client/components/core/Css.js +846 -0
- package/src/client/components/core/CssCore.js +844 -0
- package/src/client/components/core/D3Chart.js +44 -0
- package/src/client/components/core/Docs.js +331 -0
- package/src/client/components/core/DropDown.js +164 -0
- package/src/client/components/core/EventsUI.js +46 -0
- package/src/client/components/core/FileExplorer.js +699 -0
- package/src/client/components/core/FullScreen.js +45 -0
- package/src/client/components/core/Input.js +346 -0
- package/src/client/components/core/JoyStick.js +77 -0
- package/src/client/components/core/Keyboard.js +73 -0
- package/src/client/components/core/LoadingAnimation.js +178 -0
- package/src/client/components/core/LogIn.js +187 -0
- package/src/client/components/core/LogOut.js +58 -0
- package/src/client/components/core/Logger.js +26 -0
- package/src/client/components/core/Modal.js +1814 -0
- package/src/client/components/core/NotificationManager.js +84 -0
- package/src/client/components/core/Panel.js +613 -0
- package/src/client/components/core/PanelForm.js +469 -0
- package/src/client/components/core/Polyhedron.js +162 -0
- package/src/client/components/core/Recover.js +204 -0
- package/src/client/components/core/Responsive.js +68 -0
- package/src/client/components/core/RichText.js +53 -0
- package/src/client/components/core/Router.js +76 -0
- package/src/client/components/core/Scroll.js +34 -0
- package/src/client/components/core/SignUp.js +125 -0
- package/src/client/components/core/SocketIo.js +72 -0
- package/src/client/components/core/Stream.js +113 -0
- package/src/client/components/core/ToggleSwitch.js +87 -0
- package/src/client/components/core/ToolTip.js +26 -0
- package/src/client/components/core/Translate.js +446 -0
- package/src/client/components/core/Validator.js +100 -0
- package/src/client/components/core/VanillaJs.js +463 -0
- package/src/client/components/core/Wallet.js +106 -0
- package/src/client/components/core/WebComponent.js +44 -0
- package/src/client/components/core/Webhook.js +25 -0
- package/src/client/components/core/Worker.js +280 -0
- package/src/client/components/default/CommonDefault.js +29 -0
- package/src/client/components/default/CssDefault.js +13 -0
- package/src/client/components/default/ElementsDefault.js +38 -0
- package/src/client/components/default/LogInDefault.js +41 -0
- package/src/client/components/default/LogOutDefault.js +28 -0
- package/src/client/components/default/MenuDefault.js +389 -0
- package/src/client/components/default/RoutesDefault.js +48 -0
- package/src/client/components/default/SettingsDefault.js +16 -0
- package/src/client/components/default/SignUpDefault.js +9 -0
- package/src/client/components/default/SocketIoDefault.js +54 -0
- package/src/client/components/default/TranslateDefault.js +7 -0
- package/src/client/public/default/android-chrome-144x144.png +0 -0
- package/src/client/public/default/android-chrome-192x192.png +0 -0
- package/src/client/public/default/android-chrome-256x256.png +0 -0
- package/src/client/public/default/android-chrome-36x36.png +0 -0
- package/src/client/public/default/android-chrome-384x384.png +0 -0
- package/src/client/public/default/android-chrome-48x48.png +0 -0
- package/src/client/public/default/android-chrome-512x512.png +0 -0
- package/src/client/public/default/android-chrome-72x72.png +0 -0
- package/src/client/public/default/android-chrome-96x96.png +0 -0
- package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
- package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
- package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
- package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
- package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
- package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
- package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
- package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
- package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
- package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
- package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
- package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
- package/src/client/public/default/apple-touch-icon.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
- package/src/client/public/default/assets/background/white.jpg +0 -0
- package/src/client/public/default/assets/background/white0-min.jpg +0 -0
- package/src/client/public/default/assets/background/white0.jpg +0 -0
- package/src/client/public/default/assets/logo/base-icon.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
- package/src/client/public/default/browserconfig.xml +12 -0
- package/src/client/public/default/favicon-16x16.png +0 -0
- package/src/client/public/default/favicon-32x32.png +0 -0
- package/src/client/public/default/favicon-48x48.png +0 -0
- package/src/client/public/default/favicon.ico +0 -0
- package/src/client/public/default/manifest.webmanifest +69 -0
- package/src/client/public/default/mstile-144x144.png +0 -0
- package/src/client/public/default/mstile-150x150.png +0 -0
- package/src/client/public/default/mstile-310x150.png +0 -0
- package/src/client/public/default/mstile-310x310.png +0 -0
- package/src/client/public/default/mstile-70x70.png +0 -0
- package/src/client/public/default/plantuml/client-conf.svg +1 -0
- package/src/client/public/default/plantuml/client-schema.svg +1 -0
- package/src/client/public/default/plantuml/cron-conf.svg +1 -0
- package/src/client/public/default/plantuml/cron-schema.svg +1 -0
- package/src/client/public/default/plantuml/server-conf.svg +1 -0
- package/src/client/public/default/plantuml/server-schema.svg +1 -0
- package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
- package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
- package/src/client/public/default/site.webmanifest +69 -0
- package/src/client/public/default/sitemap +148 -0
- package/src/client/public/default/yandex-browser-50x50.png +0 -0
- package/src/client/public/default/yandex-browser-manifest.json +9 -0
- package/src/client/public/doc/favicon.ico +0 -0
- package/src/client/public/doc/sitemap +148 -0
- package/src/client/public/test/favicon.ico +0 -0
- package/src/client/public/test/sitemap +148 -0
- package/src/client/services/core/core.service.js +170 -0
- package/src/client/services/crypto/crypto.service.js +70 -0
- package/src/client/services/default/default.management.js +343 -0
- package/src/client/services/default/default.service.js +89 -0
- package/src/client/services/file/file.service.js +70 -0
- package/src/client/services/instance/instance.management.js +74 -0
- package/src/client/services/instance/instance.service.js +89 -0
- package/src/client/services/test/test.service.js +70 -0
- package/src/client/services/user/user.management.js +50 -0
- package/src/client/services/user/user.service.js +89 -0
- package/src/client/ssr/Render.js +237 -0
- package/src/client/ssr/common/Alert.js +75 -0
- package/src/client/ssr/common/SsrCore.js +91 -0
- package/src/client/ssr/common/Translate.js +26 -0
- package/src/client/ssr/common/Worker.js +28 -0
- package/src/client/ssr/components/body/CacheControl.js +114 -0
- package/src/client/ssr/components/body/DefaultSplashScreen.js +90 -0
- package/src/client/ssr/components/email/DefaultRecoverEmail.js +21 -0
- package/src/client/ssr/components/email/DefaultVerifyEmail.js +17 -0
- package/src/client/ssr/components/head/Css.js +241 -0
- package/src/client/ssr/components/head/DefaultScripts.js +3 -0
- package/src/client/ssr/components/head/Production.js +1 -0
- package/src/client/ssr/components/head/Pwa.js +146 -0
- package/src/client/ssr/components/head/PwaDefault.js +60 -0
- package/src/client/ssr/components/head/Seo.js +14 -0
- package/src/client/ssr/pages/404.js +12 -0
- package/src/client/ssr/pages/500.js +12 -0
- package/src/client/ssr/pages/maintenance.js +14 -0
- package/src/client/ssr/pages/offline.js +21 -0
- package/src/client/sw/default.sw.js +205 -0
- package/src/client/sw/template.sw.js +84 -0
- package/src/client.build.js +22 -0
- package/src/client.dev.js +21 -0
- package/src/db/DataBaseProvider.js +45 -0
- package/src/db/mariadb/MariaDB.js +33 -0
- package/src/db/mongo/MongooseDB.js +124 -0
- package/src/dns.js +22 -0
- package/src/index.js +43 -0
- package/src/mailer/EmailRender.js +69 -0
- package/src/mailer/MailerProvider.js +96 -0
- package/src/proxy.js +22 -0
- package/src/runtime/lampp/Lampp.js +115 -0
- package/src/runtime/nginx/Nginx.js +3 -0
- package/src/runtime/xampp/Xampp.js +49 -0
- package/src/server/auth.js +235 -0
- package/src/server/backup.js +120 -0
- package/src/server/client-build-live.js +98 -0
- package/src/server/client-build.js +754 -0
- package/src/server/client-dev-server.js +60 -0
- package/src/server/client-formatted.js +58 -0
- package/src/server/client-icons.js +151 -0
- package/src/server/conf.js +929 -0
- package/src/server/crypto.js +91 -0
- package/src/server/dns.js +118 -0
- package/src/server/downloader.js +42 -0
- package/src/server/logger.js +190 -0
- package/src/server/network.js +209 -0
- package/src/server/peer.js +33 -0
- package/src/server/process.js +66 -0
- package/src/server/prompt-optimizer.js +28 -0
- package/src/server/proxy.js +118 -0
- package/src/server/runtime.js +463 -0
- package/src/server/ssl.js +120 -0
- package/src/server.js +25 -0
- package/src/ws/IoInterface.js +45 -0
- package/src/ws/IoServer.js +39 -0
- package/src/ws/core/channels/core.ws.chat.js +23 -0
- package/src/ws/core/channels/core.ws.mailer.js +35 -0
- package/src/ws/core/channels/core.ws.stream.js +31 -0
- package/src/ws/core/core.ws.connection.js +28 -0
- package/src/ws/core/core.ws.emit.js +14 -0
- package/src/ws/core/core.ws.server.js +24 -0
- package/src/ws/core/management/core.ws.chat.js +8 -0
- package/src/ws/core/management/core.ws.mailer.js +16 -0
- package/src/ws/core/management/core.ws.stream.js +8 -0
- package/src/ws/default/channels/default.ws.main.js +16 -0
- package/src/ws/default/default.ws.connection.js +22 -0
- package/src/ws/default/default.ws.emit.js +14 -0
- package/src/ws/default/default.ws.server.js +20 -0
- package/src/ws/default/management/default.ws.main.js +8 -0
- package/startup.js +11 -0
- package/supervisord-openssh-server.conf +5 -0
- package/test/api.test.js +60 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { CryptoService } from './crypto.service.js';
|
|
3
|
+
const logger = loggerFactory(import.meta);
|
|
4
|
+
|
|
5
|
+
const CryptoController = {
|
|
6
|
+
post: async (req, res, options) => {
|
|
7
|
+
try {
|
|
8
|
+
return res.status(200).json({
|
|
9
|
+
status: 'success',
|
|
10
|
+
data: await CryptoService.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 CryptoService.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 CryptoService.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
|
+
};
|
|
50
|
+
|
|
51
|
+
export { CryptoController };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema, model, Types } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
// https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
|
|
4
|
+
|
|
5
|
+
// Example:
|
|
6
|
+
// JWKS: Array of JWK
|
|
7
|
+
// https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-key-sets
|
|
8
|
+
|
|
9
|
+
const CryptoSchema = new Schema({
|
|
10
|
+
format: { type: String, required: 'format is required' },
|
|
11
|
+
data: { type: String, required: 'data is required', unique: true },
|
|
12
|
+
algorithm: {
|
|
13
|
+
name: { type: String, required: 'name is required' },
|
|
14
|
+
namedCurve: { type: String, required: 'namedCurve is required' },
|
|
15
|
+
hash: { type: String, required: 'hash is required' },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const CryptoModel = model('Crypto', CryptoSchema);
|
|
20
|
+
|
|
21
|
+
const ProviderSchema = CryptoSchema;
|
|
22
|
+
|
|
23
|
+
export { CryptoSchema, CryptoModel, ProviderSchema };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { CryptoController } from './crypto.controller.js';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const CryptoRouter = (options) => {
|
|
8
|
+
const router = express.Router();
|
|
9
|
+
router.post(`/:id`, async (req, res) => await CryptoController.post(req, res, options));
|
|
10
|
+
router.post(`/`, authMiddleware, async (req, res) => await CryptoController.post(req, res, options));
|
|
11
|
+
router.get(`/:id`, async (req, res) => await CryptoController.get(req, res, options));
|
|
12
|
+
router.get(`/`, async (req, res) => await CryptoController.get(req, res, options));
|
|
13
|
+
router.delete(`/:id`, async (req, res) => await CryptoController.delete(req, res, options));
|
|
14
|
+
router.delete(`/`, async (req, res) => await CryptoController.delete(req, res, options));
|
|
15
|
+
return router;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ApiRouter = CryptoRouter;
|
|
19
|
+
|
|
20
|
+
export { ApiRouter, CryptoRouter };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { DataBaseProvider } from '../../db/DataBaseProvider.js';
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const CryptoService = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
/** @type {import('./crypto.model.js').CryptoModel} */
|
|
9
|
+
const Crypto = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.Crypto;
|
|
10
|
+
/** @type {import('../user/user.model.js').UserModel} */
|
|
11
|
+
const User = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.User;
|
|
12
|
+
|
|
13
|
+
switch (req.params.id) {
|
|
14
|
+
case 'verify': {
|
|
15
|
+
const signature = Buffer.from(req.body.signature, 'base64');
|
|
16
|
+
|
|
17
|
+
const publicKey = await crypto.subtle.importKey(
|
|
18
|
+
'jwk',
|
|
19
|
+
req.body.publicKey,
|
|
20
|
+
{
|
|
21
|
+
name: 'ECDSA',
|
|
22
|
+
namedCurve: 'P-384',
|
|
23
|
+
hash: 'SHA-256',
|
|
24
|
+
},
|
|
25
|
+
true,
|
|
26
|
+
['verify'],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const isValid = await crypto.subtle.verify(
|
|
30
|
+
{
|
|
31
|
+
name: 'ECDSA',
|
|
32
|
+
hash: 'SHA-256',
|
|
33
|
+
},
|
|
34
|
+
publicKey,
|
|
35
|
+
signature,
|
|
36
|
+
new TextEncoder().encode(JSON.stringify(req.body.payload)),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return { isValid };
|
|
40
|
+
}
|
|
41
|
+
default: {
|
|
42
|
+
const publicKey = await new Crypto(req.body).save();
|
|
43
|
+
const user = await User.findById(req.auth.user._id);
|
|
44
|
+
user.publicKey.push(publicKey._id);
|
|
45
|
+
await User.findByIdAndUpdate(req.auth.user._id, user, {
|
|
46
|
+
runValidators: true,
|
|
47
|
+
});
|
|
48
|
+
return publicKey;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
get: async (req, res, options) => {
|
|
53
|
+
switch (req.params.id) {
|
|
54
|
+
default:
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
delete: async (req, res, options) => {
|
|
58
|
+
switch (req.params.id) {
|
|
59
|
+
default:
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { CryptoService };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { DefaultService } from './default.service.js';
|
|
3
|
+
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const DefaultController = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await DefaultService.post(req, res, options);
|
|
10
|
+
return res.status(200).json({
|
|
11
|
+
status: 'success',
|
|
12
|
+
data: result,
|
|
13
|
+
});
|
|
14
|
+
} catch (error) {
|
|
15
|
+
logger.error(error, error.stack);
|
|
16
|
+
return res.status(400).json({
|
|
17
|
+
status: 'error',
|
|
18
|
+
message: error.message,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
get: async (req, res, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await DefaultService.get(req, res, options);
|
|
25
|
+
return res.status(200).json({
|
|
26
|
+
status: 'success',
|
|
27
|
+
data: result,
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
logger.error(error, error.stack);
|
|
31
|
+
return res.status(400).json({
|
|
32
|
+
status: 'error',
|
|
33
|
+
message: error.message,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
put: async (req, res, options) => {
|
|
38
|
+
try {
|
|
39
|
+
const result = await DefaultService.put(req, res, options);
|
|
40
|
+
return res.status(200).json({
|
|
41
|
+
status: 'success',
|
|
42
|
+
data: result,
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error(error, error.stack);
|
|
46
|
+
return res.status(400).json({
|
|
47
|
+
status: 'error',
|
|
48
|
+
message: error.message,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
delete: async (req, res, options) => {
|
|
53
|
+
try {
|
|
54
|
+
const result = await DefaultService.delete(req, res, options);
|
|
55
|
+
return res.status(200).json({
|
|
56
|
+
status: 'success',
|
|
57
|
+
data: result,
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.error(error, error.stack);
|
|
61
|
+
return res.status(400).json({
|
|
62
|
+
status: 'error',
|
|
63
|
+
message: error.message,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { DefaultController };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema, model, Types } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
// https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
|
|
4
|
+
|
|
5
|
+
const DefaultSchema = new Schema(
|
|
6
|
+
{
|
|
7
|
+
0: { type: String },
|
|
8
|
+
1: { type: String },
|
|
9
|
+
2: { type: String },
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
timestamps: true,
|
|
13
|
+
},
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const DefaultModel = model('Default', DefaultSchema);
|
|
17
|
+
|
|
18
|
+
const ProviderSchema = DefaultSchema;
|
|
19
|
+
|
|
20
|
+
export { DefaultSchema, DefaultModel, ProviderSchema };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { DefaultController } from './default.controller.js';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
|
|
6
|
+
const logger = loggerFactory(import.meta);
|
|
7
|
+
|
|
8
|
+
const DefaultRouter = (options) => {
|
|
9
|
+
const router = express.Router();
|
|
10
|
+
router.post(`/:id`, async (req, res) => await DefaultController.post(req, res, options));
|
|
11
|
+
router.post(`/`, async (req, res) => await DefaultController.post(req, res, options));
|
|
12
|
+
router.get(`/:id`, async (req, res) => await DefaultController.get(req, res, options));
|
|
13
|
+
router.get(`/`, async (req, res) => await DefaultController.get(req, res, options));
|
|
14
|
+
router.put(`/:id`, async (req, res) => await DefaultController.put(req, res, options));
|
|
15
|
+
router.put(`/`, async (req, res) => await DefaultController.put(req, res, options));
|
|
16
|
+
router.delete(`/:id`, async (req, res) => await DefaultController.delete(req, res, options));
|
|
17
|
+
router.delete(`/`, async (req, res) => await DefaultController.delete(req, res, options));
|
|
18
|
+
return router;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const ApiRouter = DefaultRouter;
|
|
22
|
+
|
|
23
|
+
export { ApiRouter, DefaultRouter };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DataBaseProvider } from '../../db/DataBaseProvider.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const DefaultService = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
/** @type {import('./default.model.js').DefaultModel} */
|
|
9
|
+
const Default = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Default;
|
|
10
|
+
return await new Default(req.body).save();
|
|
11
|
+
},
|
|
12
|
+
get: async (req, res, options) => {
|
|
13
|
+
/** @type {import('./default.model.js').DefaultModel} */
|
|
14
|
+
const Default = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Default;
|
|
15
|
+
if (req.params.id) return await Default.findById(req.params.id);
|
|
16
|
+
return await Default.find();
|
|
17
|
+
},
|
|
18
|
+
put: async (req, res, options) => {
|
|
19
|
+
/** @type {import('./default.model.js').DefaultModel} */
|
|
20
|
+
const Default = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Default;
|
|
21
|
+
return await Default.findByIdAndUpdate(req.params.id, req.body);
|
|
22
|
+
},
|
|
23
|
+
delete: async (req, res, options) => {
|
|
24
|
+
/** @type {import('./default.model.js').DefaultModel} */
|
|
25
|
+
const Default = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Default;
|
|
26
|
+
if (req.params.id) return await Default.findByIdAndDelete(req.params.id);
|
|
27
|
+
else return await await Default.deleteMany();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { DefaultService };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { FileService } from './file.service.js';
|
|
3
|
+
const logger = loggerFactory(import.meta);
|
|
4
|
+
|
|
5
|
+
const FileController = {
|
|
6
|
+
post: async (req, res, options) => {
|
|
7
|
+
try {
|
|
8
|
+
return res.status(200).json({
|
|
9
|
+
status: 'success',
|
|
10
|
+
data: await FileService.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
|
+
const result = await FileService.get(req, res, options);
|
|
23
|
+
if (result instanceof Buffer) return res.status(200).end(result);
|
|
24
|
+
return res.status(200).json({
|
|
25
|
+
status: 'success',
|
|
26
|
+
data: result,
|
|
27
|
+
});
|
|
28
|
+
} catch (error) {
|
|
29
|
+
logger.error(error, error.stack);
|
|
30
|
+
return res.status(400).json({
|
|
31
|
+
status: 'error',
|
|
32
|
+
message: error.message,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
delete: async (req, res, options) => {
|
|
37
|
+
try {
|
|
38
|
+
const result = await FileService.delete(req, res, options);
|
|
39
|
+
return res.status(200).json({
|
|
40
|
+
status: 'success',
|
|
41
|
+
data: result,
|
|
42
|
+
});
|
|
43
|
+
} catch (error) {
|
|
44
|
+
logger.error(error, error.stack);
|
|
45
|
+
return res.status(400).json({
|
|
46
|
+
status: 'error',
|
|
47
|
+
message: error.message,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { FileController };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema, model } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const FileSchema = new Schema({
|
|
4
|
+
name: { type: String },
|
|
5
|
+
data: { type: Buffer },
|
|
6
|
+
size: { type: Number },
|
|
7
|
+
encoding: { type: String },
|
|
8
|
+
tempFilePath: { type: String },
|
|
9
|
+
truncated: { type: Boolean },
|
|
10
|
+
mimetype: { type: String },
|
|
11
|
+
md5: { type: String },
|
|
12
|
+
cid: { type: String },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const FileModel = model('File', FileSchema);
|
|
16
|
+
|
|
17
|
+
const ProviderSchema = FileSchema;
|
|
18
|
+
|
|
19
|
+
export { FileSchema, FileModel, ProviderSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { adminGuard, authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { FileController } from './file.controller.js';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const FileRouter = (options) => {
|
|
8
|
+
const router = express.Router();
|
|
9
|
+
router.post(`/:id`, authMiddleware, async (req, res) => await FileController.post(req, res, options));
|
|
10
|
+
router.post(`/`, authMiddleware, async (req, res) => await FileController.post(req, res, options));
|
|
11
|
+
router.get(`/blob/:id`, async (req, res) => await FileController.get(req, res, options));
|
|
12
|
+
router.get(`/:id`, async (req, res) => await FileController.get(req, res, options));
|
|
13
|
+
router.get(`/`, async (req, res) => await FileController.get(req, res, options));
|
|
14
|
+
router.delete(`/:id`, authMiddleware, adminGuard, async (req, res) => await FileController.delete(req, res, options));
|
|
15
|
+
router.delete(`/`, authMiddleware, adminGuard, async (req, res) => await FileController.delete(req, res, options));
|
|
16
|
+
return router;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ApiRouter = FileRouter;
|
|
20
|
+
|
|
21
|
+
export { ApiRouter, FileRouter };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DataBaseProvider } from '../../db/DataBaseProvider.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const FileFactory = {
|
|
8
|
+
upload: async function (req, File) {
|
|
9
|
+
const results = [];
|
|
10
|
+
if (!req.files) throw { message: 'not file found' };
|
|
11
|
+
if (Array.isArray(req.files.file)) for (const file of req.files.file) results.push(await new File(file).save());
|
|
12
|
+
else if (Object.keys(req.files).length > 0)
|
|
13
|
+
for (const keyFile of Object.keys(req.files)) results.push(await new File(req.files[keyFile]).save());
|
|
14
|
+
let index = -1;
|
|
15
|
+
for (const file of results) {
|
|
16
|
+
index++;
|
|
17
|
+
const [result] = await File.find({
|
|
18
|
+
_id: file._id,
|
|
19
|
+
}).select({ _id: 1, name: 1, mimetype: 1 });
|
|
20
|
+
results[index] = result;
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
},
|
|
24
|
+
hex: (raw = '') => {
|
|
25
|
+
return Buffer.from(raw, 'utf8').toString('hex');
|
|
26
|
+
// reverse hexValue.toString()
|
|
27
|
+
},
|
|
28
|
+
svg: (data = new Buffer(), name = '') => {
|
|
29
|
+
return {
|
|
30
|
+
name: name,
|
|
31
|
+
data: data,
|
|
32
|
+
size: data.length,
|
|
33
|
+
encoding: '7bit',
|
|
34
|
+
tempFilePath: '',
|
|
35
|
+
truncated: false,
|
|
36
|
+
mimetype: 'image/svg+xml',
|
|
37
|
+
md5: crypto.createHash('md5').update(data).digest('hex'),
|
|
38
|
+
cid: undefined,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const FileService = {
|
|
44
|
+
post: async (req, res, options) => {
|
|
45
|
+
/** @type {import('./file.model.js').FileModel} */
|
|
46
|
+
const File = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.File;
|
|
47
|
+
return await FileFactory.upload(req, File);
|
|
48
|
+
},
|
|
49
|
+
get: async (req, res, options) => {
|
|
50
|
+
/** @type {import('./file.model.js').FileModel} */
|
|
51
|
+
const File = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.File;
|
|
52
|
+
|
|
53
|
+
if (req.path.startsWith('/blob') && req.params.id) {
|
|
54
|
+
const file = await File.findOne({ _id: req.params.id });
|
|
55
|
+
res.set('Content-Type', file.mimetype);
|
|
56
|
+
return Buffer.from(file.data, 'base64');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (req.params.id) {
|
|
60
|
+
case 'all':
|
|
61
|
+
return await File.find();
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
return await File.find({
|
|
65
|
+
_id: req.params.id,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
delete: async (req, res, options) => {
|
|
70
|
+
/** @type {import('./file.model.js').FileModel} */
|
|
71
|
+
const File = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.File;
|
|
72
|
+
|
|
73
|
+
switch (req.params.id) {
|
|
74
|
+
default:
|
|
75
|
+
return await File.findByIdAndDelete(req.params.id);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export { FileService, FileFactory };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { InstanceService } from './instance.service.js';
|
|
3
|
+
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const InstanceController = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await InstanceService.post(req, res, options);
|
|
10
|
+
return res.status(200).json({
|
|
11
|
+
status: 'success',
|
|
12
|
+
data: result,
|
|
13
|
+
});
|
|
14
|
+
} catch (error) {
|
|
15
|
+
logger.error(error, error.stack);
|
|
16
|
+
return res.status(400).json({
|
|
17
|
+
status: 'error',
|
|
18
|
+
message: error.message,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
get: async (req, res, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await InstanceService.get(req, res, options);
|
|
25
|
+
return res.status(200).json({
|
|
26
|
+
status: 'success',
|
|
27
|
+
data: result,
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
logger.error(error, error.stack);
|
|
31
|
+
return res.status(400).json({
|
|
32
|
+
status: 'error',
|
|
33
|
+
message: error.message,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
put: async (req, res, options) => {
|
|
38
|
+
try {
|
|
39
|
+
const result = await InstanceService.put(req, res, options);
|
|
40
|
+
return res.status(200).json({
|
|
41
|
+
status: 'success',
|
|
42
|
+
data: result,
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error(error, error.stack);
|
|
46
|
+
return res.status(400).json({
|
|
47
|
+
status: 'error',
|
|
48
|
+
message: error.message,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
delete: async (req, res, options) => {
|
|
53
|
+
try {
|
|
54
|
+
const result = await InstanceService.delete(req, res, options);
|
|
55
|
+
return res.status(200).json({
|
|
56
|
+
status: 'success',
|
|
57
|
+
data: result,
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.error(error, error.stack);
|
|
61
|
+
return res.status(400).json({
|
|
62
|
+
status: 'error',
|
|
63
|
+
message: error.message,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { InstanceController };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Schema, model, Types } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
// https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
|
|
4
|
+
|
|
5
|
+
const InstanceSchema = new Schema(
|
|
6
|
+
{
|
|
7
|
+
deployId: { type: String },
|
|
8
|
+
host: { type: String },
|
|
9
|
+
path: { type: String },
|
|
10
|
+
userId: {
|
|
11
|
+
type: Schema.Types.ObjectId,
|
|
12
|
+
ref: 'User',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
timestamps: true,
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const InstanceDto = {
|
|
21
|
+
populate: {
|
|
22
|
+
get: () => {
|
|
23
|
+
return {
|
|
24
|
+
path: 'userId',
|
|
25
|
+
model: 'User',
|
|
26
|
+
select: '_id email',
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const InstanceModel = model('Instance', InstanceSchema);
|
|
33
|
+
|
|
34
|
+
const ProviderSchema = InstanceSchema;
|
|
35
|
+
|
|
36
|
+
export { InstanceSchema, InstanceModel, ProviderSchema, InstanceDto };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { adminGuard, authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { InstanceController } from './instance.controller.js';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
|
|
6
|
+
const logger = loggerFactory(import.meta);
|
|
7
|
+
|
|
8
|
+
const InstanceRouter = (options) => {
|
|
9
|
+
const router = express.Router();
|
|
10
|
+
router.post(`/:id`, authMiddleware, adminGuard, async (req, res) => await InstanceController.post(req, res, options));
|
|
11
|
+
router.post(`/`, authMiddleware, adminGuard, async (req, res) => await InstanceController.post(req, res, options));
|
|
12
|
+
router.get(`/:id`, authMiddleware, adminGuard, async (req, res) => await InstanceController.get(req, res, options));
|
|
13
|
+
router.get(`/`, authMiddleware, async (req, res) => await InstanceController.get(req, res, options));
|
|
14
|
+
router.put(`/:id`, authMiddleware, adminGuard, async (req, res) => await InstanceController.put(req, res, options));
|
|
15
|
+
router.put(`/`, authMiddleware, adminGuard, async (req, res) => await InstanceController.put(req, res, options));
|
|
16
|
+
router.delete(
|
|
17
|
+
`/:id`,
|
|
18
|
+
authMiddleware,
|
|
19
|
+
adminGuard,
|
|
20
|
+
async (req, res) => await InstanceController.delete(req, res, options),
|
|
21
|
+
);
|
|
22
|
+
router.delete(
|
|
23
|
+
`/`,
|
|
24
|
+
authMiddleware,
|
|
25
|
+
adminGuard,
|
|
26
|
+
async (req, res) => await InstanceController.delete(req, res, options),
|
|
27
|
+
);
|
|
28
|
+
return router;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const ApiRouter = InstanceRouter;
|
|
32
|
+
|
|
33
|
+
export { ApiRouter, InstanceRouter };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DataBaseProvider } from '../../db/DataBaseProvider.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { InstanceDto } from './instance.model.js';
|
|
4
|
+
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const InstanceService = {
|
|
8
|
+
post: async (req, res, options) => {
|
|
9
|
+
/** @type {import('./instance.model.js').InstanceModel} */
|
|
10
|
+
const Instance = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.Instance;
|
|
11
|
+
return await new Instance(req.body).save();
|
|
12
|
+
},
|
|
13
|
+
get: async (req, res, options) => {
|
|
14
|
+
/** @type {import('./instance.model.js').InstanceModel} */
|
|
15
|
+
const Instance = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.Instance;
|
|
16
|
+
|
|
17
|
+
/** @type {import('../user/user.model.js').UserModel} */
|
|
18
|
+
const User = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.User;
|
|
19
|
+
|
|
20
|
+
const user = await User.findOne({
|
|
21
|
+
_id: req.auth.user._id,
|
|
22
|
+
});
|
|
23
|
+
switch (req.params.id) {
|
|
24
|
+
default:
|
|
25
|
+
switch (user.role) {
|
|
26
|
+
case 'admin':
|
|
27
|
+
if (req.params.id) return await Instance.findById(req.params.id);
|
|
28
|
+
return await Instance.find().populate(InstanceDto.populate.get());
|
|
29
|
+
|
|
30
|
+
default:
|
|
31
|
+
return await Instance.find({ userId: req.auth.user._id }).populate(InstanceDto.populate.get());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
put: async (req, res, options) => {
|
|
36
|
+
/** @type {import('./instance.model.js').InstanceModel} */
|
|
37
|
+
const Instance = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.Instance;
|
|
38
|
+
return await Instance.findByIdAndUpdate(req.params.id, req.body);
|
|
39
|
+
},
|
|
40
|
+
delete: async (req, res, options) => {
|
|
41
|
+
/** @type {import('./instance.model.js').InstanceModel} */
|
|
42
|
+
const Instance = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.Instance;
|
|
43
|
+
if (req.params.id) return await Instance.findByIdAndDelete(req.params.id);
|
|
44
|
+
else return await await Instance.deleteMany();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { InstanceService };
|