create-huenei-template 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/templates.js +7 -0
- package/dist/templates/README.md +7 -1
- package/dist/templates/backend/README.md +19 -9
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/dist/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/dist/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/dist/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/dist/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/dist/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/dist/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/dist/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/dist/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/dist/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/dist/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/dist/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/dist/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/dist/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/dist/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/dist/templates/frontend/react-vite/README.md +34 -34
- package/dist/templates/frontend/react-vite/package.json +82 -82
- package/dist/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/dist/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/dist/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/dist/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/dist/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/dist/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/dist/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/dist/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/dist/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/dist/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/dist/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/dist/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/dist/templates/frontend/react-vite/vite.config.ts +2 -2
- package/dist/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/package.json +1 -1
- package/templates/README.md +7 -1
- package/templates/backend/README.md +19 -9
- package/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/templates/backend/nestjs-api-mysql/dist/tsconfig.build.tsbuildinfo +1 -1
- package/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/templates/frontend/react-vite/README.md +34 -34
- package/templates/frontend/react-vite/package.json +82 -82
- package/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/templates/frontend/react-vite/vite.config.ts +2 -2
- package/templates/frontend/react-vite/vitest.config.ts +13 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Injectable, NotFoundException, ForbiddenException, Logger } from '@nestjs/common';
|
|
2
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
3
|
+
import { CreatePostDto } from './dto/create-post.dto';
|
|
4
|
+
import { UpdatePostDto } from './dto/update-post.dto';
|
|
5
|
+
import type { Post, Prisma } from '@prisma/client';
|
|
6
|
+
|
|
7
|
+
type PostWithAuthor = Prisma.PostGetPayload<{
|
|
8
|
+
include: {
|
|
9
|
+
author: {
|
|
10
|
+
select: { id: true; email: true; name: true; role: true };
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class PostsService {
|
|
17
|
+
private readonly logger = new Logger(PostsService.name);
|
|
18
|
+
|
|
19
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
20
|
+
|
|
21
|
+
async create(
|
|
22
|
+
createPostDto: CreatePostDto,
|
|
23
|
+
authorId: number,
|
|
24
|
+
): Promise<PostWithAuthor> {
|
|
25
|
+
this.logger.log(`Creating post by user ${authorId}: ${createPostDto.title}`);
|
|
26
|
+
const post = (await this.prisma.post.create({
|
|
27
|
+
data: {
|
|
28
|
+
...createPostDto,
|
|
29
|
+
authorId,
|
|
30
|
+
},
|
|
31
|
+
include: {
|
|
32
|
+
author: {
|
|
33
|
+
select: {
|
|
34
|
+
id: true,
|
|
35
|
+
email: true,
|
|
36
|
+
name: true,
|
|
37
|
+
role: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
})) as PostWithAuthor;
|
|
42
|
+
this.logger.log(`Post created successfully - ID: ${post.id}`);
|
|
43
|
+
return post;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async findAll(options: {
|
|
47
|
+
published?: boolean;
|
|
48
|
+
page?: number;
|
|
49
|
+
limit?: number;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
data: PostWithAuthor[];
|
|
52
|
+
meta: {
|
|
53
|
+
total: number;
|
|
54
|
+
page: number;
|
|
55
|
+
limit: number;
|
|
56
|
+
totalPages: number;
|
|
57
|
+
hasNextPage: boolean;
|
|
58
|
+
hasPreviousPage: boolean;
|
|
59
|
+
};
|
|
60
|
+
}> {
|
|
61
|
+
const { published, page = 1, limit = 10 } = options;
|
|
62
|
+
const skip = (page - 1) * limit;
|
|
63
|
+
|
|
64
|
+
const where = published !== undefined ? { published } : undefined;
|
|
65
|
+
|
|
66
|
+
const [data, total] = await Promise.all([
|
|
67
|
+
this.prisma.post.findMany({
|
|
68
|
+
where,
|
|
69
|
+
include: {
|
|
70
|
+
author: {
|
|
71
|
+
select: {
|
|
72
|
+
id: true,
|
|
73
|
+
email: true,
|
|
74
|
+
name: true,
|
|
75
|
+
role: true,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
orderBy: {
|
|
80
|
+
createdAt: 'desc',
|
|
81
|
+
},
|
|
82
|
+
skip,
|
|
83
|
+
take: limit,
|
|
84
|
+
}),
|
|
85
|
+
this.prisma.post.count({ where }),
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
const totalPages = Math.ceil(total / limit);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
data: data as PostWithAuthor[],
|
|
92
|
+
meta: {
|
|
93
|
+
total,
|
|
94
|
+
page,
|
|
95
|
+
limit,
|
|
96
|
+
totalPages,
|
|
97
|
+
hasNextPage: page < totalPages,
|
|
98
|
+
hasPreviousPage: page > 1,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async findOne(id: number): Promise<PostWithAuthor> {
|
|
104
|
+
const post = (await this.prisma.post.findUnique({
|
|
105
|
+
where: { id },
|
|
106
|
+
include: {
|
|
107
|
+
author: {
|
|
108
|
+
select: {
|
|
109
|
+
id: true,
|
|
110
|
+
email: true,
|
|
111
|
+
name: true,
|
|
112
|
+
role: true,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
})) as PostWithAuthor | null;
|
|
117
|
+
|
|
118
|
+
if (!post) {
|
|
119
|
+
throw new NotFoundException(`Post with ID ${id} not found`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return post;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async update(
|
|
126
|
+
id: number,
|
|
127
|
+
updatePostDto: UpdatePostDto,
|
|
128
|
+
userId: number,
|
|
129
|
+
): Promise<PostWithAuthor> {
|
|
130
|
+
// Verify post exists and belongs to user
|
|
131
|
+
const post = await this.findOne(id);
|
|
132
|
+
|
|
133
|
+
// Check ownership
|
|
134
|
+
if (post.authorId !== userId) {
|
|
135
|
+
this.logger.warn(`User ${userId} attempted to update post ${id} without permission`);
|
|
136
|
+
throw new ForbiddenException('You do not have permission to modify this post');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.logger.log(`Updating post ${id} by user ${userId}`);
|
|
140
|
+
return (await this.prisma.post.update({
|
|
141
|
+
where: { id },
|
|
142
|
+
data: updatePostDto,
|
|
143
|
+
include: {
|
|
144
|
+
author: {
|
|
145
|
+
select: {
|
|
146
|
+
id: true,
|
|
147
|
+
email: true,
|
|
148
|
+
name: true,
|
|
149
|
+
role: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
})) as PostWithAuthor;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async remove(id: number, userId: number): Promise<Post> {
|
|
157
|
+
// Verify post exists and belongs to user
|
|
158
|
+
const post = await this.findOne(id);
|
|
159
|
+
|
|
160
|
+
// Check ownership
|
|
161
|
+
if (post.authorId !== userId) {
|
|
162
|
+
this.logger.warn(`User ${userId} attempted to delete post ${id} without permission`);
|
|
163
|
+
throw new ForbiddenException('You do not have permission to delete this post');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.logger.log(`Deleting post ${id} by user ${userId}`);
|
|
167
|
+
return (await this.prisma.post.delete({
|
|
168
|
+
where: { id },
|
|
169
|
+
})) as Post;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Injectable, OnModuleInit, OnModuleDestroy, Logger } from '@nestjs/common';
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
import { PrismaMssql } from '@prisma/adapter-mssql';
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class PrismaService
|
|
7
|
+
extends PrismaClient
|
|
8
|
+
implements OnModuleInit, OnModuleDestroy
|
|
9
|
+
{
|
|
10
|
+
private readonly logger = new Logger(PrismaService.name);
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
const adapter = new PrismaMssql(process.env.DATABASE_URL as string);
|
|
14
|
+
super({ adapter });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async onModuleInit() {
|
|
18
|
+
try {
|
|
19
|
+
// First, try to connect
|
|
20
|
+
await this.$connect();
|
|
21
|
+
|
|
22
|
+
// Then, perform a real query to verify the connection works
|
|
23
|
+
await this.$queryRaw`SELECT 1`;
|
|
24
|
+
|
|
25
|
+
this.logger.log('✅ Successfully connected to SQL Server database');
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
28
|
+
|
|
29
|
+
this.logger.error('❌ Failed to connect to SQL Server database');
|
|
30
|
+
this.logger.error('');
|
|
31
|
+
this.logger.error('🐳 Docker container is NOT running or SQL Server is not available');
|
|
32
|
+
this.logger.error('');
|
|
33
|
+
this.logger.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
34
|
+
this.logger.error('');
|
|
35
|
+
this.logger.error('📝 PLEASE RUN ONE OF THE FOLLOWING COMMANDS:');
|
|
36
|
+
this.logger.error('');
|
|
37
|
+
this.logger.error(' Option 1 - Start Docker container (first time):');
|
|
38
|
+
this.logger.error(' → docker-compose up -d');
|
|
39
|
+
this.logger.error('');
|
|
40
|
+
this.logger.error(' Option 2 - Start existing stopped container:');
|
|
41
|
+
this.logger.error(' → docker-compose start');
|
|
42
|
+
this.logger.error('');
|
|
43
|
+
this.logger.error(' Option 3 - Check container status:');
|
|
44
|
+
this.logger.error(' → docker-compose ps');
|
|
45
|
+
this.logger.error('');
|
|
46
|
+
this.logger.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
47
|
+
this.logger.error('');
|
|
48
|
+
this.logger.error('💡 After starting the container, STOP this process (Ctrl+C)');
|
|
49
|
+
this.logger.error(' and run "pnpm start:dev" again');
|
|
50
|
+
this.logger.error('');
|
|
51
|
+
this.logger.error(`Error details: ${errorMessage}`);
|
|
52
|
+
this.logger.error('');
|
|
53
|
+
|
|
54
|
+
// Terminate the process to force the developer to fix the issue
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async onModuleDestroy() {
|
|
60
|
+
await this.$disconnect();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
|
|
3
|
+
export class ProfileResponseDto {
|
|
4
|
+
@ApiProperty({ example: 1 })
|
|
5
|
+
id: number;
|
|
6
|
+
|
|
7
|
+
@ApiProperty({ example: 1 })
|
|
8
|
+
userId: number;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ nullable: true, example: 'https://avatar.com/user.jpg' })
|
|
11
|
+
avatar: string | null;
|
|
12
|
+
|
|
13
|
+
@ApiProperty({
|
|
14
|
+
nullable: true,
|
|
15
|
+
example: 'Software developer passionate about tech',
|
|
16
|
+
})
|
|
17
|
+
bio: string | null;
|
|
18
|
+
|
|
19
|
+
@ApiProperty({ nullable: true, example: '+54 9 11 1234-5678' })
|
|
20
|
+
phone: string | null;
|
|
21
|
+
|
|
22
|
+
@ApiProperty({ nullable: true, example: 'https://mywebsite.com' })
|
|
23
|
+
website: string | null;
|
|
24
|
+
|
|
25
|
+
@ApiProperty({ nullable: true, example: 'John Developer' })
|
|
26
|
+
publicName: string | null;
|
|
27
|
+
|
|
28
|
+
@ApiProperty({
|
|
29
|
+
nullable: true,
|
|
30
|
+
example: { twitter: '@user', github: 'user' },
|
|
31
|
+
})
|
|
32
|
+
metadata: any | null;
|
|
33
|
+
|
|
34
|
+
@ApiProperty({ example: '2026-01-24T10:00:00.000Z' })
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
|
|
37
|
+
@ApiProperty({ example: '2026-01-24T10:00:00.000Z' })
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
|
|
3
|
+
export class SettingsResponseDto {
|
|
4
|
+
@ApiProperty({ example: 'es', enum: ['es', 'en'] })
|
|
5
|
+
language: string;
|
|
6
|
+
|
|
7
|
+
@ApiProperty({ example: 'light', enum: ['light', 'dark', 'auto'] })
|
|
8
|
+
theme: string;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ example: true })
|
|
11
|
+
emailNotifications: boolean;
|
|
12
|
+
|
|
13
|
+
@ApiProperty({ example: false })
|
|
14
|
+
pushNotifications: boolean;
|
|
15
|
+
|
|
16
|
+
@ApiProperty({ example: 'private', enum: ['private', 'public'] })
|
|
17
|
+
privacy: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsString,
|
|
3
|
+
IsOptional,
|
|
4
|
+
IsUrl,
|
|
5
|
+
MaxLength,
|
|
6
|
+
IsObject,
|
|
7
|
+
} from 'class-validator';
|
|
8
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
9
|
+
|
|
10
|
+
export class UpdateProfileDto {
|
|
11
|
+
@ApiProperty({ required: false, example: 'https://avatar.com/user.jpg' })
|
|
12
|
+
@IsOptional()
|
|
13
|
+
@IsUrl()
|
|
14
|
+
avatar?: string;
|
|
15
|
+
|
|
16
|
+
@ApiProperty({
|
|
17
|
+
required: false,
|
|
18
|
+
example: 'Software developer passionate about...',
|
|
19
|
+
})
|
|
20
|
+
@IsOptional()
|
|
21
|
+
@IsString()
|
|
22
|
+
@MaxLength(500)
|
|
23
|
+
bio?: string;
|
|
24
|
+
|
|
25
|
+
@ApiProperty({ required: false, example: '+54 9 11 1234-5678' })
|
|
26
|
+
@IsOptional()
|
|
27
|
+
@IsString()
|
|
28
|
+
phone?: string;
|
|
29
|
+
|
|
30
|
+
@ApiProperty({ required: false, example: 'https://mywebsite.com' })
|
|
31
|
+
@IsOptional()
|
|
32
|
+
@IsUrl()
|
|
33
|
+
website?: string;
|
|
34
|
+
|
|
35
|
+
@ApiProperty({ required: false, example: 'John Developer' })
|
|
36
|
+
@IsOptional()
|
|
37
|
+
@IsString()
|
|
38
|
+
@MaxLength(100)
|
|
39
|
+
publicName?: string;
|
|
40
|
+
|
|
41
|
+
@ApiProperty({
|
|
42
|
+
required: false,
|
|
43
|
+
example: { twitter: '@john', github: 'john' },
|
|
44
|
+
})
|
|
45
|
+
@IsOptional()
|
|
46
|
+
@IsObject()
|
|
47
|
+
metadata?: Record<string, any>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IsString, IsBoolean, IsOptional, IsIn } from 'class-validator';
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
+
|
|
4
|
+
export class UpdateSettingsDto {
|
|
5
|
+
@ApiProperty({ required: false, example: 'es', enum: ['es', 'en'] })
|
|
6
|
+
@IsOptional()
|
|
7
|
+
@IsString()
|
|
8
|
+
@IsIn(['es', 'en'])
|
|
9
|
+
language?: string;
|
|
10
|
+
|
|
11
|
+
@ApiProperty({
|
|
12
|
+
required: false,
|
|
13
|
+
example: 'dark',
|
|
14
|
+
enum: ['light', 'dark', 'auto'],
|
|
15
|
+
})
|
|
16
|
+
@IsOptional()
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsIn(['light', 'dark', 'auto'])
|
|
19
|
+
theme?: string;
|
|
20
|
+
|
|
21
|
+
@ApiProperty({ required: false, example: true })
|
|
22
|
+
@IsOptional()
|
|
23
|
+
@IsBoolean()
|
|
24
|
+
emailNotifications?: boolean;
|
|
25
|
+
|
|
26
|
+
@ApiProperty({ required: false, example: false })
|
|
27
|
+
@IsOptional()
|
|
28
|
+
@IsBoolean()
|
|
29
|
+
pushNotifications?: boolean;
|
|
30
|
+
|
|
31
|
+
@ApiProperty({
|
|
32
|
+
required: false,
|
|
33
|
+
example: 'private',
|
|
34
|
+
enum: ['private', 'public'],
|
|
35
|
+
})
|
|
36
|
+
@IsOptional()
|
|
37
|
+
@IsString()
|
|
38
|
+
@IsIn(['private', 'public'])
|
|
39
|
+
privacy?: string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
|
|
3
|
+
export class UserResponseDto {
|
|
4
|
+
@ApiProperty({ example: 1 })
|
|
5
|
+
id: number;
|
|
6
|
+
|
|
7
|
+
@ApiProperty({ example: 'user@example.com' })
|
|
8
|
+
email: string;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ example: 'John Doe', nullable: true })
|
|
11
|
+
name: string | null;
|
|
12
|
+
|
|
13
|
+
@ApiProperty({ example: '2026-01-23T10:00:00.000Z' })
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
|
|
16
|
+
@ApiProperty({ example: '2026-01-23T10:00:00.000Z' })
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
3
|
+
import { UpdateProfileDto } from './dto/update-profile.dto';
|
|
4
|
+
import { ProfileResponseDto } from './dto/profile-response.dto';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ProfileService {
|
|
8
|
+
constructor(private prisma: PrismaService) {}
|
|
9
|
+
|
|
10
|
+
async getProfile(userId: number): Promise<ProfileResponseDto> {
|
|
11
|
+
const profile = await this.prisma.userProfile.findUnique({
|
|
12
|
+
where: { userId },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!profile) {
|
|
16
|
+
return this.createProfile(userId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...profile,
|
|
21
|
+
metadata: profile.metadata ? JSON.parse(profile.metadata) : null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async updateProfile(
|
|
26
|
+
userId: number,
|
|
27
|
+
dto: UpdateProfileDto,
|
|
28
|
+
): Promise<ProfileResponseDto> {
|
|
29
|
+
const data = {
|
|
30
|
+
...dto,
|
|
31
|
+
metadata: dto.metadata !== undefined ? JSON.stringify(dto.metadata) : undefined,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const exists = await this.prisma.userProfile.findUnique({
|
|
35
|
+
where: { userId },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!exists) {
|
|
39
|
+
const created = await this.prisma.userProfile.create({
|
|
40
|
+
data: { userId, ...data },
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
...created,
|
|
44
|
+
metadata: created.metadata ? JSON.parse(created.metadata) : null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const updated = await this.prisma.userProfile.update({
|
|
49
|
+
where: { userId },
|
|
50
|
+
data,
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
...updated,
|
|
54
|
+
metadata: updated.metadata ? JSON.parse(updated.metadata) : null,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async createProfile(userId: number): Promise<ProfileResponseDto> {
|
|
59
|
+
const profile = await this.prisma.userProfile.create({
|
|
60
|
+
data: { userId },
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
...profile,
|
|
64
|
+
metadata: profile.metadata ? JSON.parse(profile.metadata) : null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
3
|
+
import { UpdateSettingsDto } from './dto/update-settings.dto';
|
|
4
|
+
import { SettingsResponseDto } from './dto/settings-response.dto';
|
|
5
|
+
import { DEFAULT_USER_SETTINGS } from './constants/settings.constants';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class SettingsService {
|
|
9
|
+
constructor(private prisma: PrismaService) {}
|
|
10
|
+
|
|
11
|
+
async getSettings(userId: number): Promise<SettingsResponseDto> {
|
|
12
|
+
const settings = await this.prisma.userSettings.findUnique({
|
|
13
|
+
where: { userId },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (!settings) {
|
|
17
|
+
return this.createSettings(userId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return JSON.parse(settings.preferences) as SettingsResponseDto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async updateSettings(
|
|
24
|
+
userId: number,
|
|
25
|
+
dto: UpdateSettingsDto,
|
|
26
|
+
): Promise<SettingsResponseDto> {
|
|
27
|
+
const current = await this.prisma.userSettings.findUnique({
|
|
28
|
+
where: { userId },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const cleanDto = Object.entries(dto).reduce(
|
|
32
|
+
(acc, [key, value]) => {
|
|
33
|
+
if (value !== undefined) {
|
|
34
|
+
acc[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return acc;
|
|
37
|
+
},
|
|
38
|
+
{} as Record<string, any>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (!current) {
|
|
42
|
+
const newPreferences = { ...DEFAULT_USER_SETTINGS, ...cleanDto };
|
|
43
|
+
const newSettings = await this.prisma.userSettings.create({
|
|
44
|
+
data: {
|
|
45
|
+
userId,
|
|
46
|
+
preferences: JSON.stringify(newPreferences),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return JSON.parse(newSettings.preferences) as SettingsResponseDto;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const mergedPreferences = {
|
|
53
|
+
...(JSON.parse(current.preferences) as object),
|
|
54
|
+
...cleanDto,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const updated = await this.prisma.userSettings.update({
|
|
58
|
+
where: { userId },
|
|
59
|
+
data: {
|
|
60
|
+
preferences: JSON.stringify(mergedPreferences),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return JSON.parse(updated.preferences) as SettingsResponseDto;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async createSettings(userId: number): Promise<SettingsResponseDto> {
|
|
68
|
+
await this.prisma.userSettings.create({
|
|
69
|
+
data: {
|
|
70
|
+
userId,
|
|
71
|
+
preferences: JSON.stringify(DEFAULT_USER_SETTINGS),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return DEFAULT_USER_SETTINGS;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Controller,
|
|
3
|
+
Get,
|
|
4
|
+
Request,
|
|
5
|
+
UseGuards,
|
|
6
|
+
Patch,
|
|
7
|
+
Body,
|
|
8
|
+
} from '@nestjs/common';
|
|
9
|
+
import {
|
|
10
|
+
ApiTags,
|
|
11
|
+
ApiBearerAuth,
|
|
12
|
+
ApiOperation,
|
|
13
|
+
ApiResponse,
|
|
14
|
+
} from '@nestjs/swagger';
|
|
15
|
+
import { UsersService } from './users.service';
|
|
16
|
+
import { ProfileService } from './profile.service';
|
|
17
|
+
import { SettingsService } from './settings.service';
|
|
18
|
+
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
19
|
+
import { UserResponseDto } from './dto/user-response.dto';
|
|
20
|
+
import { UpdateProfileDto } from './dto/update-profile.dto';
|
|
21
|
+
import { ProfileResponseDto } from './dto/profile-response.dto';
|
|
22
|
+
import { UpdateSettingsDto } from './dto/update-settings.dto';
|
|
23
|
+
import { SettingsResponseDto } from './dto/settings-response.dto';
|
|
24
|
+
import type { AuthenticatedRequest } from '../auth/types';
|
|
25
|
+
|
|
26
|
+
@ApiTags('Users')
|
|
27
|
+
@ApiBearerAuth('JWT-auth')
|
|
28
|
+
@Controller('users')
|
|
29
|
+
@UseGuards(JwtAuthGuard)
|
|
30
|
+
export class UsersController {
|
|
31
|
+
constructor(
|
|
32
|
+
private readonly usersService: UsersService,
|
|
33
|
+
private readonly profileService: ProfileService,
|
|
34
|
+
private readonly settingsService: SettingsService,
|
|
35
|
+
) {}
|
|
36
|
+
|
|
37
|
+
@Get('me')
|
|
38
|
+
@ApiOperation({ summary: 'Get current user basic info' })
|
|
39
|
+
@ApiResponse({
|
|
40
|
+
status: 200,
|
|
41
|
+
description: 'User basic info retrieved',
|
|
42
|
+
type: UserResponseDto,
|
|
43
|
+
})
|
|
44
|
+
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
45
|
+
async getMe(@Request() req: AuthenticatedRequest) {
|
|
46
|
+
return this.usersService.findById(req.user.id);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Get('me/profile')
|
|
50
|
+
@ApiOperation({ summary: 'Get current user profile' })
|
|
51
|
+
@ApiResponse({
|
|
52
|
+
status: 200,
|
|
53
|
+
description: 'User profile retrieved',
|
|
54
|
+
type: ProfileResponseDto,
|
|
55
|
+
})
|
|
56
|
+
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
57
|
+
async getMyProfile(@Request() req: AuthenticatedRequest) {
|
|
58
|
+
return this.profileService.getProfile(req.user.id);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Patch('me/profile')
|
|
62
|
+
@ApiOperation({ summary: 'Update current user profile' })
|
|
63
|
+
@ApiResponse({
|
|
64
|
+
status: 200,
|
|
65
|
+
description: 'User profile updated',
|
|
66
|
+
type: ProfileResponseDto,
|
|
67
|
+
})
|
|
68
|
+
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
69
|
+
async updateMyProfile(
|
|
70
|
+
@Request() req: AuthenticatedRequest,
|
|
71
|
+
@Body() dto: UpdateProfileDto,
|
|
72
|
+
) {
|
|
73
|
+
return this.profileService.updateProfile(req.user.id, dto);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Get('me/settings')
|
|
77
|
+
@ApiOperation({ summary: 'Get current user settings' })
|
|
78
|
+
@ApiResponse({
|
|
79
|
+
status: 200,
|
|
80
|
+
description: 'User settings retrieved',
|
|
81
|
+
type: SettingsResponseDto,
|
|
82
|
+
})
|
|
83
|
+
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
84
|
+
async getMySettings(@Request() req: AuthenticatedRequest) {
|
|
85
|
+
return this.settingsService.getSettings(req.user.id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Patch('me/settings')
|
|
89
|
+
@ApiOperation({ summary: 'Update current user settings' })
|
|
90
|
+
@ApiResponse({
|
|
91
|
+
status: 200,
|
|
92
|
+
description: 'User settings updated',
|
|
93
|
+
type: SettingsResponseDto,
|
|
94
|
+
})
|
|
95
|
+
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
96
|
+
async updateMySettings(
|
|
97
|
+
@Request() req: AuthenticatedRequest,
|
|
98
|
+
@Body() dto: UpdateSettingsDto,
|
|
99
|
+
) {
|
|
100
|
+
return this.settingsService.updateSettings(req.user.id, dto);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { UsersController } from './users.controller';
|
|
3
|
+
import { UsersService } from './users.service';
|
|
4
|
+
import { ProfileService } from './profile.service';
|
|
5
|
+
import { SettingsService } from './settings.service';
|
|
6
|
+
import { PrismaModule } from '../prisma/prisma.module';
|
|
7
|
+
|
|
8
|
+
@Module({
|
|
9
|
+
imports: [PrismaModule],
|
|
10
|
+
controllers: [UsersController],
|
|
11
|
+
providers: [UsersService, ProfileService, SettingsService],
|
|
12
|
+
exports: [UsersService],
|
|
13
|
+
})
|
|
14
|
+
export class UsersModule {}
|