@Asprod

TypeError: Cannot read property 'create' of undefined?

Ошибка при создании записи
await User.create({login: userLogin, password: userPassword, license: "2025-12-13"});

Вот контроллер
const {User} = require("../models/models");

class WorkersController {
    async create(req, res){
        let {userLogin, userPassword} = req.body
        let newUser = await User.create({login: userLogin, password: userPassword, license: "2025-12-13"});
        await newUser.save();
        return newUser
    }
    async delete(req, res){
    }
    async block(req, res){
    }
}
module.exports = new WorkersController();


А это модель
const sequelize = require("../db");
const {DataTypes} = require("sequelize");

const User = sequelize.define('User', {
    id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},
    login: {type: DataTypes.STRING, unique:true, allowNull:false},
    password: {type: DataTypes.STRING, allowNull:false},
    role: {type: DataTypes.STRING, defaultValue: "user"},
    tc_login: {type: DataTypes.STRING, allowNull:true},
    blocked: {type: DataTypes.BOOLEAN, defaultValue: false},
    license: {type: DataTypes.DATE, allowNull:false},
    createdAt: {type: DataTypes.DATE, defaultValue: sequelize.literal('NOW()'), allowNull:true}
})

module.export = {
    User, Proxy, Domain, Link, Design
}


Вот db
const {Sequelize} = require("sequelize");
const config = require("./config/config.json")


module.exports = new Sequelize(
    config.development.database,
    config.development.username,
    config.development.password,
    {
        dialect: "postgres",
        host: config.development.host,
        port: config.development.port
    }
)
  • Вопрос задан
  • 36 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы