134 lines
3.5 KiB
JavaScript
134 lines
3.5 KiB
JavaScript
|
|
import { body, query } from 'express-validator';
|
|
|
|
// product/create:
|
|
export const productDataValidate = [
|
|
body('plu')
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.withMessage('поле plu обязательно')
|
|
.isNumeric()
|
|
.withMessage('plu должен быть числом')
|
|
.isLength({ min: 4, max: 5 })
|
|
.withMessage('plu должен состоять из 4-5 цифр'),
|
|
body('name')
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.withMessage('поле name обязательно')
|
|
.isLength({ min: 3, max: 100 })
|
|
.withMessage('поле name должно содержать не менее трех и не более 100 символов')
|
|
];
|
|
|
|
// shop/create:
|
|
export const shopDataValidate = [
|
|
body('name')
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.withMessage('поле name обязательно')
|
|
.isLength({ min: 3, max: 100 })
|
|
.withMessage('поле name должно содержать не менее трех и не более 100 символов')
|
|
];
|
|
|
|
// stocks/create:
|
|
export const stocksDataValidate = [
|
|
body('plu')
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.withMessage('поле plu обязательно')
|
|
.isNumeric()
|
|
.withMessage('plu должен быть числом')
|
|
.isLength({ min: 4, max: 5 })
|
|
.withMessage('plu должен состоять из 4-5 цифр'),
|
|
body('shop_id')
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.withMessage('поле shop_id обязательно')
|
|
.isNumeric()
|
|
.withMessage('поле shop_id должно быть числом'),
|
|
body('in_stock')
|
|
.default(0)
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.isNumeric()
|
|
.withMessage('поле in_stock должно быть числом'),
|
|
body('in_order')
|
|
.default(0)
|
|
.exists({ checkFalsy: true, checkNull: true })
|
|
.isNumeric()
|
|
.withMessage('поле in_order должно быть числом'),
|
|
];
|
|
|
|
|
|
// stocks/increase:
|
|
export const increaseDataValidate = [
|
|
body('id')
|
|
.toFloat()
|
|
.default(null),
|
|
body('plu')
|
|
.toFloat()
|
|
.default(null),
|
|
body('shop_id')
|
|
.toFloat()
|
|
.default(null),
|
|
body('increase_shelf')
|
|
.toFloat()
|
|
.default(0),
|
|
body('increase_order')
|
|
.toFloat()
|
|
.default(0),
|
|
];
|
|
|
|
// stocks/decrease:
|
|
export const decreaseDataValidate = [
|
|
body('id')
|
|
.toFloat()
|
|
.default(null),
|
|
body('plu')
|
|
.toFloat()
|
|
.default(null),
|
|
body('shop_id')
|
|
.toFloat()
|
|
.default(null),
|
|
body('decrease_shelf')
|
|
.toFloat()
|
|
.default(0),
|
|
body('decrease_order')
|
|
.toFloat()
|
|
.default(0),
|
|
];
|
|
|
|
// stocks:
|
|
export const getStocksDataValidate = [
|
|
query('plu')
|
|
.toFloat()
|
|
.default(null),
|
|
query('shop_id')
|
|
.toFloat()
|
|
.default(null),
|
|
query('shelf_from')
|
|
.toFloat()
|
|
.default(null),
|
|
query('shelf_to')
|
|
.toFloat()
|
|
.default(null),
|
|
query('order_from')
|
|
.toFloat()
|
|
.default(null),
|
|
query('order_to')
|
|
.toFloat()
|
|
.default(null),
|
|
query('page')
|
|
.toFloat()
|
|
.default(1),
|
|
query('page_size')
|
|
.toFloat()
|
|
.default(10),
|
|
];
|
|
|
|
export const getProductsDataValidate = [
|
|
query('plu')
|
|
.toFloat()
|
|
.default(null),
|
|
query('name')
|
|
.default(null),
|
|
query('page')
|
|
.toFloat()
|
|
.default(1),
|
|
query('page_size')
|
|
.toFloat()
|
|
.default(10),
|
|
]; |