Estoy aprendiendo sobre NodeJS y estoy tratando de crear datos usando la secuencia de Postgres. pero tengo un error
bcrypt UnhandledPromiseRejectionWarning: Error: data and salt arguments required. Aquí está mi model user.js
'use strict'; const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class User extends Model { /** * Helper method for defining associations. * This method is not a part of the Sequelize lifecycle. * The `models/index` file will call this method automatically. */ static associate(models) { // define association here } }; User.init({ full_name: { type: DataTypes.STRING, allowNull: false, validate: { notEmpty: { msg: 'Nama tidak boleh kosong' } } }, email: { type: DataTypes.STRING, allowNull: false, validate: { isEmail: true, notEmpty: { msg: 'Email tidak boleh kosong' }, unique: { args: true, msg: 'Email address already in use!' } } }, username: { type: DataTypes.STRING, allowNull: false, validate: { notEmpty: { msg: 'Username tidak boleh kosong' } } }, password: { type: DataTypes.STRING, allowNull: false, validate: { notEmpty: { msg: 'Password tidak boleh kosong' } } }, profile_image_url: { type: DataTypes.STRING, allowNull: true, defaultValue: 'www.image.com', validate: { notEmpty: { msg: 'Url tidak boleh kosong' } } }, age: { type: DataTypes.INTEGER, allowNull: false, validate: { notEmpty: { msg: 'Umur tidak boleh kosong' } } }, phone_number: { type: DataTypes.STRING, allowNull: false, validate: { notEmpty: { msg: 'No telp tidak boleh kosong' } } } }, { sequelize, modelName: 'User', }); return User; }; He estado buscando respuestas de varias otras fuentes, pero aún no las he encontrado. Aquí está mi controller createUser.js .
const { User } = require('../../models/user'); const bcrypt = require('bcrypt'); module.exports = async (req, res) => { const { full_name, email, username, password, age, phone_number } = req.body; const hash = await bcrypt.hash(password, 10); await User.create({ full_name, email, username, password: hash, age, phone_number }).then(success => { return res.status(201).json({ status: 'success', message: 'Success register', data: success }) }).catch(error => { return res.status(400).json({ status: 'error', message: error.message }); }); }