feat(checkout): let the admin choose the details asked at checkout
The admin enables or disables each option (phone, address, Snapchat, Instagram, Telegram, SimpleX, WhatsApp, Signal, notes, preferred time) from a new "Checkout fields" page; the customer's name is always asked. Backend - checkoutfields module: single-row settings (CHECK id = 1), public GET and admin GET/PUT. - orders: answers stored as JSONB (contacts, info_sup); the customer phone moves from customer_phone to contacts.phone (migration 000034 copies existing values before dropping the column). - Orders are validated against the live settings: disabled options and unknown keys are dropped, enabled phone/address are required, and format, length and control characters are checked. - The Telegram notification includes the answers. Frontend - Checkout form generated from the enabled options; admin settings page; answers shown in the order list and detail. - API calls live in src/api (checkoutFields.ts, orders.ts); ApiError keeps the response body so the rejected field can be reported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
178652ef14
commit
f9bfdc9d3c
+10
-1
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"backend/internal/modules/auth"
|
||||
"backend/internal/modules/categories"
|
||||
"backend/internal/modules/checkoutfields"
|
||||
"backend/internal/modules/contactlinks"
|
||||
"backend/internal/modules/customerverification"
|
||||
"backend/internal/modules/media"
|
||||
@@ -85,6 +86,11 @@ func main() {
|
||||
unitsService := units.NewService(unitsRepo)
|
||||
unitsHandler := units.NewHandler(unitsService)
|
||||
|
||||
// --- Checkout fields module ---
|
||||
checkoutFieldsRepo := checkoutfields.NewRepository(database)
|
||||
checkoutFieldsService := checkoutfields.NewService(checkoutFieldsRepo)
|
||||
checkoutFieldsHandler := checkoutfields.NewHandler(checkoutFieldsService)
|
||||
|
||||
// --- Products module ---
|
||||
productsRepo := products.NewRepository(database)
|
||||
productsService := products.NewService(productsRepo, categoriesRepo)
|
||||
@@ -121,7 +127,7 @@ func main() {
|
||||
// --- Orders module (depends on products/units/pricing for authoritative
|
||||
// pricing, and on telegram as its pluggable OrderNotifier) ---
|
||||
ordersRepo := orders.NewRepository(database)
|
||||
ordersService := orders.NewService(ordersRepo, productsService, unitsService, pricingService, telegramService)
|
||||
ordersService := orders.NewService(ordersRepo, productsService, unitsService, pricingService, telegramService, checkoutFieldsService)
|
||||
ordersHandler := orders.NewHandler(ordersService)
|
||||
|
||||
requireAdmin := appmiddleware.RequireAdmin(cfg.JWT.Secret)
|
||||
@@ -166,6 +172,9 @@ func main() {
|
||||
units.RegisterAdminRoutes(api, unitsHandler, requireAdmin)
|
||||
units.RegisterPublicRoutes(api, unitsHandler)
|
||||
|
||||
checkoutfields.RegisterAdminRoutes(api, checkoutFieldsHandler, requireAdmin)
|
||||
checkoutfields.RegisterPublicRoutes(api, checkoutFieldsHandler)
|
||||
|
||||
products.RegisterAdminRoutes(api, productsHandler, requireAdmin)
|
||||
products.RegisterPublicRoutes(api, productsHandler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user