Snai3i-MarketPlace / backend / src / services / auth / auth.validator.ts
auth.validator.ts
Raw
import { body } from 'express-validator';

export const loginValidators = [
  body('email').isEmail().withMessage('Invalid email'),
  body('password').notEmpty().withMessage('Password is required'),
];

export const registerValidators = [
  body('email').isEmail().withMessage('Invalid email'),
  body('password')
    .isLength({ min: 8 })
    .withMessage('Password must be at least 8 characters long'),
  body('firstName')
    .isLength({ min: 2 })
    .withMessage('First name must be at least 2 characters long'),
  body('lastName')
    .isLength({ min: 2 })
    .withMessage('Last name must be at least 2 characters long'),
  body('role').isIn([
    'admin',
    'super_admin',
    'inst_admin',
    'teacher',
    'school',
    'inst_designer',
  ]),
  body('phone')
    .optional({
      nullable: true,
    })
    .isMobilePhone('any')
    .withMessage('Invalid phone number'),
  body('schoolName')
    .optional()
    .isLength({ min: 2 })
    .withMessage('School name must be at least 2 characters long'),
  body('address')
    .optional({
      nullable: true,
    })
    .isLength({ min: 2 })
    .withMessage('Address must be at least 2 characters long'),
  // isActive
  body('isActive')
    .optional()
    .isBoolean()
    .withMessage('Invalid value for isActive'),
];

export const registerTeacherValidators = [
  body('email').isEmail().withMessage('Invalid email'),
  body('password')
    .isLength({ min: 8 })
    .withMessage('Password must be at least 8 characters long'),
  body('firstName')
    .isLength({ min: 2 })
    .withMessage('First name must be at least 2 characters long'),
  body('lastName')
    .isLength({ min: 2 })
    .withMessage('Last name must be at least 2 characters long'),
  body('role').isIn(['teacher']),
  // phone can be null
  body('phone')
    .optional({
      nullable: true,
    })
    .isMobilePhone('any')
    .withMessage('Invalid phone number'),
  // isActive
  body('isActive')
    .optional()
    .isBoolean()
    .withMessage('Invalid value for isActive'),
];