получаю notNull Violation: you must enter a name даже если передаю поле name

учусь писать backend на Nodejs. Использую express с mysql и для связи с бд sequelize.

ввожу все поля как описал в файле, делаю post запрос, но выходит notNull Violation: you must enter a name, хотя поле name передано.

models.js


        const sequelize = require('../db')
    const {DataTypes} = require('sequelize')
    
    const User = sequelize.define( 'user', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
        email: {type: DataTypes.STRING, unique: true},
        password: {type: DataTypes.STRING},
        role: {type: DataTypes.STRING, defaultValue: 'USER'},
    })
    const Basket = sequelize.define( 'basket', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
    })
    const BasketProduct = sequelize.define( 'basket_device', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
    })
    const Product = sequelize.define( 'Product', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
        name: {type: DataTypes.STRING, unique: true, allowNull: false, validate: {notNull: {args: true, msg:'you must enter a name'}}},
        price: {type: DataTypes.INTEGER, defaultValue: 0, allowNull: false},
        img: {type: DataTypes.STRING, allowNull: false},
    })
    const Type = sequelize.define( 'type', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
        name: {type: DataTypes.STRING, unique: true, allowNull: false},
    })
    const Brand = sequelize.define( 'brand', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
        name: {type: DataTypes.STRING, unique: true, allowNull: false},
    })
    const ProductInfo = sequelize.define( 'product_info', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
        title: {type: DataTypes.STRING, allowNull: false},
        description: {type: DataTypes.STRING, allowNull: false},
    })
    const TypeBrand = sequelize.define( 'type_brand', {
        id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
    })
    User.hasOne(Basket)
    Basket.belongsTo(User)
    
    Basket.hasMany(BasketProduct)
    BasketProduct.belongsTo(Basket)
    
    Type.hasMany(Product)
    Product.belongsTo(Type)
    
    Brand.hasMany(Product)
    Product.belongsTo(Brand)
    
    Product.hasMany(ProductInfo)
    ProductInfo.belongsTo(Product)
    
    Type.belongsToMany(Brand, {through: TypeBrand })
    Brand.belongsToMany(Type, {through: TypeBrand })
    
    module.exports = {
        User, 
        Basket, 
        BasketProduct, 
        Product, 
        Type, 
        Brand, 
        TypeBrand, 
        ProductInfo
    }

productController.js


    const uuid  = require('uuid');
    const path = require('path');
    const {Product} = require('../models/models');
    const ApiError = require('../error/ApiError')
    class ProductController {
        async create(req, res, next) {
            try {
                const {name, price, brandId, typeId, info} = req.body
                const {img} = req.files
                let fileName = uuid.v4() + ".jpg"
                img.mv(path.resolve(__dirname, '..', 'static', fileName))
                const product = await Product.create({name, price, brandId, typeId, img: fileName});
    
                return res.json(product)
            } catch (e) {
                next(ApiError.BadRequest(e.message))
            }
    module.exports = new ProductController()


Ответы (0 шт):