Я пытаюсь создать пользователя, но мне не даёт error = > Cannot read properties of undefined (reading 'findOrCreate')
const auth = new Scenes.WizardScene('auth', async (ctx) => {
try {
if (!ctx?.from) return;
const username = ctx.from.username || ctx.from.id;
const User = await user.findOrCreate({
where: {
id: ctx.from.id,
},
defaults: {
id: ctx.from.id,
username,
}
})
if (user[0].username !== username)
user[0].update({
username,
});
ctx.state.user = user[0];
return next();
models:
'use strict';
const {
Model
} = require('sequelize');
const connectdb = require('../other/connect');
module.exports = (sequelize, DataTypes) => {
class user extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
user.init({
username: DataTypes.STRING,
banned: DataTypes.BOOLEAN,
percent: DataTypes.DECIMAL(36, 2),
status: DataTypes.TINYINT
}, {
sequelize: connectdb,
modelName: 'user',
});
return user;
};
migrations:
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('user', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.BIGINT
},
username: {
type: Sequelize.STRING
},
banned: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false
},
percent: {
type: Sequelize.DECIMAL(36, 2),
allowNull: true,
},
status: {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 0
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await user.sync({ force: true })
console.log("The table for the User model was just (re)created!");
await queryInterface.dropTable('user');
}
};