updateweb
This commit is contained in:
@@ -82,13 +82,17 @@ const validators = {
|
||||
body("name")
|
||||
.isLength({ min: 1, max: 255 })
|
||||
.withMessage("Product name is required (max 255 characters)")
|
||||
.trim()
|
||||
.escape(),
|
||||
.trim(),
|
||||
body("shortdescription")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 500 })
|
||||
.withMessage("Short description must be under 500 characters")
|
||||
.trim(),
|
||||
body("description")
|
||||
.optional()
|
||||
.isString()
|
||||
.withMessage("Description must be text")
|
||||
.trim(),
|
||||
.withMessage("Description must be text"),
|
||||
body("price")
|
||||
.isFloat({ min: 0 })
|
||||
.withMessage("Price must be a positive number"),
|
||||
@@ -100,18 +104,78 @@ const validators = {
|
||||
.optional()
|
||||
.isString()
|
||||
.withMessage("Category must be text")
|
||||
.trim()
|
||||
.escape(),
|
||||
.trim(),
|
||||
body("sku")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("SKU must be under 100 characters")
|
||||
.trim(),
|
||||
body("weight")
|
||||
.optional()
|
||||
.isFloat({ min: 0 })
|
||||
.withMessage("Weight must be a positive number"),
|
||||
body("dimensions")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("Dimensions must be under 100 characters")
|
||||
.trim(),
|
||||
body("material")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 255 })
|
||||
.withMessage("Material must be under 255 characters")
|
||||
.trim(),
|
||||
body("isactive")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Active status must be true or false"),
|
||||
body("isfeatured")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Featured status must be true or false"),
|
||||
body("isbestseller")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Bestseller status must be true or false"),
|
||||
body("images").optional().isArray().withMessage("Images must be an array"),
|
||||
body("images.*.color_variant")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("Color variant must be under 100 characters")
|
||||
.trim(),
|
||||
body("images.*.image_url")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 500 })
|
||||
.withMessage("Image URL must be under 500 characters"),
|
||||
body("images.*.alt_text")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 255 })
|
||||
.withMessage("Alt text must be under 255 characters")
|
||||
.trim(),
|
||||
],
|
||||
|
||||
updateProduct: [
|
||||
param("id").isUUID().withMessage("Invalid product ID"),
|
||||
param("id").notEmpty().withMessage("Invalid product ID"),
|
||||
body("name")
|
||||
.optional()
|
||||
.isLength({ min: 1, max: 255 })
|
||||
.withMessage("Product name must be 1-255 characters")
|
||||
.trim()
|
||||
.escape(),
|
||||
.trim(),
|
||||
body("shortdescription")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 500 })
|
||||
.withMessage("Short description must be under 500 characters")
|
||||
.trim(),
|
||||
body("description")
|
||||
.optional()
|
||||
.isString()
|
||||
.withMessage("Description must be text"),
|
||||
body("price")
|
||||
.optional()
|
||||
.isFloat({ min: 0 })
|
||||
@@ -120,6 +184,63 @@ const validators = {
|
||||
.optional()
|
||||
.isInt({ min: 0 })
|
||||
.withMessage("Stock quantity must be a non-negative integer"),
|
||||
body("category")
|
||||
.optional()
|
||||
.isString()
|
||||
.withMessage("Category must be text")
|
||||
.trim(),
|
||||
body("sku")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("SKU must be under 100 characters")
|
||||
.trim(),
|
||||
body("weight")
|
||||
.optional()
|
||||
.isFloat({ min: 0 })
|
||||
.withMessage("Weight must be a positive number"),
|
||||
body("dimensions")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("Dimensions must be under 100 characters")
|
||||
.trim(),
|
||||
body("material")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 255 })
|
||||
.withMessage("Material must be under 255 characters")
|
||||
.trim(),
|
||||
body("isactive")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Active status must be true or false"),
|
||||
body("isfeatured")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Featured status must be true or false"),
|
||||
body("isbestseller")
|
||||
.optional()
|
||||
.isBoolean()
|
||||
.withMessage("Bestseller status must be true or false"),
|
||||
body("images").optional().isArray().withMessage("Images must be an array"),
|
||||
body("images.*.color_variant")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 100 })
|
||||
.withMessage("Color variant must be under 100 characters")
|
||||
.trim(),
|
||||
body("images.*.image_url")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 500 })
|
||||
.withMessage("Image URL must be under 500 characters"),
|
||||
body("images.*.alt_text")
|
||||
.optional()
|
||||
.isString()
|
||||
.isLength({ max: 255 })
|
||||
.withMessage("Alt text must be under 255 characters")
|
||||
.trim(),
|
||||
],
|
||||
|
||||
// Blog validators
|
||||
|
||||
Reference in New Issue
Block a user