@aurostack/stacks 0.1.0
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/LICENSE +21 -0
- package/README.md +209 -0
- package/cli/src/extract.mjs +165 -0
- package/cli/src/fsx.mjs +197 -0
- package/cli/src/generate.mjs +235 -0
- package/cli/src/hooks.mjs +55 -0
- package/cli/src/manifest.mjs +163 -0
- package/cli/src/strip.mjs +208 -0
- package/cli/src/tokens.mjs +102 -0
- package/cli/stack.mjs +672 -0
- package/package.json +37 -0
- package/templates/nest-api/files/.bin/db.ts +123 -0
- package/templates/nest-api/files/.bin/dc.ts +74 -0
- package/templates/nest-api/files/.bin/helpers.ts +49 -0
- package/templates/nest-api/files/.bin/secrets.ts +68 -0
- package/templates/nest-api/files/.bin/start.ts +47 -0
- package/templates/nest-api/files/.dockerignore +7 -0
- package/templates/nest-api/files/.env.example +91 -0
- package/templates/nest-api/files/.env.test.example +75 -0
- package/templates/nest-api/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/nest-api/files/.forgejo/workflows/test-e2e.yml +83 -0
- package/templates/nest-api/files/.forgejo/workflows/test.yml +53 -0
- package/templates/nest-api/files/.npmrc.example +1 -0
- package/templates/nest-api/files/.nvmrc +1 -0
- package/templates/nest-api/files/.prettierrc +8 -0
- package/templates/nest-api/files/.swcrc +15 -0
- package/templates/nest-api/files/.watchmanconfig +3 -0
- package/templates/nest-api/files/.yarnrc.yml +1 -0
- package/templates/nest-api/files/Dockerfile +40 -0
- package/templates/nest-api/files/__mocks__/activation-twofa.js +7 -0
- package/templates/nest-api/files/__mocks__/activation.js +7 -0
- package/templates/nest-api/files/__mocks__/forgot-password.js +7 -0
- package/templates/nest-api/files/__mocks__/main-layout.js +7 -0
- package/templates/nest-api/files/__mocks__/password-changed.js +7 -0
- package/templates/nest-api/files/__mocks__/reset-password.js +7 -0
- package/templates/nest-api/files/__mocks__/set-password.js +7 -0
- package/templates/nest-api/files/__mocks__/welcome.js +7 -0
- package/templates/nest-api/files/_gitignore +62 -0
- package/templates/nest-api/files/compose.test.yml +33 -0
- package/templates/nest-api/files/compose.yml +39 -0
- package/templates/nest-api/files/emails/activation-twofa.tsx +58 -0
- package/templates/nest-api/files/emails/activation.tsx +36 -0
- package/templates/nest-api/files/emails/forgot-password.tsx +29 -0
- package/templates/nest-api/files/emails/main-layout.tsx +134 -0
- package/templates/nest-api/files/emails/password-changed.tsx +24 -0
- package/templates/nest-api/files/emails/reset-password.tsx +24 -0
- package/templates/nest-api/files/emails/set-password.tsx +25 -0
- package/templates/nest-api/files/emails/welcome.tsx +39 -0
- package/templates/nest-api/files/eslint.config.mjs +28 -0
- package/templates/nest-api/files/global.d.ts +5 -0
- package/templates/nest-api/files/nest-cli.json +8 -0
- package/templates/nest-api/files/package.json +150 -0
- package/templates/nest-api/files/prisma/schema/auth.prisma +75 -0
- package/templates/nest-api/files/prisma/schema/base.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/enum.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/notification.prisma +14 -0
- package/templates/nest-api/files/prisma.config.ts +13 -0
- package/templates/nest-api/files/public/.gitkeep +0 -0
- package/templates/nest-api/files/seeders/index.ts +27 -0
- package/templates/nest-api/files/seeders/util.ts +88 -0
- package/templates/nest-api/files/src/__tests__/app.controller.spec.ts +29 -0
- package/templates/nest-api/files/src/app.controller.ts +40 -0
- package/templates/nest-api/files/src/app.module.ts +268 -0
- package/templates/nest-api/files/src/app.resolver.ts +32 -0
- package/templates/nest-api/files/src/app.setup.ts +178 -0
- package/templates/nest-api/files/src/common/__tests__/auth.service.spec.ts +31 -0
- package/templates/nest-api/files/src/common/__tests__/cache.service.spec.ts +214 -0
- package/templates/nest-api/files/src/common/__tests__/config.service.spec.ts +56 -0
- package/templates/nest-api/files/src/common/__tests__/generator.service.spec.ts +114 -0
- package/templates/nest-api/files/src/common/__tests__/health.controller.spec.ts +72 -0
- package/templates/nest-api/files/src/common/__tests__/helpers.spec.ts +124 -0
- package/templates/nest-api/files/src/common/__tests__/mail.service.spec.ts +75 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.indicator.spec.ts +39 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.service.spec.ts +15 -0
- package/templates/nest-api/files/src/common/__tests__/records.spec.ts +87 -0
- package/templates/nest-api/files/src/common/__tests__/schemas.spec.ts +142 -0
- package/templates/nest-api/files/src/common/__tests__/throttler-storage.service.spec.ts +80 -0
- package/templates/nest-api/files/src/common/common.module.ts +72 -0
- package/templates/nest-api/files/src/common/constants/index.ts +2 -0
- package/templates/nest-api/files/src/common/constants/options.ts +52 -0
- package/templates/nest-api/files/src/common/constants/pino.ts +24 -0
- package/templates/nest-api/files/src/common/controllers/health.controller.ts +54 -0
- package/templates/nest-api/files/src/common/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/common/controllers/metrics.controller.ts +21 -0
- package/templates/nest-api/files/src/common/decorators/index.ts +2 -0
- package/templates/nest-api/files/src/common/decorators/misc.decorator.ts +49 -0
- package/templates/nest-api/files/src/common/decorators/multi-part.decorator.ts +6 -0
- package/templates/nest-api/files/src/common/dto/filters.dto.ts +25 -0
- package/templates/nest-api/files/src/common/dto/index.ts +1 -0
- package/templates/nest-api/files/src/common/entity/index.ts +2 -0
- package/templates/nest-api/files/src/common/entity/ok.entity.ts +11 -0
- package/templates/nest-api/files/src/common/entity/pagination.entity.ts +24 -0
- package/templates/nest-api/files/src/common/exceptions/index.ts +1 -0
- package/templates/nest-api/files/src/common/exceptions/prisma.exception.ts +57 -0
- package/templates/nest-api/files/src/common/guards/feature-flag.guard.ts +51 -0
- package/templates/nest-api/files/src/common/guards/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/metrics.interceptor.ts +37 -0
- package/templates/nest-api/files/src/common/misc/helpers.ts +26 -0
- package/templates/nest-api/files/src/common/misc/index.ts +3 -0
- package/templates/nest-api/files/src/common/misc/origin-builder.ts +56 -0
- package/templates/nest-api/files/src/common/misc/prisma.indicator.ts +24 -0
- package/templates/nest-api/files/src/common/modules/index.ts +3 -0
- package/templates/nest-api/files/src/common/modules/logger.module.ts +104 -0
- package/templates/nest-api/files/src/common/modules/metrics.module.ts +28 -0
- package/templates/nest-api/files/src/common/modules/queue.module.ts +23 -0
- package/templates/nest-api/files/src/common/processors/index.ts +1 -0
- package/templates/nest-api/files/src/common/processors/mail/index.ts +47 -0
- package/templates/nest-api/files/src/common/processors/mail/process.ts +225 -0
- package/templates/nest-api/files/src/common/schemas/fields.ts +76 -0
- package/templates/nest-api/files/src/common/schemas/index.ts +1 -0
- package/templates/nest-api/files/src/common/services/auth-rate-limit.storage.ts +79 -0
- package/templates/nest-api/files/src/common/services/auth.service.ts +16 -0
- package/templates/nest-api/files/src/common/services/cache.service.ts +118 -0
- package/templates/nest-api/files/src/common/services/config.service.ts +388 -0
- package/templates/nest-api/files/src/common/services/feature-flag.service.ts +117 -0
- package/templates/nest-api/files/src/common/services/generator.service.ts +54 -0
- package/templates/nest-api/files/src/common/services/index.ts +10 -0
- package/templates/nest-api/files/src/common/services/logger.service.ts +14 -0
- package/templates/nest-api/files/src/common/services/mail.service.ts +44 -0
- package/templates/nest-api/files/src/common/services/prisma.service.ts +106 -0
- package/templates/nest-api/files/src/common/services/throttler-storage.service.ts +112 -0
- package/templates/nest-api/files/src/common/types/email.ts +55 -0
- package/templates/nest-api/files/src/common/types/index.ts +3 -0
- package/templates/nest-api/files/src/common/types/misc.ts +20 -0
- package/templates/nest-api/files/src/common/types/prisma.ts +18 -0
- package/templates/nest-api/files/src/common/utils/enum.ts +39 -0
- package/templates/nest-api/files/src/common/utils/helpers.ts +139 -0
- package/templates/nest-api/files/src/common/utils/index.ts +5 -0
- package/templates/nest-api/files/src/common/utils/ip.ts +22 -0
- package/templates/nest-api/files/src/common/utils/records.ts +66 -0
- package/templates/nest-api/files/src/common/utils/redis.keys.ts +31 -0
- package/templates/nest-api/files/src/lib/__tests__/access.spec.ts +33 -0
- package/templates/nest-api/files/src/lib/access.ts +114 -0
- package/templates/nest-api/files/src/lib/auth.ts +76 -0
- package/templates/nest-api/files/src/lib/rate-limit.ts +20 -0
- package/templates/nest-api/files/src/main.ts +28 -0
- package/templates/nest-api/files/src/media/__tests__/media.service.spec.ts +60 -0
- package/templates/nest-api/files/src/media/__tests__/s3.service.spec.ts +159 -0
- package/templates/nest-api/files/src/media/entity/file.entity.ts +7 -0
- package/templates/nest-api/files/src/media/entity/index.ts +1 -0
- package/templates/nest-api/files/src/media/media.module.ts +20 -0
- package/templates/nest-api/files/src/media/processors/index.ts +44 -0
- package/templates/nest-api/files/src/media/services/index.ts +2 -0
- package/templates/nest-api/files/src/media/services/media.service.ts +29 -0
- package/templates/nest-api/files/src/media/services/s3.service.ts +168 -0
- package/templates/nest-api/files/src/notifications/controllers/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/controllers/notifications.controller.ts +72 -0
- package/templates/nest-api/files/src/notifications/dto/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/dto/notification.dto.ts +11 -0
- package/templates/nest-api/files/src/notifications/entity/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/entity/notification.entity.ts +37 -0
- package/templates/nest-api/files/src/notifications/notifications.module.ts +11 -0
- package/templates/nest-api/files/src/notifications/services/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/services/notifications.service.ts +98 -0
- package/templates/nest-api/files/src/realtime/__tests__/events.gateway.spec.ts +88 -0
- package/templates/nest-api/files/src/realtime/__tests__/rooms.spec.ts +29 -0
- package/templates/nest-api/files/src/realtime/__tests__/ws-permissions.guard.spec.ts +54 -0
- package/templates/nest-api/files/src/realtime/adapters/redis-io.adapter.ts +57 -0
- package/templates/nest-api/files/src/realtime/constants/index.ts +68 -0
- package/templates/nest-api/files/src/realtime/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/realtime/decorators/ws-permissions.decorator.ts +14 -0
- package/templates/nest-api/files/src/realtime/gateways/events.gateway.ts +187 -0
- package/templates/nest-api/files/src/realtime/guards/index.ts +2 -0
- package/templates/nest-api/files/src/realtime/guards/ws-auth.guard.ts +20 -0
- package/templates/nest-api/files/src/realtime/guards/ws-permissions.guard.ts +35 -0
- package/templates/nest-api/files/src/realtime/misc/session-from-socket.ts +54 -0
- package/templates/nest-api/files/src/realtime/realtime.module.ts +26 -0
- package/templates/nest-api/files/src/realtime/services/presence.service.ts +56 -0
- package/templates/nest-api/files/src/realtime/services/realtime.service.ts +72 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.controller.spec.ts +77 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.service.spec.ts +159 -0
- package/templates/nest-api/files/src/users/__tests__/user.entity.spec.ts +175 -0
- package/templates/nest-api/files/src/users/__tests__/users.controller.spec.ts +89 -0
- package/templates/nest-api/files/src/users/__tests__/users.service.spec.ts +398 -0
- package/templates/nest-api/files/src/users/controllers/current-user.controller.ts +82 -0
- package/templates/nest-api/files/src/users/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/users/controllers/users.controller.ts +40 -0
- package/templates/nest-api/files/src/users/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/users/decorators/permissions.decorator.ts +24 -0
- package/templates/nest-api/files/src/users/dto/avatar.dto.ts +13 -0
- package/templates/nest-api/files/src/users/dto/filters.dto.ts +8 -0
- package/templates/nest-api/files/src/users/dto/index.ts +2 -0
- package/templates/nest-api/files/src/users/entity/index.ts +1 -0
- package/templates/nest-api/files/src/users/entity/user.entity.ts +53 -0
- package/templates/nest-api/files/src/users/services/current-user.service.ts +46 -0
- package/templates/nest-api/files/src/users/services/index.ts +2 -0
- package/templates/nest-api/files/src/users/services/users.service.ts +88 -0
- package/templates/nest-api/files/src/users/users.module.ts +10 -0
- package/templates/nest-api/files/test/app.spec.ts +102 -0
- package/templates/nest-api/files/test/auth.spec.ts +108 -0
- package/templates/nest-api/files/test/current-user.spec.ts +154 -0
- package/templates/nest-api/files/test/factory/app.ts +172 -0
- package/templates/nest-api/files/test/factory/constants.ts +22 -0
- package/templates/nest-api/files/test/factory/dto.ts +27 -0
- package/templates/nest-api/files/test/factory/entity.ts +70 -0
- package/templates/nest-api/files/test/factory/gen.ts +75 -0
- package/templates/nest-api/files/test/factory/util.ts +21 -0
- package/templates/nest-api/files/test/notifications.spec.ts +176 -0
- package/templates/nest-api/files/test/rate-limit.spec.ts +180 -0
- package/templates/nest-api/files/test/setup.ts +1 -0
- package/templates/nest-api/files/test/users.spec.ts +437 -0
- package/templates/nest-api/files/tsconfig.build.json +13 -0
- package/templates/nest-api/files/tsconfig.json +35 -0
- package/templates/nest-api/files/vitest.config.ts +53 -0
- package/templates/nest-api/template.json +452 -0
- package/templates/node-worker/files/.bin/db.ts +123 -0
- package/templates/node-worker/files/.bin/helpers.ts +49 -0
- package/templates/node-worker/files/.bin/secrets.ts +68 -0
- package/templates/node-worker/files/.dockerignore +5 -0
- package/templates/node-worker/files/.env.example +21 -0
- package/templates/node-worker/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/node-worker/files/.nvmrc +1 -0
- package/templates/node-worker/files/.prettierignore +4 -0
- package/templates/node-worker/files/.prettierrc +8 -0
- package/templates/node-worker/files/.yarnrc.yml +5 -0
- package/templates/node-worker/files/Dockerfile +63 -0
- package/templates/node-worker/files/Dockerfile.dev +59 -0
- package/templates/node-worker/files/_gitignore +48 -0
- package/templates/node-worker/files/ecosystem.config.cjs +10 -0
- package/templates/node-worker/files/eslint.config.js +37 -0
- package/templates/node-worker/files/package.json +67 -0
- package/templates/node-worker/files/prisma/_gitignore +1 -0
- package/templates/node-worker/files/prisma/schema/base.prisma +36 -0
- package/templates/node-worker/files/prisma.config.ts +13 -0
- package/templates/node-worker/files/src/config.ts +55 -0
- package/templates/node-worker/files/src/db.ts +118 -0
- package/templates/node-worker/files/src/index.ts +7 -0
- package/templates/node-worker/files/src/logger.ts +45 -0
- package/templates/node-worker/files/src/types.ts +23 -0
- package/templates/node-worker/files/src/utils/browser.ts +16 -0
- package/templates/node-worker/files/src/utils/date.ts +68 -0
- package/templates/node-worker/files/src/utils/helpers.ts +17 -0
- package/templates/node-worker/files/src/utils/number.ts +47 -0
- package/templates/node-worker/files/src/utils/worker.ts +29 -0
- package/templates/node-worker/files/src/workers/constants.ts +6 -0
- package/templates/node-worker/files/src/workers/example/index.ts +27 -0
- package/templates/node-worker/files/src/workers/index.ts +1 -0
- package/templates/node-worker/files/tsconfig.json +30 -0
- package/templates/node-worker/template.json +135 -0
- package/templates/py-worker/files/.dockerignore +176 -0
- package/templates/py-worker/files/.env.example +20 -0
- package/templates/py-worker/files/.forgejo/workflows/build-amd-push.yml +39 -0
- package/templates/py-worker/files/Dockerfile +10 -0
- package/templates/py-worker/files/README.md +3 -0
- package/templates/py-worker/files/_gitignore +176 -0
- package/templates/py-worker/files/config.py +89 -0
- package/templates/py-worker/files/models/decorators.py +42 -0
- package/templates/py-worker/files/models/enums.py +32 -0
- package/templates/py-worker/files/models/mixins.py +61 -0
- package/templates/py-worker/files/requirements.txt +18 -0
- package/templates/py-worker/files/utils/db.py +67 -0
- package/templates/py-worker/files/utils/logger.py +97 -0
- package/templates/py-worker/files/utils/misc.py +45 -0
- package/templates/py-worker/files/utils/worker.py +80 -0
- package/templates/py-worker/files/worker.py +41 -0
- package/templates/py-worker/files/workers/hello/process.py +22 -0
- package/templates/py-worker/template.json +87 -0
- package/templates/react-app/README.md +78 -0
- package/templates/react-app/derive.sh +128 -0
- package/templates/react-app/files/.bin/openapi.js +32 -0
- package/templates/react-app/files/.bin/secrets.js +47 -0
- package/templates/react-app/files/.dockerignore +16 -0
- package/templates/react-app/files/.editorconfig +12 -0
- package/templates/react-app/files/.env.example +34 -0
- package/templates/react-app/files/.forgejo/workflows/build-and-push.yml +55 -0
- package/templates/react-app/files/.forgejo/workflows/ci.yml +39 -0
- package/templates/react-app/files/.husky/pre-commit +1 -0
- package/templates/react-app/files/.nvmrc +1 -0
- package/templates/react-app/files/.prettierignore +6 -0
- package/templates/react-app/files/.prettierrc +9 -0
- package/templates/react-app/files/.yarnrc.yml +2 -0
- package/templates/react-app/files/Dockerfile +52 -0
- package/templates/react-app/files/_gitignore +33 -0
- package/templates/react-app/files/build.sh +53 -0
- package/templates/react-app/files/docker/nginx.conf +134 -0
- package/templates/react-app/files/eslint.config.mjs +75 -0
- package/templates/react-app/files/index.html +62 -0
- package/templates/react-app/files/openapi-ts.config.ts +22 -0
- package/templates/react-app/files/package.json +80 -0
- package/templates/react-app/files/src/app/nav.tsx +32 -0
- package/templates/react-app/files/src/app/providers.tsx +39 -0
- package/templates/react-app/files/src/app/router.tsx +142 -0
- package/templates/react-app/files/src/app/store.ts +20 -0
- package/templates/react-app/files/src/features/auth/components/auth-card.tsx +23 -0
- package/templates/react-app/files/src/features/auth/components/checkbox-field.tsx +32 -0
- package/templates/react-app/files/src/features/auth/components/google-button.tsx +41 -0
- package/templates/react-app/files/src/features/auth/components/or-divider.tsx +9 -0
- package/templates/react-app/files/src/features/auth/components/password-field.tsx +70 -0
- package/templates/react-app/files/src/features/auth/components/submit-button.tsx +16 -0
- package/templates/react-app/files/src/features/auth/lib/auth-actions.ts +68 -0
- package/templates/react-app/files/src/features/auth/lib/password-strength.ts +20 -0
- package/templates/react-app/files/src/features/auth/lib/redirect.ts +6 -0
- package/templates/react-app/files/src/features/auth/lib/schemas.ts +37 -0
- package/templates/react-app/files/src/features/seo/routes.ts +65 -0
- package/templates/react-app/files/src/lib/env.ts +28 -0
- package/templates/react-app/files/src/lib/paths.ts +58 -0
- package/templates/react-app/files/src/main.tsx +19 -0
- package/templates/react-app/files/src/routes/admin/home.tsx +24 -0
- package/templates/react-app/files/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/files/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/files/src/routes/auth/reset-password.tsx +83 -0
- package/templates/react-app/files/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/files/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/files/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/files/src/routes/home.tsx +17 -0
- package/templates/react-app/files/src/routes/legal/privacy.tsx +26 -0
- package/templates/react-app/files/src/routes/legal/terms.tsx +28 -0
- package/templates/react-app/files/src/routes/marketing/home.tsx +18 -0
- package/templates/react-app/files/src/routes/settings.tsx +10 -0
- package/templates/react-app/files/src/shared/api/base-api.ts +24 -0
- package/templates/react-app/files/src/shared/api/base-query.ts +29 -0
- package/templates/react-app/files/src/shared/api/config.ts +21 -0
- package/templates/react-app/files/src/shared/api/index.ts +15 -0
- package/templates/react-app/files/src/shared/api/realtime-events.ts +34 -0
- package/templates/react-app/files/src/shared/api/socket.ts +41 -0
- package/templates/react-app/files/src/shared/api/store.ts +39 -0
- package/templates/react-app/files/src/shared/api/upload-query.ts +115 -0
- package/templates/react-app/files/src/shared/auth/client.ts +27 -0
- package/templates/react-app/files/src/shared/auth/config.ts +28 -0
- package/templates/react-app/files/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/files/src/shared/auth/hooks.ts +13 -0
- package/templates/react-app/files/src/shared/auth/index.ts +20 -0
- package/templates/react-app/files/src/shared/auth/logout.ts +23 -0
- package/templates/react-app/files/src/shared/auth/provider.tsx +52 -0
- package/templates/react-app/files/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/files/src/shared/auth/slice.ts +54 -0
- package/templates/react-app/files/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/app-shell.tsx +225 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/user-menu.tsx +74 -0
- package/templates/react-app/files/src/shared/layouts/auth-layout.tsx +137 -0
- package/templates/react-app/files/src/shared/layouts/error-boundary.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/index.ts +23 -0
- package/templates/react-app/files/src/shared/layouts/marketing/marketing-layout.tsx +29 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section-heading.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section.tsx +30 -0
- package/templates/react-app/files/src/shared/layouts/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-app/files/src/shared/layouts/states/empty.tsx +22 -0
- package/templates/react-app/files/src/shared/layouts/states/forbidden.tsx +14 -0
- package/templates/react-app/files/src/shared/layouts/states/loading.tsx +11 -0
- package/templates/react-app/files/src/shared/layouts/states/not-found.tsx +21 -0
- package/templates/react-app/files/src/shared/layouts/states/page-skeleton.tsx +39 -0
- package/templates/react-app/files/src/shared/layouts/states/route-fallback.tsx +26 -0
- package/templates/react-app/files/src/shared/layouts/states/state-screen.tsx +22 -0
- package/templates/react-app/files/src/shared/types/README.md +28 -0
- package/templates/react-app/files/src/shared/types/api/index.ts +9 -0
- package/templates/react-app/files/src/shared/types/api/zod.gen.ts +5 -0
- package/templates/react-app/files/src/shared/types/index.ts +4 -0
- package/templates/react-app/files/src/shared/ui/components/brand/logo.tsx +51 -0
- package/templates/react-app/files/src/shared/ui/components/brand/social-icons.tsx +37 -0
- package/templates/react-app/files/src/shared/ui/components/form/form.tsx +120 -0
- package/templates/react-app/files/src/shared/ui/components/ui/alert.tsx +25 -0
- package/templates/react-app/files/src/shared/ui/components/ui/button.tsx +43 -0
- package/templates/react-app/files/src/shared/ui/components/ui/calendar.tsx +78 -0
- package/templates/react-app/files/src/shared/ui/components/ui/card.tsx +44 -0
- package/templates/react-app/files/src/shared/ui/components/ui/checkbox.tsx +16 -0
- package/templates/react-app/files/src/shared/ui/components/ui/date-picker.tsx +76 -0
- package/templates/react-app/files/src/shared/ui/components/ui/input.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/components/ui/label.tsx +19 -0
- package/templates/react-app/files/src/shared/ui/components/ui/modal.tsx +94 -0
- package/templates/react-app/files/src/shared/ui/components/ui/popover.tsx +31 -0
- package/templates/react-app/files/src/shared/ui/components/ui/progress.tsx +33 -0
- package/templates/react-app/files/src/shared/ui/components/ui/search-input.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/components/ui/select.tsx +80 -0
- package/templates/react-app/files/src/shared/ui/components/ui/skeleton.tsx +12 -0
- package/templates/react-app/files/src/shared/ui/components/ui/sonner.tsx +23 -0
- package/templates/react-app/files/src/shared/ui/components/ui/spinner.tsx +8 -0
- package/templates/react-app/files/src/shared/ui/components/ui/textarea.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/index.ts +45 -0
- package/templates/react-app/files/src/shared/ui/lib/utils.ts +7 -0
- package/templates/react-app/files/src/shared/ui/lib/zod-setup.ts +28 -0
- package/templates/react-app/files/src/shared/ui/meta/brand.ts +18 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-context.ts +30 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-provider.tsx +24 -0
- package/templates/react-app/files/src/shared/ui/meta/page-meta.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/meta/use-meta-config.ts +11 -0
- package/templates/react-app/files/src/shared/ui/styles/globals.css +285 -0
- package/templates/react-app/files/src/shared/ui/styles/theme.css +48 -0
- package/templates/react-app/files/src/shared/ui/theme/init-script.ts +23 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-colors.ts +14 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-context.ts +60 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-provider.tsx +101 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-toggle.tsx +40 -0
- package/templates/react-app/files/src/shared/ui/theme/use-theme.ts +11 -0
- package/templates/react-app/files/src/vite-env.d.ts +13 -0
- package/templates/react-app/files/tsconfig.json +26 -0
- package/templates/react-app/files/tsconfig.node.json +25 -0
- package/templates/react-app/files/vite.config.ts +344 -0
- package/templates/react-app/overrides/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/overrides/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/overrides/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/overrides/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/overrides/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/overrides/src/shared/auth/config.ts +28 -0
- package/templates/react-app/overrides/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/overrides/src/shared/auth/index.ts +20 -0
- package/templates/react-app/overrides/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/overrides/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/overrides/src/shared/types/README.md +28 -0
- package/templates/react-app/template.json +222 -0
- package/templates/react-monorepo/files/.dockerignore +19 -0
- package/templates/react-monorepo/files/.editorconfig +12 -0
- package/templates/react-monorepo/files/.forgejo/workflows/build-and-push.yml +98 -0
- package/templates/react-monorepo/files/.forgejo/workflows/ci.yml +35 -0
- package/templates/react-monorepo/files/.husky/pre-commit +1 -0
- package/templates/react-monorepo/files/.nvmrc +1 -0
- package/templates/react-monorepo/files/.prettierignore +6 -0
- package/templates/react-monorepo/files/.prettierrc +9 -0
- package/templates/react-monorepo/files/.yarnrc.yml +2 -0
- package/templates/react-monorepo/files/Dockerfile +90 -0
- package/templates/react-monorepo/files/_gitignore +35 -0
- package/templates/react-monorepo/files/apps/admin/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/admin/.env.example +16 -0
- package/templates/react-monorepo/files/apps/admin/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/admin/index.html +57 -0
- package/templates/react-monorepo/files/apps/admin/package.json +33 -0
- package/templates/react-monorepo/files/apps/admin/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/admin/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/admin/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/admin/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/admin/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/admin/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/admin/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/admin/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/admin/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/auth/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/auth/.env.example +16 -0
- package/templates/react-monorepo/files/apps/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/auth/index.html +57 -0
- package/templates/react-monorepo/files/apps/auth/package.json +32 -0
- package/templates/react-monorepo/files/apps/auth/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/auth/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/auth/src/app/router.tsx +19 -0
- package/templates/react-monorepo/files/apps/auth/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/auth/src/components/auth-card.tsx +23 -0
- package/templates/react-monorepo/files/apps/auth/src/components/checkbox-field.tsx +32 -0
- package/templates/react-monorepo/files/apps/auth/src/components/google-button.tsx +41 -0
- package/templates/react-monorepo/files/apps/auth/src/components/or-divider.tsx +9 -0
- package/templates/react-monorepo/files/apps/auth/src/components/password-field.tsx +70 -0
- package/templates/react-monorepo/files/apps/auth/src/components/submit-button.tsx +16 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/auth-actions.ts +68 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/env.ts +8 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/password-strength.ts +20 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/redirect.ts +6 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/schemas.ts +37 -0
- package/templates/react-monorepo/files/apps/auth/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/forgot-password.tsx +91 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/login.tsx +82 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/reset-password.tsx +83 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/signup.tsx +117 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verified.tsx +30 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verify-email.tsx +96 -0
- package/templates/react-monorepo/files/apps/auth/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/auth/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/auth/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/client/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/client/.env.example +16 -0
- package/templates/react-monorepo/files/apps/client/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/client/index.html +57 -0
- package/templates/react-monorepo/files/apps/client/package.json +35 -0
- package/templates/react-monorepo/files/apps/client/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/client/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/client/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/client/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/client/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/client/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/client/src/main.tsx +19 -0
- package/templates/react-monorepo/files/apps/client/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/client/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/client/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/client/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/client/vite.config.ts +120 -0
- package/templates/react-monorepo/files/apps/landing/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/landing/.env.example +20 -0
- package/templates/react-monorepo/files/apps/landing/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/landing/index.html +51 -0
- package/templates/react-monorepo/files/apps/landing/package.json +33 -0
- package/templates/react-monorepo/files/apps/landing/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/landing/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/landing/src/app/router.tsx +21 -0
- package/templates/react-monorepo/files/apps/landing/src/app/store.ts +18 -0
- package/templates/react-monorepo/files/apps/landing/src/features/seo/routes.ts +65 -0
- package/templates/react-monorepo/files/apps/landing/src/lib/env.ts +10 -0
- package/templates/react-monorepo/files/apps/landing/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/landing/src/routes/home.tsx +18 -0
- package/templates/react-monorepo/files/apps/landing/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/landing/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/landing/vite.config.ts +169 -0
- package/templates/react-monorepo/files/build.sh +61 -0
- package/templates/react-monorepo/files/docker/nginx.conf +136 -0
- package/templates/react-monorepo/files/package.json +37 -0
- package/templates/react-monorepo/files/packages/.gitkeep +0 -0
- package/templates/react-monorepo/files/packages/api/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/api/package.json +30 -0
- package/templates/react-monorepo/files/packages/api/src/base-api.ts +24 -0
- package/templates/react-monorepo/files/packages/api/src/base-query.ts +29 -0
- package/templates/react-monorepo/files/packages/api/src/config.ts +21 -0
- package/templates/react-monorepo/files/packages/api/src/index.ts +15 -0
- package/templates/react-monorepo/files/packages/api/src/realtime-events.ts +34 -0
- package/templates/react-monorepo/files/packages/api/src/socket.ts +41 -0
- package/templates/react-monorepo/files/packages/api/src/store.ts +39 -0
- package/templates/react-monorepo/files/packages/api/src/upload-query.ts +115 -0
- package/templates/react-monorepo/files/packages/api/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/auth/package.json +33 -0
- package/templates/react-monorepo/files/packages/auth/src/client.ts +27 -0
- package/templates/react-monorepo/files/packages/auth/src/config.ts +22 -0
- package/templates/react-monorepo/files/packages/auth/src/guards.tsx +61 -0
- package/templates/react-monorepo/files/packages/auth/src/hooks.ts +13 -0
- package/templates/react-monorepo/files/packages/auth/src/index.ts +20 -0
- package/templates/react-monorepo/files/packages/auth/src/logout.ts +23 -0
- package/templates/react-monorepo/files/packages/auth/src/provider.tsx +52 -0
- package/templates/react-monorepo/files/packages/auth/src/redirect.ts +37 -0
- package/templates/react-monorepo/files/packages/auth/src/slice.ts +54 -0
- package/templates/react-monorepo/files/packages/auth/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/config/README.md +47 -0
- package/templates/react-monorepo/files/packages/config/eslint/base.mjs +83 -0
- package/templates/react-monorepo/files/packages/config/package.json +37 -0
- package/templates/react-monorepo/files/packages/config/tailwind/theme.css +48 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/base.json +22 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/node.json +9 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/react.json +9 -0
- package/templates/react-monorepo/files/packages/config/vite/index.d.ts +18 -0
- package/templates/react-monorepo/files/packages/config/vite/index.mjs +129 -0
- package/templates/react-monorepo/files/packages/hooks/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/hooks/package.json +16 -0
- package/templates/react-monorepo/files/packages/hooks/src/index.ts +3 -0
- package/templates/react-monorepo/files/packages/hooks/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/layouts/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/layouts/package.json +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/app-shell.tsx +225 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/user-menu.tsx +74 -0
- package/templates/react-monorepo/files/packages/layouts/src/auth-layout.tsx +137 -0
- package/templates/react-monorepo/files/packages/layouts/src/error-boundary.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/index.ts +23 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/marketing-layout.tsx +29 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section-heading.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section.tsx +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/empty.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/forbidden.tsx +14 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/loading.tsx +11 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/not-found.tsx +21 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/page-skeleton.tsx +39 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/route-fallback.tsx +26 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/state-screen.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/types/.bin/openapi.js +32 -0
- package/templates/react-monorepo/files/packages/types/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/packages/types/README.md +28 -0
- package/templates/react-monorepo/files/packages/types/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/types/openapi-ts.config.ts +22 -0
- package/templates/react-monorepo/files/packages/types/package.json +29 -0
- package/templates/react-monorepo/files/packages/types/src/index.ts +4 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/index.ts +9 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/zod.gen.ts +5 -0
- package/templates/react-monorepo/files/packages/types/tsconfig.json +7 -0
- package/templates/react-monorepo/files/packages/ui/components.json +21 -0
- package/templates/react-monorepo/files/packages/ui/eslint.config.mjs +13 -0
- package/templates/react-monorepo/files/packages/ui/package.json +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/logo.tsx +51 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/social-icons.tsx +37 -0
- package/templates/react-monorepo/files/packages/ui/src/components/form/form.tsx +120 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/alert.tsx +25 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/button.tsx +43 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/calendar.tsx +78 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/card.tsx +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/checkbox.tsx +16 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/date-picker.tsx +76 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/input.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/label.tsx +19 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/modal.tsx +94 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/popover.tsx +31 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/progress.tsx +33 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/search-input.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/select.tsx +80 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/skeleton.tsx +12 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/sonner.tsx +23 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/spinner.tsx +8 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/textarea.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/index.ts +45 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/utils.ts +7 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/zod-setup.ts +28 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/brand.ts +18 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-context.ts +30 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-provider.tsx +24 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/page-meta.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/use-meta-config.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/src/styles/globals.css +285 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/init-script.ts +23 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-colors.ts +14 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-context.ts +60 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-provider.tsx +101 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-toggle.tsx +40 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/use-theme.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/tsconfig.json +9 -0
- package/templates/react-monorepo/files/turbo.json +24 -0
- package/templates/react-monorepo/template.json +230 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { TestBed, type Mocked } from '@suites/unit';
|
|
2
|
+
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
|
3
|
+
import { Gen } from '@test/factory/gen';
|
|
4
|
+
import { Entity } from '@test/factory/entity';
|
|
5
|
+
import { Dto } from '@test/factory/dto';
|
|
6
|
+
import { PrismaService } from 'common/services';
|
|
7
|
+
import { UsersService } from '../services';
|
|
8
|
+
import { PaginatedUserEntity, UserEntity } from '../entity';
|
|
9
|
+
import { OKEntity } from 'common/entity';
|
|
10
|
+
|
|
11
|
+
describe('UsersService', () => {
|
|
12
|
+
let service: UsersService;
|
|
13
|
+
let db: Mocked<PrismaService>;
|
|
14
|
+
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
const { unit, unitRef } = await TestBed.solitary(UsersService).compile();
|
|
17
|
+
service = unit;
|
|
18
|
+
db = unitRef.get(PrismaService);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should be defined', () => {
|
|
22
|
+
expect(service).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('paginate', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.clearAllMocks();
|
|
28
|
+
// Every role the specs filter by is one some user holds.
|
|
29
|
+
db.x.user.exists.mockResolvedValue(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const currentUser = Entity.requestUser.build({ role: 'admin' });
|
|
33
|
+
const getCallArgs = (): any => db.x.user.paginate.mock.calls[0][0];
|
|
34
|
+
|
|
35
|
+
it('should return a PaginatedUserEntity', async () => {
|
|
36
|
+
const users = Entity.user.buildList(3);
|
|
37
|
+
db.x.user.paginate.mockResolvedValue([
|
|
38
|
+
users,
|
|
39
|
+
{ total: 3, currentPage: 1, pageSize: 3, lastPage: 1 }
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const result = await service.paginate(currentUser, {});
|
|
43
|
+
expect(PaginatedUserEntity.safeParse(result).success).toBe(true);
|
|
44
|
+
expect(result.list).toHaveLength(3);
|
|
45
|
+
expect(result.total).toBe(3);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('rejects a role no user holds, with a validation error', async () => {
|
|
49
|
+
db.x.user.exists.mockResolvedValue(false);
|
|
50
|
+
|
|
51
|
+
await expect(
|
|
52
|
+
service.paginate(currentUser, Dto.userFilters.build({ role: 'ghost' }))
|
|
53
|
+
).rejects.toThrow(
|
|
54
|
+
new BadRequestException("Validation: role 'ghost' does not exist")
|
|
55
|
+
);
|
|
56
|
+
expect(db.x.user.exists).toHaveBeenCalledWith({
|
|
57
|
+
role: { equals: 'ghost', mode: 'insensitive' }
|
|
58
|
+
});
|
|
59
|
+
expect(db.x.user.paginate).not.toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('skips the role lookup when no role is given', async () => {
|
|
63
|
+
db.x.user.paginate.mockResolvedValue([
|
|
64
|
+
[],
|
|
65
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
await service.paginate(currentUser, {});
|
|
69
|
+
expect(db.x.user.exists).not.toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should exclude the current user from results', async () => {
|
|
73
|
+
db.x.user.paginate.mockResolvedValue([
|
|
74
|
+
[],
|
|
75
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
await service.paginate(currentUser, {});
|
|
79
|
+
|
|
80
|
+
const callArgs = getCallArgs();
|
|
81
|
+
expect(callArgs.where.id).toEqual({ not: currentUser.id });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// The listing is now an allowlist of visible roles rather than a single
|
|
85
|
+
// "not superuser" exclusion, so `moderator` is filterable and superusers
|
|
86
|
+
// are visible to their own tier.
|
|
87
|
+
it('restricts a non-superuser viewer to the non-superuser roles', async () => {
|
|
88
|
+
db.x.user.paginate.mockResolvedValue([
|
|
89
|
+
[],
|
|
90
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
await service.paginate(currentUser, {});
|
|
94
|
+
|
|
95
|
+
const callArgs = getCallArgs();
|
|
96
|
+
expect(callArgs.where.role).toEqual({
|
|
97
|
+
in: ['user', 'moderator', 'admin']
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('lets a superuser see superusers too', async () => {
|
|
102
|
+
db.x.user.paginate.mockResolvedValue([
|
|
103
|
+
[],
|
|
104
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
await service.paginate(
|
|
108
|
+
Entity.requestUser.build({ role: 'superuser' }),
|
|
109
|
+
{}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const callArgs = getCallArgs();
|
|
113
|
+
expect(callArgs.where.role).toEqual({
|
|
114
|
+
in: ['user', 'moderator', 'admin', 'superuser']
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should add search filter for name and email when search is provided', async () => {
|
|
119
|
+
db.x.user.paginate.mockResolvedValue([
|
|
120
|
+
[],
|
|
121
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
await service.paginate(
|
|
125
|
+
currentUser,
|
|
126
|
+
Dto.userFilters.build({ search: 'john' })
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const callArgs = getCallArgs();
|
|
130
|
+
expect(callArgs.where.OR).toEqual([
|
|
131
|
+
{ email: { contains: 'john', mode: 'insensitive' } },
|
|
132
|
+
{ name: { contains: 'john', mode: 'insensitive' } }
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should trim the search string', async () => {
|
|
137
|
+
db.x.user.paginate.mockResolvedValue([
|
|
138
|
+
[],
|
|
139
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
await service.paginate(
|
|
143
|
+
currentUser,
|
|
144
|
+
Dto.userFilters.build({ search: ' john ' })
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const callArgs = getCallArgs();
|
|
148
|
+
expect(callArgs.where.OR).toEqual([
|
|
149
|
+
{ email: { contains: 'john', mode: 'insensitive' } },
|
|
150
|
+
{ name: { contains: 'john', mode: 'insensitive' } }
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should skip search filter when search is empty string', async () => {
|
|
155
|
+
db.x.user.paginate.mockResolvedValue([
|
|
156
|
+
[],
|
|
157
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
158
|
+
]);
|
|
159
|
+
|
|
160
|
+
await service.paginate(
|
|
161
|
+
currentUser,
|
|
162
|
+
Dto.userFilters.build({ search: '' })
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const callArgs = getCallArgs();
|
|
166
|
+
expect(callArgs.where.OR).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should skip search filter when search is only whitespace', async () => {
|
|
170
|
+
db.x.user.paginate.mockResolvedValue([
|
|
171
|
+
[],
|
|
172
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
await service.paginate(
|
|
176
|
+
currentUser,
|
|
177
|
+
Dto.userFilters.build({ search: ' ' })
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const callArgs = getCallArgs();
|
|
181
|
+
expect(callArgs.where.OR).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should filter by role when role is "admin"', async () => {
|
|
185
|
+
db.x.user.paginate.mockResolvedValue([
|
|
186
|
+
[],
|
|
187
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
188
|
+
]);
|
|
189
|
+
|
|
190
|
+
await service.paginate(
|
|
191
|
+
currentUser,
|
|
192
|
+
Dto.userFilters.build({ role: 'admin' })
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const callArgs = getCallArgs();
|
|
196
|
+
expect(callArgs.where.role).toBe('admin');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should filter by role when role is "user"', async () => {
|
|
200
|
+
db.x.user.paginate.mockResolvedValue([
|
|
201
|
+
[],
|
|
202
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
203
|
+
]);
|
|
204
|
+
|
|
205
|
+
await service.paginate(
|
|
206
|
+
currentUser,
|
|
207
|
+
Dto.userFilters.build({ role: 'user' })
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const callArgs = getCallArgs();
|
|
211
|
+
expect(callArgs.where.role).toBe('user');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// The security-relevant path: an admin asking for superusers must not get
|
|
215
|
+
// them, and must not get an unfiltered listing either.
|
|
216
|
+
it('falls back to the visible roles when an admin filters by superuser', async () => {
|
|
217
|
+
db.x.user.paginate.mockResolvedValue([
|
|
218
|
+
[],
|
|
219
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
220
|
+
]);
|
|
221
|
+
|
|
222
|
+
await service.paginate(
|
|
223
|
+
currentUser,
|
|
224
|
+
Dto.userFilters.build({ role: 'superuser' })
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const callArgs = getCallArgs();
|
|
228
|
+
expect(callArgs.where.role).toEqual({
|
|
229
|
+
in: ['user', 'moderator', 'admin']
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('honours a superuser filtering by superuser', async () => {
|
|
234
|
+
db.x.user.paginate.mockResolvedValue([
|
|
235
|
+
[],
|
|
236
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
237
|
+
]);
|
|
238
|
+
|
|
239
|
+
await service.paginate(
|
|
240
|
+
Entity.requestUser.build({ role: 'superuser' }),
|
|
241
|
+
Dto.userFilters.build({ role: 'superuser' })
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const callArgs = getCallArgs();
|
|
245
|
+
expect(callArgs.where.role).toBe('superuser');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Previously the role filter only accepted 'admin' | 'user', so asking for
|
|
249
|
+
// moderators silently returned everyone. That was a bug, not a policy.
|
|
250
|
+
it('should filter by role when role is "moderator"', async () => {
|
|
251
|
+
db.x.user.paginate.mockResolvedValue([
|
|
252
|
+
[],
|
|
253
|
+
{ total: 0, currentPage: 1, pageSize: 0, lastPage: 1 }
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
await service.paginate(
|
|
257
|
+
currentUser,
|
|
258
|
+
Dto.userFilters.build({ role: 'moderator' })
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const callArgs = getCallArgs();
|
|
262
|
+
expect(callArgs.where.role).toBe('moderator');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should pass page and limit to paginate', async () => {
|
|
266
|
+
db.x.user.paginate.mockResolvedValue([
|
|
267
|
+
[],
|
|
268
|
+
{ total: 0, currentPage: 3, pageSize: 0, lastPage: 5 }
|
|
269
|
+
]);
|
|
270
|
+
|
|
271
|
+
await service.paginate(
|
|
272
|
+
currentUser,
|
|
273
|
+
Dto.userFilters.build({ page: 3, limit: 5 })
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const callArgs = getCallArgs();
|
|
277
|
+
expect(callArgs.page).toBe(3);
|
|
278
|
+
expect(callArgs.limit).toBe(5);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('getUserById', () => {
|
|
283
|
+
// Takes the whole session user, not just an id: visibility depends on the
|
|
284
|
+
// viewer's role and has to agree with `paginate`.
|
|
285
|
+
const admin = Entity.requestUser.build({ role: 'admin' });
|
|
286
|
+
const superuser = Entity.requestUser.build({ role: 'superuser' });
|
|
287
|
+
|
|
288
|
+
it('should throw NotFoundException when looking up own ID', async () => {
|
|
289
|
+
await expect(service.getUserById(admin, admin.id)).rejects.toThrow(
|
|
290
|
+
NotFoundException
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('should throw NotFoundException when user does not exist', async () => {
|
|
295
|
+
const targetId = Gen.uuid();
|
|
296
|
+
db.user.findFirst.mockResolvedValue(null);
|
|
297
|
+
|
|
298
|
+
await expect(service.getUserById(admin, targetId)).rejects.toThrow(
|
|
299
|
+
NotFoundException
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('hides a superuser from an admin', async () => {
|
|
304
|
+
const targetId = Gen.uuid();
|
|
305
|
+
db.user.findFirst.mockResolvedValue(
|
|
306
|
+
Entity.user.build({ id: targetId, role: 'superuser' })
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
await expect(service.getUserById(admin, targetId)).rejects.toThrow(
|
|
310
|
+
NotFoundException
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// The inconsistency this signature change fixed: `paginate` lists
|
|
315
|
+
// superusers to a superuser, so opening one must not 404.
|
|
316
|
+
it('shows a superuser to another superuser', async () => {
|
|
317
|
+
const targetId = Gen.uuid();
|
|
318
|
+
db.user.findFirst.mockResolvedValue(
|
|
319
|
+
Entity.user.build({ id: targetId, role: 'superuser' })
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const result = await service.getUserById(superuser, targetId);
|
|
323
|
+
expect(UserEntity.safeParse(result).success).toBe(true);
|
|
324
|
+
expect(result.role).toBe('superuser');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('reads a multi-role viewer, not just an exact match', async () => {
|
|
328
|
+
const targetId = Gen.uuid();
|
|
329
|
+
db.user.findFirst.mockResolvedValue(
|
|
330
|
+
Entity.user.build({ id: targetId, role: 'superuser' })
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const result = await service.getUserById(
|
|
334
|
+
Entity.requestUser.build({ role: 'admin,superuser' }),
|
|
335
|
+
targetId
|
|
336
|
+
);
|
|
337
|
+
expect(UserEntity.safeParse(result).success).toBe(true);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should return UserEntity for a valid user', async () => {
|
|
341
|
+
const targetId = Gen.uuid();
|
|
342
|
+
db.user.findFirst.mockResolvedValue(
|
|
343
|
+
Entity.user.build({ id: targetId, role: 'user' })
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const result = await service.getUserById(admin, targetId);
|
|
347
|
+
expect(UserEntity.safeParse(result).success).toBe(true);
|
|
348
|
+
expect(result.id).toBe(targetId);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should return UserEntity for an admin user', async () => {
|
|
352
|
+
const targetId = Gen.uuid();
|
|
353
|
+
db.user.findFirst.mockResolvedValue(
|
|
354
|
+
Entity.user.build({ id: targetId, role: 'admin' })
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
const result = await service.getUserById(admin, targetId);
|
|
358
|
+
expect(UserEntity.safeParse(result).success).toBe(true);
|
|
359
|
+
expect(result.role).toBe('admin');
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should query by id', async () => {
|
|
363
|
+
const targetId = Gen.uuid();
|
|
364
|
+
db.user.findFirst.mockResolvedValue(
|
|
365
|
+
Entity.user.build({ id: targetId, role: 'user' })
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
await service.getUserById(admin, targetId);
|
|
369
|
+
|
|
370
|
+
expect(db.user.findFirst).toHaveBeenCalledWith({
|
|
371
|
+
where: { id: targetId }
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe('remove', () => {
|
|
377
|
+
it('should delete the user by id', async () => {
|
|
378
|
+
const userId = Gen.uuid();
|
|
379
|
+
db.user.delete.mockResolvedValue(Entity.user.build({ id: userId }));
|
|
380
|
+
|
|
381
|
+
await service.remove(userId);
|
|
382
|
+
|
|
383
|
+
expect(db.user.delete).toHaveBeenCalledWith({
|
|
384
|
+
where: { id: userId }
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('should return an OKEntity', async () => {
|
|
389
|
+
const userId = Gen.uuid();
|
|
390
|
+
db.user.delete.mockResolvedValue(Entity.user.build({ id: userId }));
|
|
391
|
+
|
|
392
|
+
const result = await service.remove(userId);
|
|
393
|
+
expect(OKEntity.safeParse(result).success).toBe(true);
|
|
394
|
+
expect(result.status).toBe(200);
|
|
395
|
+
expect(result.message).toBe('ok');
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException, // @feature media
|
|
3
|
+
Controller,
|
|
4
|
+
Get,
|
|
5
|
+
HttpCode,
|
|
6
|
+
Post,
|
|
7
|
+
UploadedFile, // @feature media
|
|
8
|
+
UseInterceptors // @feature media
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
import { ApiTags } from '@nestjs/swagger';
|
|
11
|
+
import { ApiBadRequestResponse, ApiBody } from '@nestjs/swagger'; // @feature media
|
|
12
|
+
import { FileInterceptor } from '@nestjs/platform-express'; // @feature media
|
|
13
|
+
import { Session, UserSession } from '@thallesp/nestjs-better-auth';
|
|
14
|
+
import { Op, Returns } from 'common/decorators';
|
|
15
|
+
import { MultipartFormData } from 'common/decorators'; // @feature media
|
|
16
|
+
import { FileEntity } from 'media/entity'; // @feature media
|
|
17
|
+
import { CurrentUserService } from '../services';
|
|
18
|
+
import { CurrentUserEntity, toCurrentUser } from '../entity';
|
|
19
|
+
import { AVATAR_UPLOAD_SCHEMA } from '../dto'; // @feature media
|
|
20
|
+
|
|
21
|
+
@ApiTags('Current User')
|
|
22
|
+
@Controller({ path: 'user', version: '1' })
|
|
23
|
+
export class CurrentUserController {
|
|
24
|
+
constructor(private service: CurrentUserService) {}
|
|
25
|
+
|
|
26
|
+
@Get()
|
|
27
|
+
@Op('user', '/v1/user', 'Get current user')
|
|
28
|
+
@Returns(CurrentUserEntity, { description: 'The current user' })
|
|
29
|
+
getCurrentUser(@Session() { user }: UserSession) {
|
|
30
|
+
return toCurrentUser(user);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Post('onboarding')
|
|
34
|
+
@Op(
|
|
35
|
+
'completeOnboarding',
|
|
36
|
+
'/v1/user/onboarding',
|
|
37
|
+
"Mark the current user's onboarding as complete"
|
|
38
|
+
)
|
|
39
|
+
@HttpCode(200)
|
|
40
|
+
@Returns(CurrentUserEntity, { description: 'The updated user' })
|
|
41
|
+
completeOnboarding(@Session() { user }: UserSession) {
|
|
42
|
+
return this.service.completeOnboarding(user);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// @feature:start media
|
|
46
|
+
@Post('avatar')
|
|
47
|
+
@Op(
|
|
48
|
+
'avatar',
|
|
49
|
+
'/v1/user/avatar',
|
|
50
|
+
'Upload a new avatar image for the current user'
|
|
51
|
+
)
|
|
52
|
+
@MultipartFormData()
|
|
53
|
+
@ApiBody({ schema: AVATAR_UPLOAD_SCHEMA })
|
|
54
|
+
@UseInterceptors(
|
|
55
|
+
FileInterceptor('file', {
|
|
56
|
+
limits: { fileSize: 1 * 1024 * 1024 }, // 1MB limit
|
|
57
|
+
fileFilter: (req, file, cb) => {
|
|
58
|
+
if (!file.mimetype.match(/\/(jpg|jpeg|png|gif)$/)) {
|
|
59
|
+
return cb(
|
|
60
|
+
new BadRequestException(
|
|
61
|
+
'Only image files (jpg, jpeg, png, gif) are allowed for avatars'
|
|
62
|
+
),
|
|
63
|
+
false
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
cb(null, true);
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
@HttpCode(200)
|
|
71
|
+
@Returns(FileEntity, { description: 'The uploaded avatar file entity' })
|
|
72
|
+
@ApiBadRequestResponse({
|
|
73
|
+
description: 'Invalid file upload (e.g., wrong format, file too large)'
|
|
74
|
+
})
|
|
75
|
+
updateAvatar(
|
|
76
|
+
@Session() { user }: UserSession,
|
|
77
|
+
@UploadedFile() file: Express.Multer.File
|
|
78
|
+
) {
|
|
79
|
+
return this.service.updateAvatar(user, file);
|
|
80
|
+
}
|
|
81
|
+
// @feature:end
|
|
82
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Controller, Get, Param, Query } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
ApiBadRequestResponse,
|
|
4
|
+
ApiNotFoundResponse,
|
|
5
|
+
ApiTags
|
|
6
|
+
} from '@nestjs/swagger';
|
|
7
|
+
import { Session, UserSession } from '@thallesp/nestjs-better-auth';
|
|
8
|
+
import { IdParam, Op, Returns } from 'common/decorators';
|
|
9
|
+
import { UserPermissions } from '../decorators';
|
|
10
|
+
import { UsersService } from '../services';
|
|
11
|
+
import { UserEntity, PaginatedUserEntity } from '../entity';
|
|
12
|
+
import { UserFilters } from '../dto';
|
|
13
|
+
|
|
14
|
+
@ApiTags('Users')
|
|
15
|
+
@Controller({ path: 'users', version: '1' })
|
|
16
|
+
export class UsersController {
|
|
17
|
+
constructor(private service: UsersService) {}
|
|
18
|
+
|
|
19
|
+
@Get()
|
|
20
|
+
@Op('users', '/v1/users', 'Get all users')
|
|
21
|
+
@Returns(PaginatedUserEntity)
|
|
22
|
+
@UserPermissions('list')
|
|
23
|
+
findAll(
|
|
24
|
+
@Query({ schema: UserFilters }) filters: UserFilters,
|
|
25
|
+
@Session() { user }: UserSession
|
|
26
|
+
) {
|
|
27
|
+
return this.service.paginate(user, filters);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Get(':id')
|
|
31
|
+
@Op('users/:id', '/v1/users/:id', 'Get user by ID')
|
|
32
|
+
@IdParam()
|
|
33
|
+
@ApiBadRequestResponse()
|
|
34
|
+
@Returns(UserEntity)
|
|
35
|
+
@ApiNotFoundResponse({ description: 'User not found' })
|
|
36
|
+
@UserPermissions('get')
|
|
37
|
+
async findOne(@Param('id') id: string, @Session() { user }: UserSession) {
|
|
38
|
+
return this.service.getUserById(user, id);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './permissions.decorator';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { applyDecorators } from '@nestjs/common';
|
|
2
|
+
import { UserHasPermission } from '@thallesp/nestjs-better-auth';
|
|
3
|
+
import type { PermissionAction, Permission } from 'lib/access';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Thin, typed wrappers over better-auth's `UserHasPermission`. Add one per
|
|
7
|
+
* resource you declare in `lib/access.ts` — the `PermissionAction<'x'>` type
|
|
8
|
+
* argument is what makes a typo'd action a compile error instead of a check
|
|
9
|
+
* that silently never passes.
|
|
10
|
+
*/
|
|
11
|
+
export function UserPermissions(...actions: PermissionAction<'user'>[]) {
|
|
12
|
+
return applyDecorators(UserHasPermission({ permission: { user: actions } }));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function SessionPermissions(...actions: PermissionAction<'session'>[]) {
|
|
16
|
+
return applyDecorators(
|
|
17
|
+
UserHasPermission({ permission: { session: actions } })
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Escape hatch for a multi-resource check. */
|
|
22
|
+
export function Permissions(permissions: Permission) {
|
|
23
|
+
return applyDecorators(UserHasPermission({ permissions }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { SchemaObject } from '@nestjs/swagger';
|
|
3
|
+
import { binary } from 'common/schemas';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The avatar upload body. Documentation only: the file itself arrives through
|
|
7
|
+
* FileInterceptor, which the validation pipe does not see.
|
|
8
|
+
*/
|
|
9
|
+
export const AvatarUpload = z.object({ file: binary() });
|
|
10
|
+
|
|
11
|
+
export const AVATAR_UPLOAD_SCHEMA = z.toJSONSchema(AvatarUpload, {
|
|
12
|
+
target: 'openapi-3.0'
|
|
13
|
+
}) as SchemaObject;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CommonFilters } from 'common/dto';
|
|
3
|
+
|
|
4
|
+
export const UserFilters = CommonFilters.extend({
|
|
5
|
+
// Whether any user holds this role is checked in UsersService, against the DB.
|
|
6
|
+
role: z.string().optional()
|
|
7
|
+
});
|
|
8
|
+
export type UserFilters = z.output<typeof UserFilters>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './user.entity';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UserSession } from '@thallesp/nestjs-better-auth';
|
|
3
|
+
import { faker as F } from '@faker-js/faker';
|
|
4
|
+
import { dateTime, email } from 'common/schemas';
|
|
5
|
+
import { paginated } from 'common/entity';
|
|
6
|
+
|
|
7
|
+
export const UserEntity = z
|
|
8
|
+
.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
name: z.string().meta({ example: F.person.fullName() }),
|
|
11
|
+
email: email(),
|
|
12
|
+
emailVerified: z.boolean(),
|
|
13
|
+
image: z.string().nullable().meta({ example: F.image.avatar() }),
|
|
14
|
+
createdAt: dateTime(),
|
|
15
|
+
updatedAt: dateTime(),
|
|
16
|
+
role: z.string().nullable().meta({ example: 'user' }),
|
|
17
|
+
banned: z.boolean().nullable().meta({ example: false }),
|
|
18
|
+
banReason: z.string().nullable().meta({ example: 'Violation of terms' }),
|
|
19
|
+
banExpires: dateTime().nullable(),
|
|
20
|
+
onboardingCompletedAt: dateTime().nullable()
|
|
21
|
+
})
|
|
22
|
+
.meta({ id: 'UserEntity' });
|
|
23
|
+
/** What a service hands back; the schema turns it into the response. */
|
|
24
|
+
export type UserEntity = z.input<typeof UserEntity>;
|
|
25
|
+
|
|
26
|
+
export const PaginatedUserEntity = paginated(UserEntity, 'PaginatedUserEntity');
|
|
27
|
+
export type PaginatedUserEntity = z.input<typeof PaginatedUserEntity>;
|
|
28
|
+
|
|
29
|
+
export const CurrentUserEntity = UserEntity.omit({
|
|
30
|
+
banned: true,
|
|
31
|
+
banReason: true,
|
|
32
|
+
banExpires: true
|
|
33
|
+
}).meta({ id: 'CurrentUserEntity' });
|
|
34
|
+
export type CurrentUserEntity = z.input<typeof CurrentUserEntity>;
|
|
35
|
+
|
|
36
|
+
/** Shape a better-auth session user into a {@link CurrentUserEntity}. */
|
|
37
|
+
export function toCurrentUser(user: UserSession['user']): CurrentUserEntity {
|
|
38
|
+
return {
|
|
39
|
+
id: user.id,
|
|
40
|
+
name: user.name,
|
|
41
|
+
email: user.email,
|
|
42
|
+
emailVerified: user.emailVerified,
|
|
43
|
+
image: user.image || null,
|
|
44
|
+
createdAt: user.createdAt,
|
|
45
|
+
updatedAt: user.updatedAt,
|
|
46
|
+
// better-auth may hand back several roles; the first is the primary one.
|
|
47
|
+
role: (Array.isArray(user.role) ? user.role[0] : user.role) || null,
|
|
48
|
+
// additionalField — not present on the inferred session-user type.
|
|
49
|
+
onboardingCompletedAt:
|
|
50
|
+
(user as { onboardingCompletedAt?: Date | null }).onboardingCompletedAt ??
|
|
51
|
+
null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { UserSession } from '@thallesp/nestjs-better-auth';
|
|
3
|
+
import { PrismaService } from 'common/services';
|
|
4
|
+
import { MediaService } from 'media/services'; // @feature media
|
|
5
|
+
import { FileEntity } from 'media/entity'; // @feature media
|
|
6
|
+
import { CurrentUserEntity, toCurrentUser } from '../entity';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class CurrentUserService {
|
|
10
|
+
constructor(
|
|
11
|
+
private media: MediaService, // @feature media
|
|
12
|
+
private db: PrismaService
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
// @feature:start media
|
|
16
|
+
async updateAvatar(
|
|
17
|
+
user: UserSession['user'],
|
|
18
|
+
file: Express.Multer.File
|
|
19
|
+
): Promise<FileEntity> {
|
|
20
|
+
const image = await this.media.uploadAvatar(file);
|
|
21
|
+
if (user.image) {
|
|
22
|
+
this.media.deleteFile(user.image);
|
|
23
|
+
}
|
|
24
|
+
await this.db.user.update({
|
|
25
|
+
where: { id: user.id },
|
|
26
|
+
data: { image }
|
|
27
|
+
});
|
|
28
|
+
return { path: image };
|
|
29
|
+
}
|
|
30
|
+
// @feature:end
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Stamp the user's onboarding as complete (idempotent — re-stamps on repeat).
|
|
34
|
+
* Called when the wizard finishes or is skipped so the first-run gate stops
|
|
35
|
+
* redirecting them.
|
|
36
|
+
*/
|
|
37
|
+
async completeOnboarding(
|
|
38
|
+
user: UserSession['user']
|
|
39
|
+
): Promise<CurrentUserEntity> {
|
|
40
|
+
const updated = await this.db.user.update({
|
|
41
|
+
where: { id: user.id },
|
|
42
|
+
data: { onboardingCompletedAt: new Date() }
|
|
43
|
+
});
|
|
44
|
+
return toCurrentUser(updated as unknown as UserSession['user']);
|
|
45
|
+
}
|
|
46
|
+
}
|