add supplier management module
This commit is contained in:
66
backend/src/modules/suppliers/suppliers.routes.ts
Normal file
66
backend/src/modules/suppliers/suppliers.routes.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Router } from 'express';
|
||||
import { body, param } from 'express-validator';
|
||||
import { authenticate, authorize } from '../../shared/middleware/auth';
|
||||
import { validate } from '../../shared/middleware/validation';
|
||||
import { suppliersController } from './suppliers.controller';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use(authenticate);
|
||||
|
||||
router.get('/', authorize('contacts', 'contacts', 'read'), suppliersController.findAll);
|
||||
router.get('/stats', authorize('contacts', 'contacts', 'read'), suppliersController.getStats);
|
||||
router.get('/export', authorize('contacts', 'contacts', 'read'), suppliersController.export);
|
||||
|
||||
router.get(
|
||||
'/:id',
|
||||
authorize('contacts', 'contacts', 'read'),
|
||||
param('id').isUUID(),
|
||||
validate,
|
||||
suppliersController.findById
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/',
|
||||
authorize('contacts', 'contacts', 'create'),
|
||||
[
|
||||
body('name').optional({ values: 'falsy' }).trim(),
|
||||
body('companyName').optional({ values: 'falsy' }).trim(),
|
||||
body('email')
|
||||
.optional({ values: 'falsy' })
|
||||
.custom((value) => {
|
||||
if (value === null || value === undefined || value === '') return true;
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
||||
})
|
||||
.withMessage('Invalid email format'),
|
||||
validate,
|
||||
],
|
||||
suppliersController.create
|
||||
);
|
||||
|
||||
router.put(
|
||||
'/:id',
|
||||
authorize('contacts', 'contacts', 'update'),
|
||||
[
|
||||
param('id').isUUID(),
|
||||
body('email')
|
||||
.optional({ values: 'falsy' })
|
||||
.custom((value) => {
|
||||
if (value === null || value === undefined || value === '') return true;
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
||||
})
|
||||
.withMessage('Invalid email format'),
|
||||
validate,
|
||||
],
|
||||
suppliersController.update
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/archive',
|
||||
authorize('contacts', 'contacts', 'archive'),
|
||||
param('id').isUUID(),
|
||||
validate,
|
||||
suppliersController.archive
|
||||
);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user