60 lines
2.9 KiB
TypeScript
60 lines
2.9 KiB
TypeScript
import router from '@adonisjs/core/services/router'
|
|
import { middleware } from '#start/kernel'
|
|
|
|
const AuthController = () => import('#controllers/auth_controller')
|
|
const ProductsController = () => import('#controllers/products_controller')
|
|
const ImportsController = () => import('#controllers/imports_controller')
|
|
const PricingController = () => import('#controllers/pricing_controller')
|
|
const LogsController = () => import('#controllers/logs_controller')
|
|
const HistoriesController = () => import('#controllers/histories_controller')
|
|
const NotificationsController = () => import('#controllers/notifications_controller')
|
|
|
|
router.get('/', async () => ({ service: 'suggestprice-api', status: 'ok' }))
|
|
router.get('/api/health', async () => ({ ok: true }))
|
|
router.get('/api/products/syncProductBySku', [ProductsController, 'syncProductBySku'])
|
|
router.get('/api/products', [ProductsController, 'index'])
|
|
|
|
router
|
|
.group(() => {
|
|
// --- Auth ---
|
|
router.post('/auth/register', [AuthController, 'register'])
|
|
router.post('/auth/login', [AuthController, 'login'])
|
|
|
|
router
|
|
.group(() => {
|
|
router.post('/auth/logout', [AuthController, 'logout'])
|
|
router.get('/auth/me', [AuthController, 'me'])
|
|
|
|
// --- Products (CRUD: manual + sync) ---
|
|
|
|
router.post('/products', [ProductsController, 'store'])
|
|
// Gắn/bỏ cờ noListing hàng loạt — khai báo TRƯỚC '/products/:id' để không bị nuốt bởi route động.
|
|
router.patch('/products/no-listing', [ProductsController, 'setNoListing'])
|
|
router.get('/products/:id', [ProductsController, 'show'])
|
|
router.patch('/products/:id', [ProductsController, 'update'])
|
|
router.delete('/products/:id', [ProductsController, 'destroy'])
|
|
|
|
// --- Import Excel ---
|
|
router.post('/imports/products', [ImportsController, 'products'])
|
|
|
|
// --- Pricing (service gợi ý giá) ---
|
|
router.post('/pricing/suggest/:id', [PricingController, 'suggest'])
|
|
router.post('/pricing/suggest/:id/approve', [PricingController, 'approve'])
|
|
router.post('/pricing/batch', [PricingController, 'batch'])
|
|
|
|
// --- Log & History ---
|
|
router.get('/logs', [LogsController, 'index'])
|
|
router.get('/histories', [HistoriesController, 'index'])
|
|
router.get('/histories/:id', [HistoriesController, 'show'])
|
|
|
|
// --- Notifications (thông báo cho người dùng) ---
|
|
router.get('/notifications', [NotificationsController, 'index'])
|
|
router.get('/notifications/unread-count', [NotificationsController, 'unreadCount'])
|
|
router.patch('/notifications/read-all', [NotificationsController, 'markAllRead'])
|
|
router.patch('/notifications/:id/read', [NotificationsController, 'markRead'])
|
|
router.delete('/notifications/:id', [NotificationsController, 'destroy'])
|
|
})
|
|
.use(middleware.auth())
|
|
})
|
|
.prefix('/api')
|