kybernus 3.0.1 → 3.2.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/README.md +1 -1
- package/dist/cli/commands/ecommerce.d.ts +3 -0
- package/dist/cli/commands/ecommerce.d.ts.map +1 -0
- package/dist/cli/commands/ecommerce.js +164 -0
- package/dist/cli/commands/ecommerce.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/ecommerce/.env.example +10 -0
- package/templates/ecommerce/.github/workflows/ci.yml +102 -0
- package/templates/ecommerce/.github/workflows/deploy.yml +31 -0
- package/templates/ecommerce/.prettierrc +9 -0
- package/templates/ecommerce/Dockerfile +54 -0
- package/templates/ecommerce/README.md +295 -0
- package/templates/ecommerce/apps/api/.env.example +59 -0
- package/templates/ecommerce/apps/api/jest.config.ts +50 -0
- package/templates/ecommerce/apps/api/jest.integration.config.ts +45 -0
- package/templates/ecommerce/apps/api/package.json +59 -0
- package/templates/ecommerce/apps/api/prisma/migrations/20260306000137_init/migration.sql +184 -0
- package/templates/ecommerce/apps/api/prisma/migrations/migration_lock.toml +3 -0
- package/templates/ecommerce/apps/api/prisma/schema.prisma +181 -0
- package/templates/ecommerce/apps/api/prisma/seed.ts +159 -0
- package/templates/ecommerce/apps/api/src/__tests__/app.test.ts +39 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalSetup.ts +34 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalTeardown.ts +16 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.db.ts +18 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.env.ts +14 -0
- package/templates/ecommerce/apps/api/src/app.ts +133 -0
- package/templates/ecommerce/apps/api/src/application/admin/admin-user.service.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/admin/dashboard.service.ts +102 -0
- package/templates/ecommerce/apps/api/src/application/auth/auth.service.ts +185 -0
- package/templates/ecommerce/apps/api/src/application/cart/cart.service.ts +151 -0
- package/templates/ecommerce/apps/api/src/application/cart/coupon.service.ts +51 -0
- package/templates/ecommerce/apps/api/src/application/catalog/catalog.service.ts +168 -0
- package/templates/ecommerce/apps/api/src/application/checkout/checkout.service.ts +114 -0
- package/templates/ecommerce/apps/api/src/application/orders/order.service.ts +93 -0
- package/templates/ecommerce/apps/api/src/application/ports/email.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/payment.port.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/ports/shipping.port.ts +9 -0
- package/templates/ecommerce/apps/api/src/application/ports/storage.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/token-blacklist.port.ts +4 -0
- package/templates/ecommerce/apps/api/src/application/ports/token.port.ts +18 -0
- package/templates/ecommerce/apps/api/src/application/profile/profile.service.ts +76 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.entity.ts +109 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.entity.ts +136 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.repository.ts +8 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.entity.ts +58 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.entity.ts +51 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.entity.ts +130 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.repository.ts +28 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.entity.ts +121 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/shared/AppError.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/cache/redis.ts +16 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/admin.registry.ts +13 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/auth.registry.ts +34 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/cart.registry.ts +49 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/catalog.registry.ts +24 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/checkout.registry.ts +47 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/orders.registry.ts +6 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/profile.registry.ts +4 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/cart.memory.repository.ts +33 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/category.memory.repository.ts +41 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/coupon.memory.repository.ts +55 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/order.memory.repository.ts +75 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/product.memory.repository.ts +100 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/user.memory.repository.ts +54 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/auth/user.prisma.repository.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/category.prisma.repository.ts +69 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/product.prisma.repository.ts +185 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/checkout/order.prisma.repository.ts +149 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma-client.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/email.registry.ts +18 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/ethereal.email.service.ts +38 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/noop.email.service.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/smtp.email.service.ts +36 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe-webhook.handler.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe.adapter.ts +39 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/shipping/mock.shipping.service.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/in-memory.storage.service.ts +11 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/local-disk.storage.service.ts +27 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/s3.storage.service.ts +52 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/storage.registry.ts +19 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/redis.token.blacklist.ts +23 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.blacklist.ts +30 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.service.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/admin/__tests__/admin.routes.integration.test.ts +250 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.user.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.logout.redis.test.ts +104 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.routes.integration.test.ts +211 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.service.unit.test.ts +260 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/email.service.unit.test.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/token.blacklist.redis.test.ts +65 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.entity.unit.test.ts +79 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.prisma.repository.test.ts +138 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.controller.ts +148 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/redis.token.blacklist.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.blacklist.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.entity.unit.test.ts +144 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.routes.integration.test.ts +242 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.service.unit.test.ts +151 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/coupon.admin.integration.test.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/shipping.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.routes.integration.test.ts +275 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.service.unit.test.ts +223 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.image.integration.test.ts +130 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.prisma.repository.test.ts +174 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.routes.integration.test.ts +163 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.service.unit.test.ts +191 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/order.prisma.repository.test.ts +150 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/tax.service.ts +9 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.entity.unit.test.ts +68 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.routes.integration.test.ts +254 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.service.email.unit.test.ts +142 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe-webhook.unit.test.ts +330 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe.adapter.unit.test.ts +84 -0
- package/templates/ecommerce/apps/api/src/modules/payment/adapters/stripe.adapter.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/payment.port.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/stripe-webhook.handler.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.routes.integration.test.ts +180 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.service.unit.test.ts +187 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authenticate.ts +37 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authorize.ts +23 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/errorHandler.ts +48 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.controller.ts +147 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/presentation/validators/uuidParam.ts +20 -0
- package/templates/ecommerce/apps/api/src/server.ts +47 -0
- package/templates/ecommerce/apps/api/src/shared/__tests__/uuid.validation.test.ts +111 -0
- package/templates/ecommerce/apps/api/src/shared/errors/AppError.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/EtherealEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/IEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/NoopEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/SmtpEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/__tests__/ethereal.email.integration.test.ts +32 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/email.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/prisma.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/redis.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/IStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/InMemoryStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/LocalDiskStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/S3StorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/__tests__/s3.storage.unit.test.ts +73 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/storage.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authenticate.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authorize.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/errorHandler.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/validators/uuidParam.ts +1 -0
- package/templates/ecommerce/apps/api/tsconfig.json +15 -0
- package/templates/ecommerce/apps/web/.env.example +8 -0
- package/templates/ecommerce/apps/web/index.html +19 -0
- package/templates/ecommerce/apps/web/jest.config.ts +45 -0
- package/templates/ecommerce/apps/web/package.json +38 -0
- package/templates/ecommerce/apps/web/src/App.tsx +133 -0
- package/templates/ecommerce/apps/web/src/__mocks__/fileMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/__mocks__/styleMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/index.css +159 -0
- package/templates/ecommerce/apps/web/src/main.tsx +13 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/CouponsAdminPage.test.tsx +134 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/DashboardPage.test.tsx +65 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/OrdersAdminPage.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/ProductsAdminPage.test.tsx +84 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/UsersAdminPage.test.tsx +85 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/CouponsAdminPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/DashboardPage.tsx +58 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/OrdersAdminPage.tsx +178 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/ProductsAdminPage.tsx +444 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/UsersAdminPage.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/auth/LoginForm.tsx +91 -0
- package/templates/ecommerce/apps/web/src/modules/auth/RegisterForm.tsx +109 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ForgotPasswordPage.test.tsx +42 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/LoginForm.test.tsx +76 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/RegisterForm.test.tsx +62 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ResetPasswordPage.test.tsx +66 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ForgotPasswordPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/LoginPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/RegisterPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ResetPasswordPage.tsx +110 -0
- package/templates/ecommerce/apps/web/src/modules/auth/useAuthStore.ts +141 -0
- package/templates/ecommerce/apps/web/src/modules/cart/__tests__/CartPage.test.tsx +111 -0
- package/templates/ecommerce/apps/web/src/modules/cart/pages/CartPage.tsx +313 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductCard.test.tsx +59 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductFilters.test.tsx +56 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductCard.tsx +78 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductFilters.tsx +104 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductDetailPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductListPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/CheckoutPage.test.tsx +159 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/StripePaymentForm.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/components/StripePaymentForm.tsx +55 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/hooks/useCheckout.ts +56 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutPage.tsx +344 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutSuccessPage.tsx +12 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/PrivacyPolicyPage.tsx +207 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/TermsOfServicePage.tsx +175 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderDetailPage.test.tsx +75 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderHistoryPage.test.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderDetailPage.tsx +73 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderHistoryPage.tsx +97 -0
- package/templates/ecommerce/apps/web/src/modules/profile/__tests__/ProfilePage.test.tsx +150 -0
- package/templates/ecommerce/apps/web/src/modules/profile/pages/ProfilePage.tsx +275 -0
- package/templates/ecommerce/apps/web/src/setupTests.ts +10 -0
- package/templates/ecommerce/apps/web/src/shared/components/CookieConsent.tsx +108 -0
- package/templates/ecommerce/apps/web/src/shared/components/ErrorBoundary.tsx +112 -0
- package/templates/ecommerce/apps/web/src/shared/components/Layout.tsx +143 -0
- package/templates/ecommerce/apps/web/src/shared/components/ProtectedRoute.tsx +21 -0
- package/templates/ecommerce/apps/web/src/shared/config/siteConfig.ts +57 -0
- package/templates/ecommerce/apps/web/src/shared/hooks/usePageTitle.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/lib/apiFetch.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/pages/NotFoundPage.tsx +42 -0
- package/templates/ecommerce/apps/web/src/shared/theme/ThemeProvider.tsx +45 -0
- package/templates/ecommerce/apps/web/src/shared/theme/__tests__/ThemeProvider.test.tsx +78 -0
- package/templates/ecommerce/apps/web/src/shared/theme/createTheme.ts +58 -0
- package/templates/ecommerce/apps/web/src/shared/theme/tokens.ts +81 -0
- package/templates/ecommerce/apps/web/src/vite-env.d.ts +1 -0
- package/templates/ecommerce/apps/web/tsconfig.jest.json +12 -0
- package/templates/ecommerce/apps/web/tsconfig.json +25 -0
- package/templates/ecommerce/apps/web/tsconfig.node.json +11 -0
- package/templates/ecommerce/apps/web/vite.config.ts +30 -0
- package/templates/ecommerce/docker-compose.yml +85 -0
- package/templates/ecommerce/package-lock.json +11255 -0
- package/templates/ecommerce/package.json +27 -0
- package/templates/ecommerce/packages/shared-types/package.json +13 -0
- package/templates/ecommerce/packages/shared-types/src/index.ts +3 -0
- package/templates/ecommerce/packages/shared-types/src/theme.ts +44 -0
- package/templates/ecommerce/packages/shared-types/tsconfig.json +11 -0
- package/templates/ecommerce/scripts/customize.sh +201 -0
- package/templates/ecommerce/tsconfig.json +14 -0
- package/templates/java-spring/clean/.gitignore.hbs +72 -0
- package/templates/java-spring/clean/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/application/usecase/PaymentUseCase.java.hbs +21 -17
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/entity/UserEntity.java.hbs +52 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/repository/JpaUserRepository.java.hbs +12 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/JwtAuthenticationFilter.java.hbs +64 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/SecurityConfig.java.hbs +36 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/stripe/StripeGateway.java.hbs +63 -0
- package/templates/java-spring/clean/src/main/resources/application.properties.hbs +6 -7
- package/templates/java-spring/hexagonal/.gitignore.hbs +72 -0
- package/templates/java-spring/hexagonal/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/JwtFilter.java.hbs +71 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/SecurityConfig.java.hbs +35 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/core/service/PaymentService.java.hbs +3 -3
- package/templates/java-spring/hexagonal/src/main/resources/application.properties.hbs +4 -4
- package/templates/java-spring/mvc/.gitignore.hbs +72 -0
- package/templates/java-spring/mvc/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/config/SecurityConfig.java.hbs +13 -12
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/AuthController.java.hbs +9 -8
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/PaymentsController.java.hbs +5 -6
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/service/StripeService.java.hbs +3 -3
- package/templates/java-spring/mvc/src/main/resources/application.yml.hbs +29 -26
- package/templates/nestjs/clean/.gitignore.hbs +42 -0
- package/templates/nestjs/clean/Dockerfile.hbs +6 -3
- package/templates/nestjs/clean/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/clean/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/clean/src/application/payment.service.ts.hbs +72 -72
- package/templates/nestjs/clean/src/domain/entities/user.entity.ts.hbs +2 -2
- package/templates/nestjs/clean/src/domain/repositories/user.repository.ts.hbs +2 -2
- package/templates/nestjs/clean/src/infrastructure/database/repositories/prisma.user.repository.ts.hbs +18 -18
- package/templates/nestjs/clean/src/infrastructure/http/health.controller.ts.hbs +9 -0
- package/templates/nestjs/clean/src/main.ts.hbs +1 -4
- package/templates/nestjs/clean/src/payment.module.ts.hbs +12 -12
- package/templates/nestjs/hexagonal/.gitignore.hbs +42 -0
- package/templates/nestjs/hexagonal/Dockerfile.hbs +6 -3
- package/templates/nestjs/hexagonal/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/hexagonal/src/adapters/inbound/health.controller.ts.hbs +9 -0
- package/templates/nestjs/hexagonal/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/hexagonal/src/core/domain/user.entity.ts.hbs +6 -6
- package/templates/nestjs/hexagonal/src/core/ports/ports.ts.hbs +4 -4
- package/templates/nestjs/hexagonal/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/.gitignore.hbs +42 -0
- package/templates/nestjs/mvc/Dockerfile.hbs +6 -3
- package/templates/nestjs/mvc/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/mvc/src/auth/auth.controller.ts.hbs +11 -1
- package/templates/nestjs/mvc/src/auth/auth.service.ts.hbs +3 -1
- package/templates/nestjs/mvc/src/controllers/health.controller.ts.hbs +6 -6
- package/templates/nestjs/mvc/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/src/models/create-item.dto.ts.hbs +5 -2
- package/templates/nestjs/mvc/src/prisma/prisma.service.ts.hbs +1 -0
- package/templates/nextjs/mvc/.gitignore.hbs +42 -0
- package/templates/nextjs/mvc/Dockerfile.hbs +23 -8
- package/templates/nextjs/mvc/docker-compose.yml.hbs +1 -1
- package/templates/nodejs-express/clean/.gitignore.hbs +42 -0
- package/templates/nodejs-express/clean/Dockerfile.hbs +6 -1
- package/templates/nodejs-express/clean/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/clean/package.json.hbs +69 -69
- package/templates/nodejs-express/clean/src/config.ts.hbs +11 -0
- package/templates/nodejs-express/clean/src/domain/entities/User.ts.hbs +46 -8
- package/templates/nodejs-express/hexagonal/.gitignore.hbs +42 -0
- package/templates/nodejs-express/hexagonal/Dockerfile.hbs +1 -1
- package/templates/nodejs-express/hexagonal/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/hexagonal/package.json.hbs +69 -69
- package/templates/nodejs-express/hexagonal/src/adapters/inbound/http/PaymentController.ts.hbs +21 -38
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts.hbs +2 -0
- package/templates/nodejs-express/hexagonal/src/config.ts.hbs +9 -0
- package/templates/nodejs-express/hexagonal/src/core/AuthService.ts.hbs +5 -5
- package/templates/nodejs-express/hexagonal/src/core/PaymentService.ts.hbs +7 -22
- package/templates/nodejs-express/hexagonal/src/core/domain/entities/User.ts.hbs +24 -4
- package/templates/nodejs-express/mvc/.gitignore.hbs +42 -0
- package/templates/nodejs-express/mvc/package.json.hbs +67 -67
- package/templates/python-fastapi/clean/.gitignore.hbs +76 -0
- package/templates/python-fastapi/clean/app/application/services/payment_service.py.hbs +3 -3
- package/templates/python-fastapi/clean/app/config.py.hbs +6 -7
- package/templates/python-fastapi/clean/app/domain/usecases/login_user.py.hbs +15 -0
- package/templates/python-fastapi/clean/app/infrastructure/http/auth_controller.py.hbs +40 -6
- package/templates/python-fastapi/clean/app/infrastructure/http/payment_controller.py.hbs +5 -4
- package/templates/python-fastapi/clean/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/clean/app/main.py.hbs +3 -0
- package/templates/python-fastapi/clean/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/clean/requirements.txt.hbs +3 -0
- package/templates/python-fastapi/hexagonal/.gitignore.hbs +76 -0
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/http_adapter.py.hbs +6 -9
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/payment_http_adapter.py.hbs +4 -3
- package/templates/python-fastapi/hexagonal/app/adapters/outbound/stripe_adapter.py.hbs +30 -19
- package/templates/python-fastapi/hexagonal/app/config.py.hbs +14 -4
- package/templates/python-fastapi/hexagonal/app/core/domain/user.py.hbs +3 -1
- package/templates/python-fastapi/hexagonal/app/core/payment_service.py.hbs +28 -18
- package/templates/python-fastapi/hexagonal/app/core/ports/__init__.py.hbs +3 -0
- package/templates/python-fastapi/hexagonal/app/core/ports/user_repository.py.hbs +15 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/session.py.hbs +7 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/user_repository.py.hbs +53 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/__init__.py.hbs +0 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/adapters.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/hexagonal/requirements.txt.hbs +4 -0
- package/templates/python-fastapi/mvc/.gitignore.hbs +76 -0
- package/templates/python-fastapi/mvc/app/controllers/payments.py.hbs +3 -17
- package/templates/python-fastapi/mvc/app/middleware/security.py.hbs +24 -3
- package/templates/python-fastapi/mvc/app/schemas/item.py.hbs +3 -1
- package/templates/python-fastapi/mvc/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/mvc/requirements.txt.hbs +3 -1
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts +0 -5
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { authService } from '../../../infrastructure/config/registry/auth.registry';
|
|
4
|
+
|
|
5
|
+
// ── Validation schemas ────────────────────────────────────────────────────────
|
|
6
|
+
const registerSchema = z.object({
|
|
7
|
+
name: z.string().min(1, 'Nome é obrigatório'),
|
|
8
|
+
email: z.string().email('Email inválido'),
|
|
9
|
+
password: z.string().min(8, 'Senha deve ter pelo menos 8 caracteres'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const loginSchema = z.object({
|
|
13
|
+
email: z.string().email('Email inválido'),
|
|
14
|
+
password: z.string().min(1, 'Senha é obrigatória'),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// ── Cookie helpers ────────────────────────────────────────────────────────────
|
|
18
|
+
const REFRESH_COOKIE = 'refreshToken';
|
|
19
|
+
const COOKIE_OPTIONS = {
|
|
20
|
+
httpOnly: true,
|
|
21
|
+
secure: process.env['NODE_ENV'] === 'production',
|
|
22
|
+
sameSite: 'strict' as const,
|
|
23
|
+
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days in ms
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ── Controllers ───────────────────────────────────────────────────────────────
|
|
27
|
+
export async function register(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
28
|
+
const parsed = registerSchema.safeParse(req.body);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const user = await authService.register(parsed.data);
|
|
36
|
+
|
|
37
|
+
// Generate tokens right away so the client is logged in after registration
|
|
38
|
+
const loginResult = await authService.login({
|
|
39
|
+
email: parsed.data.email,
|
|
40
|
+
password: parsed.data.password,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
res.cookie(REFRESH_COOKIE, loginResult.refreshToken, COOKIE_OPTIONS);
|
|
44
|
+
res.status(201).json({ user, accessToken: loginResult.accessToken });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
next(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function login(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
51
|
+
const parsed = loginSchema.safeParse(req.body);
|
|
52
|
+
if (!parsed.success) {
|
|
53
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const { accessToken, refreshToken, user } = await authService.login(parsed.data);
|
|
59
|
+
res.cookie(REFRESH_COOKIE, refreshToken, COOKIE_OPTIONS);
|
|
60
|
+
res.status(200).json({ accessToken, user });
|
|
61
|
+
} catch (err) {
|
|
62
|
+
next(err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function refresh(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
67
|
+
const token = (req.cookies as Record<string, string | undefined>)[REFRESH_COOKIE];
|
|
68
|
+
if (!token) {
|
|
69
|
+
res.status(401).json({ error: 'Refresh token não encontrado' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const { accessToken } = await authService.refreshToken(token);
|
|
75
|
+
res.status(200).json({ accessToken });
|
|
76
|
+
} catch (err) {
|
|
77
|
+
next(err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function logout(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
82
|
+
const token = (req.cookies as Record<string, string | undefined>)[REFRESH_COOKIE];
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
if (token) {
|
|
86
|
+
await authService.logout(token);
|
|
87
|
+
}
|
|
88
|
+
res.clearCookie(REFRESH_COOKIE);
|
|
89
|
+
res.status(204).send();
|
|
90
|
+
} catch (err) {
|
|
91
|
+
next(err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function me(req: Request, res: Response): void {
|
|
96
|
+
res.status(200).json(req.user);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function adminTest(_req: Request, res: Response): void {
|
|
100
|
+
res.status(200).json({ message: 'Admin access granted' });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function forgotPassword(
|
|
104
|
+
req: Request,
|
|
105
|
+
res: Response,
|
|
106
|
+
next: NextFunction,
|
|
107
|
+
): Promise<void> {
|
|
108
|
+
const parsed = z
|
|
109
|
+
.object({ email: z.string().email('Email inválido') })
|
|
110
|
+
.safeParse(req.body);
|
|
111
|
+
if (!parsed.success) {
|
|
112
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
await authService.forgotPassword({ email: parsed.data.email });
|
|
117
|
+
// Always respond with the same message to prevent user enumeration
|
|
118
|
+
res
|
|
119
|
+
.status(200)
|
|
120
|
+
.json({ message: 'Se o email existir, você receberá as instruções em breve.' });
|
|
121
|
+
} catch (err) {
|
|
122
|
+
next(err);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function resetPassword(
|
|
127
|
+
req: Request,
|
|
128
|
+
res: Response,
|
|
129
|
+
next: NextFunction,
|
|
130
|
+
): Promise<void> {
|
|
131
|
+
const parsed = z
|
|
132
|
+
.object({
|
|
133
|
+
token: z.string().min(1, 'Token é obrigatório'),
|
|
134
|
+
newPassword: z.string().min(6, 'A senha deve ter pelo menos 6 caracteres'),
|
|
135
|
+
})
|
|
136
|
+
.safeParse(req.body);
|
|
137
|
+
if (!parsed.success) {
|
|
138
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
await authService.resetPassword(parsed.data);
|
|
143
|
+
res.status(200).json({ message: 'Senha redefinida com sucesso.' });
|
|
144
|
+
} catch (err) {
|
|
145
|
+
next(err);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { authenticate } from '../../middlewares/authenticate';
|
|
3
|
+
import { authorize } from '../../middlewares/authorize';
|
|
4
|
+
import * as authController from './auth.controller';
|
|
5
|
+
|
|
6
|
+
const router = Router();
|
|
7
|
+
|
|
8
|
+
router.post('/register', authController.register);
|
|
9
|
+
router.post('/login', authController.login);
|
|
10
|
+
router.post('/refresh', authController.refresh);
|
|
11
|
+
router.post('/logout', authController.logout);
|
|
12
|
+
router.get('/me', authenticate, authController.me);
|
|
13
|
+
router.get('/admin-test', authenticate, authorize('ADMIN'), authController.adminTest);
|
|
14
|
+
router.post('/forgot-password', authController.forgotPassword);
|
|
15
|
+
router.post('/reset-password', authController.resetPassword);
|
|
16
|
+
|
|
17
|
+
export default router;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { cartService } from '../../../infrastructure/config/registry/cart.registry';
|
|
4
|
+
import type { CartKey } from '../../../application/cart/cart.service';
|
|
5
|
+
|
|
6
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
7
|
+
function cartKey(req: Request): CartKey {
|
|
8
|
+
// req.user is attached by authenticate middleware — always present on cart routes
|
|
9
|
+
const user = req.user as { id: string } | undefined;
|
|
10
|
+
if (user) return { userId: user.id };
|
|
11
|
+
// Fallback for anonymous access (not currently used — routes all require auth)
|
|
12
|
+
const sessionId = (req.headers['x-session-id'] as string | undefined) ?? 'anon';
|
|
13
|
+
return { sessionId };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ── Zod schemas ───────────────────────────────────────────────────────────────
|
|
17
|
+
const addItemSchema = z.object({
|
|
18
|
+
productId: z.string().min(1),
|
|
19
|
+
variantId: z.string().min(1),
|
|
20
|
+
qty: z.number().int().min(1, 'Quantidade deve ser maior que zero'),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const updateItemSchema = z.object({
|
|
24
|
+
qty: z.number().int().min(0, 'Quantidade não pode ser negativa'),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const applyCouponSchema = z.object({
|
|
28
|
+
code: z.string().min(1),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const shippingQuerySchema = z.object({
|
|
32
|
+
cep: z.string().regex(/^\d{8}$/, 'CEP inválido — use 8 dígitos numéricos'),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ── Controllers ───────────────────────────────────────────────────────────────
|
|
36
|
+
export async function getCart(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
const cart = await cartService.getCart(cartKey(req));
|
|
39
|
+
res.status(200).json(cart.toRecord());
|
|
40
|
+
} catch (err) {
|
|
41
|
+
next(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function addItem(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
46
|
+
try {
|
|
47
|
+
const dto = addItemSchema.parse(req.body);
|
|
48
|
+
const cart = await cartService.addItem(cartKey(req), dto);
|
|
49
|
+
res.status(201).json(cart.toRecord());
|
|
50
|
+
} catch (err) {
|
|
51
|
+
next(err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function updateItem(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
56
|
+
try {
|
|
57
|
+
const { variantId } = req.params as { variantId: string };
|
|
58
|
+
const { qty } = updateItemSchema.parse(req.body);
|
|
59
|
+
const cart = await cartService.updateItem(cartKey(req), variantId, qty);
|
|
60
|
+
res.status(200).json(cart.toRecord());
|
|
61
|
+
} catch (err) {
|
|
62
|
+
next(err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function removeItem(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
67
|
+
try {
|
|
68
|
+
const { variantId } = req.params as { variantId: string };
|
|
69
|
+
await cartService.removeItem(cartKey(req), variantId);
|
|
70
|
+
res.status(204).send();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
next(err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function applyCoupon(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
77
|
+
try {
|
|
78
|
+
const { code } = applyCouponSchema.parse(req.body);
|
|
79
|
+
const cart = await cartService.applyCoupon(cartKey(req), code);
|
|
80
|
+
res.status(200).json(cart.toRecord());
|
|
81
|
+
} catch (err) {
|
|
82
|
+
next(err);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function getShipping(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
87
|
+
try {
|
|
88
|
+
const { cep } = shippingQuerySchema.parse(req.query);
|
|
89
|
+
const options = await cartService.getShippingOptions(cartKey(req), cep);
|
|
90
|
+
res.status(200).json(options);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
next(err);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { authenticate } from '../../middlewares/authenticate';
|
|
3
|
+
import * as cartController from './cart.controller';
|
|
4
|
+
|
|
5
|
+
const router = Router();
|
|
6
|
+
|
|
7
|
+
// All cart routes require authentication (users must be logged in)
|
|
8
|
+
router.use(authenticate);
|
|
9
|
+
|
|
10
|
+
router.get('/', cartController.getCart);
|
|
11
|
+
router.post('/items', cartController.addItem);
|
|
12
|
+
router.patch('/items/:variantId', cartController.updateItem);
|
|
13
|
+
router.delete('/items/:variantId', cartController.removeItem);
|
|
14
|
+
router.post('/coupon', cartController.applyCoupon);
|
|
15
|
+
router.get('/shipping', cartController.getShipping);
|
|
16
|
+
|
|
17
|
+
export default router;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { catalogService } from '../../../infrastructure/config/registry/catalog.registry';
|
|
4
|
+
|
|
5
|
+
// ── Validation schemas ────────────────────────────────────────────────────────
|
|
6
|
+
const variantSchema = z.object({
|
|
7
|
+
sku: z.string().min(1),
|
|
8
|
+
size: z.string().nullish(),
|
|
9
|
+
color: z.string().nullish(),
|
|
10
|
+
stock: z.number().int().min(0),
|
|
11
|
+
price: z.number().positive().nullish(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const createProductSchema = z.object({
|
|
15
|
+
name: z.string().min(1, 'Nome é obrigatório'),
|
|
16
|
+
description: z.string().nullish(),
|
|
17
|
+
price: z.number({ required_error: 'Preço é obrigatório' }),
|
|
18
|
+
categoryId: z.string().optional(),
|
|
19
|
+
categorySlug: z.string().optional(),
|
|
20
|
+
images: z.array(z.string().url()).default([]),
|
|
21
|
+
variants: z.array(variantSchema).min(1, 'Pelo menos uma variação é necessária'),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const updateProductSchema = z.object({
|
|
25
|
+
name: z.string().min(1).optional(),
|
|
26
|
+
description: z.string().nullish(),
|
|
27
|
+
price: z.number().optional(),
|
|
28
|
+
images: z.array(z.string().url()).optional(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const stockUpdateSchema = z.object({
|
|
32
|
+
variantId: z.string().min(1),
|
|
33
|
+
delta: z.number().int(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const listQuerySchema = z.object({
|
|
37
|
+
categorySlug: z.string().optional(),
|
|
38
|
+
categoryId: z.string().optional(),
|
|
39
|
+
minPrice: z.coerce.number().optional(),
|
|
40
|
+
maxPrice: z.coerce.number().optional(),
|
|
41
|
+
q: z.string().optional(),
|
|
42
|
+
sortBy: z.enum(['price_asc', 'price_desc', 'newest']).optional(),
|
|
43
|
+
cursor: z.string().optional(),
|
|
44
|
+
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ── Controllers ───────────────────────────────────────────────────────────────
|
|
48
|
+
export async function listProducts(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
49
|
+
const parsed = listQuerySchema.safeParse(req.query);
|
|
50
|
+
if (!parsed.success) {
|
|
51
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Resolve categorySlug → categoryId if needed
|
|
57
|
+
let categoryId = parsed.data.categoryId;
|
|
58
|
+
if (!categoryId && parsed.data.categorySlug) {
|
|
59
|
+
const cats = await catalogService.listCategories();
|
|
60
|
+
const cat = cats.find((c) => c.slug === parsed.data.categorySlug);
|
|
61
|
+
if (cat) categoryId = cat.id;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await catalogService.searchProducts({
|
|
65
|
+
...parsed.data,
|
|
66
|
+
categoryId,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
res.status(200).json({
|
|
70
|
+
items: result.items.map((p) => p.toRecord()),
|
|
71
|
+
nextCursor: result.nextCursor,
|
|
72
|
+
});
|
|
73
|
+
} catch (err) {
|
|
74
|
+
next(err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function getProduct(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
79
|
+
try {
|
|
80
|
+
const product = await catalogService.getProductBySlug(req.params['slug'] ?? '');
|
|
81
|
+
res.status(200).json(product.toRecord());
|
|
82
|
+
} catch (err) {
|
|
83
|
+
next(err);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function createProduct(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
88
|
+
const parsed = createProductSchema.safeParse(req.body);
|
|
89
|
+
if (!parsed.success) {
|
|
90
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const product = await catalogService.createProduct(parsed.data);
|
|
96
|
+
res.status(201).json(product.toRecord());
|
|
97
|
+
} catch (err) {
|
|
98
|
+
next(err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function updateProduct(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
103
|
+
const parsed = updateProductSchema.safeParse(req.body);
|
|
104
|
+
if (!parsed.success) {
|
|
105
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const product = await catalogService.updateProduct(req.params['id'] ?? '', parsed.data);
|
|
111
|
+
res.status(200).json(product.toRecord());
|
|
112
|
+
} catch (err) {
|
|
113
|
+
next(err);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function deleteProduct(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
118
|
+
try {
|
|
119
|
+
await catalogService.deleteProduct(req.params['id'] ?? '');
|
|
120
|
+
res.status(204).send();
|
|
121
|
+
} catch (err) {
|
|
122
|
+
next(err);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function updateStock(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
127
|
+
const parsed = stockUpdateSchema.safeParse(req.body);
|
|
128
|
+
if (!parsed.success) {
|
|
129
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const result = await catalogService.updateStock({
|
|
135
|
+
productId: req.params['id'] ?? '',
|
|
136
|
+
variantId: parsed.data.variantId,
|
|
137
|
+
delta: parsed.data.delta,
|
|
138
|
+
});
|
|
139
|
+
res.status(200).json(result);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
next(err);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function listCategories(_req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
146
|
+
try {
|
|
147
|
+
const cats = await catalogService.listCategories();
|
|
148
|
+
res.status(200).json({ data: cats.map((c) => c.toRecord()) });
|
|
149
|
+
} catch (err) {
|
|
150
|
+
next(err);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function uploadProductImage(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
155
|
+
if (!req.file) {
|
|
156
|
+
res.status(400).json({ error: 'Arquivo de imagem obrigatório' });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const ALLOWED_MIMETYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
|
161
|
+
if (!ALLOWED_MIMETYPES.includes(req.file.mimetype)) {
|
|
162
|
+
res.status(400).json({ error: 'Apenas imagens JPEG, PNG, GIF ou WebP são aceitas' });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const product = await catalogService.uploadProductImage(
|
|
168
|
+
req.params['id'] ?? '',
|
|
169
|
+
req.file.buffer,
|
|
170
|
+
req.file.mimetype,
|
|
171
|
+
);
|
|
172
|
+
res.status(200).json(product.toRecord());
|
|
173
|
+
} catch (err) {
|
|
174
|
+
next(err);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import multer from 'multer';
|
|
3
|
+
import { authenticate } from '../../middlewares/authenticate';
|
|
4
|
+
import { authorize } from '../../middlewares/authorize';
|
|
5
|
+
import { validateUuidParam } from '../../validators/uuidParam';
|
|
6
|
+
import * as catalogController from './catalog.controller';
|
|
7
|
+
|
|
8
|
+
const router = Router();
|
|
9
|
+
|
|
10
|
+
// Multer: memory storage, 5 MB limit — MIME validation done in controller
|
|
11
|
+
const imageUpload = multer({
|
|
12
|
+
storage: multer.memoryStorage(),
|
|
13
|
+
limits: { fileSize: 5 * 1024 * 1024 },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// ── Public routes ─────────────────────────────────────────────────────────────
|
|
17
|
+
router.get('/', catalogController.listProducts);
|
|
18
|
+
router.get('/:slug', catalogController.getProduct);
|
|
19
|
+
|
|
20
|
+
// ── Admin-only routes ─────────────────────────────────────────────────────────
|
|
21
|
+
router.post('/', authenticate, authorize('ADMIN'), catalogController.createProduct);
|
|
22
|
+
router.put('/:id', authenticate, authorize('ADMIN'), validateUuidParam(), catalogController.updateProduct);
|
|
23
|
+
router.delete('/:id', authenticate, authorize('ADMIN'), validateUuidParam(), catalogController.deleteProduct);
|
|
24
|
+
router.patch('/:id/stock', authenticate, authorize('ADMIN'), validateUuidParam(), catalogController.updateStock);
|
|
25
|
+
router.post(
|
|
26
|
+
'/:id/image',
|
|
27
|
+
authenticate,
|
|
28
|
+
authorize('ADMIN'),
|
|
29
|
+
validateUuidParam(),
|
|
30
|
+
imageUpload.single('image'),
|
|
31
|
+
catalogController.uploadProductImage,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export default router;
|
|
35
|
+
|
|
36
|
+
// ── Stand-alone categories router ─────────────────────────────────────────────
|
|
37
|
+
export const categoryRouter = Router();
|
|
38
|
+
categoryRouter.get('/', catalogController.listCategories);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { checkoutRegistry } from '../../../infrastructure/config/registry/checkout.registry';
|
|
4
|
+
import { AppError } from '../../../domain/shared/AppError';
|
|
5
|
+
|
|
6
|
+
// ── Zod schemas ───────────────────────────────────────────────────────────────
|
|
7
|
+
const checkoutSchema = z.object({
|
|
8
|
+
shippingCost: z.number().min(0),
|
|
9
|
+
shippingAddress: z
|
|
10
|
+
.record(z.string(), z.string())
|
|
11
|
+
.nullable()
|
|
12
|
+
.optional()
|
|
13
|
+
.transform((v) => v ?? null),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// ── POST /api/checkout ────────────────────────────────────────────────────────
|
|
17
|
+
export async function checkout(
|
|
18
|
+
req: Request,
|
|
19
|
+
res: Response,
|
|
20
|
+
next: NextFunction,
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
try {
|
|
23
|
+
const user = req.user as { id: string };
|
|
24
|
+
const dto = checkoutSchema.parse(req.body);
|
|
25
|
+
|
|
26
|
+
const result = await checkoutRegistry.checkoutService.checkout({
|
|
27
|
+
userId: user.id,
|
|
28
|
+
shippingCost: dto.shippingCost,
|
|
29
|
+
shippingAddress: dto.shippingAddress ?? null,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
res.status(201).json(result);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
next(err);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ── POST /api/checkout/webhook ────────────────────────────────────────────────
|
|
39
|
+
export async function webhook(
|
|
40
|
+
req: Request,
|
|
41
|
+
res: Response,
|
|
42
|
+
next: NextFunction,
|
|
43
|
+
): Promise<void> {
|
|
44
|
+
try {
|
|
45
|
+
const signature = req.headers['stripe-signature'];
|
|
46
|
+
if (!signature || typeof signature !== 'string') {
|
|
47
|
+
throw new AppError('Header stripe-signature ausente', 400);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// req.body is a Buffer when using express.raw()
|
|
51
|
+
const payload =
|
|
52
|
+
Buffer.isBuffer(req.body) ? req.body.toString('utf-8') : JSON.stringify(req.body);
|
|
53
|
+
|
|
54
|
+
await checkoutRegistry.webhookHandler.handleEvent(payload, signature);
|
|
55
|
+
res.status(200).json({ received: true });
|
|
56
|
+
} catch (err) {
|
|
57
|
+
next(err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { authenticate } from '../../middlewares/authenticate';
|
|
4
|
+
import * as checkoutController from './checkout.controller';
|
|
5
|
+
|
|
6
|
+
const router = Router();
|
|
7
|
+
|
|
8
|
+
// POST /api/checkout — create order and payment intent
|
|
9
|
+
router.post('/', authenticate, checkoutController.checkout);
|
|
10
|
+
|
|
11
|
+
// POST /api/checkout/webhook — Stripe webhook (raw body required for signature verification)
|
|
12
|
+
router.post(
|
|
13
|
+
'/webhook',
|
|
14
|
+
express.raw({ type: 'application/json' }),
|
|
15
|
+
checkoutController.webhook,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default router;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { orderService } from '../../../infrastructure/config/registry/orders.registry';
|
|
4
|
+
import type { OrderStatus } from '../../../domain/checkout/order.entity';
|
|
5
|
+
|
|
6
|
+
// ── Zod schemas ───────────────────────────────────────────────────────────────
|
|
7
|
+
const paginationSchema = z.object({
|
|
8
|
+
cursor: z.string().optional(),
|
|
9
|
+
limit: z.coerce.number().int().min(1).max(100).optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const updateStatusSchema = z.object({
|
|
13
|
+
status: z.enum(['PENDING', 'PAID', 'FAILED', 'SHIPPED', 'DELIVERED', 'CANCELLED']),
|
|
14
|
+
trackingCode: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const statusFilterSchema = z.object({
|
|
18
|
+
status: z.enum(['PENDING', 'PAID', 'FAILED', 'SHIPPED', 'DELIVERED', 'CANCELLED']).optional(),
|
|
19
|
+
cursor: z.string().optional(),
|
|
20
|
+
limit: z.coerce.number().int().min(1).max(100).optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function serializeOrder(order: { toRecord: () => object }) {
|
|
24
|
+
return order.toRecord();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ── Customer controllers ──────────────────────────────────────────────────────
|
|
28
|
+
export async function listOrders(
|
|
29
|
+
req: Request,
|
|
30
|
+
res: Response,
|
|
31
|
+
next: NextFunction,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
try {
|
|
34
|
+
const user = req.user as { id: string };
|
|
35
|
+
const { cursor, limit } = paginationSchema.parse(req.query);
|
|
36
|
+
const result = await orderService.getOrdersByUser(user.id, { cursor, limit });
|
|
37
|
+
res.status(200).json({
|
|
38
|
+
items: result.items.map(serializeOrder),
|
|
39
|
+
nextCursor: result.nextCursor,
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
next(err);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function getOrder(
|
|
47
|
+
req: Request,
|
|
48
|
+
res: Response,
|
|
49
|
+
next: NextFunction,
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
try {
|
|
52
|
+
const user = req.user as { id: string };
|
|
53
|
+
const { id } = req.params as { id: string };
|
|
54
|
+
const order = await orderService.getOrderById(id, user.id);
|
|
55
|
+
res.status(200).json(serializeOrder(order));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
next(err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── Admin controllers ─────────────────────────────────────────────────────────
|
|
62
|
+
export async function adminListOrders(
|
|
63
|
+
req: Request,
|
|
64
|
+
res: Response,
|
|
65
|
+
next: NextFunction,
|
|
66
|
+
): Promise<void> {
|
|
67
|
+
try {
|
|
68
|
+
const { status, cursor, limit } = statusFilterSchema.parse(req.query);
|
|
69
|
+
const result = await orderService.getAllOrders({
|
|
70
|
+
status: status as OrderStatus | undefined,
|
|
71
|
+
cursor,
|
|
72
|
+
limit,
|
|
73
|
+
});
|
|
74
|
+
res.status(200).json({
|
|
75
|
+
items: result.items.map(serializeOrder),
|
|
76
|
+
nextCursor: result.nextCursor,
|
|
77
|
+
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
next(err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function adminUpdateOrderStatus(
|
|
84
|
+
req: Request,
|
|
85
|
+
res: Response,
|
|
86
|
+
next: NextFunction,
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
try {
|
|
89
|
+
const { id } = req.params as { id: string };
|
|
90
|
+
const { status, trackingCode } = updateStatusSchema.parse(req.body);
|
|
91
|
+
const order = await orderService.updateOrderStatus(id, status, trackingCode);
|
|
92
|
+
res.status(200).json(serializeOrder(order));
|
|
93
|
+
} catch (err) {
|
|
94
|
+
next(err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { authenticate } from '../../middlewares/authenticate';
|
|
3
|
+
import { authorize } from '../../middlewares/authorize';
|
|
4
|
+
import { validateUuidParam } from '../../validators/uuidParam';
|
|
5
|
+
import * as orderController from './order.controller';
|
|
6
|
+
|
|
7
|
+
// ── Customer routes — mounted at /api/orders ──────────────────────────────────
|
|
8
|
+
export const orderRoutes = Router();
|
|
9
|
+
orderRoutes.use(authenticate);
|
|
10
|
+
orderRoutes.get('/', orderController.listOrders);
|
|
11
|
+
orderRoutes.get('/:id', validateUuidParam(), orderController.getOrder);
|
|
12
|
+
|
|
13
|
+
// ── Admin routes — mounted at /api/admin/orders ───────────────────────────────
|
|
14
|
+
export const adminOrderRoutes = Router();
|
|
15
|
+
adminOrderRoutes.use(authenticate, authorize('ADMIN'));
|
|
16
|
+
adminOrderRoutes.get('/', orderController.adminListOrders);
|
|
17
|
+
adminOrderRoutes.patch('/:id/status', validateUuidParam(), orderController.adminUpdateOrderStatus);
|