1. Home
  2. Nodejs Boilerplate
  3. প্রজেক্ট তৈরী ও কনফিগ করা
  4. ১ ০। userValidation.js ফাইল তৈরি

১ ০। userValidation.js ফাইল তৈরি

প্রথমে validation/userValidation.js নামে একটি ফাইল তৈরি করে সেখানে Joi স্কিমাগুলো সংজ্ঞায়িত করবো।

const Joi = require("joi");

// Create User Validation Schema
const createUserSchema = Joi.object({
  username: Joi.string().min(3).max(30).required(),
  email: Joi.string().email().required(),
  password: Joi.string().min(6).required(),
});

// Update User Validation Schema
const updateUserSchema = Joi.object({
  username: Joi.string().min(3).max(30).optional(),
  email: Joi.string().email().optional(),
  password: Joi.string().min(6).optional(),
  // Do not include 'id' in the schema here
});

// Get User by ID Validation Schema
const getUserSchema = Joi.object({
  id: Joi.string().min(1).max(50).required() // Allow IDs of any length between 1 and 50 characters
});

// Delete User by ID Validation Schema
const deleteUserSchema = Joi.object({
  id: Joi.string().min(1).max(50).required() // Allow IDs of any length between 1 and 50 characters
});

module.exports = {
  createUserSchema,
  updateUserSchema,
  getUserSchema,
  deleteUserSchema,
};

How can we help?