chore: lint

This commit is contained in:
karishmas6
2024-09-24 17:24:11 +05:30
parent df998b4304
commit 87fa644ecf

View File

@@ -3,56 +3,56 @@ import bcrypt from 'bcrypt';
import sequelize from '../db/config'; import sequelize from '../db/config';
interface UserAttributes { interface UserAttributes {
id: number; id: number;
email: string; email: string;
password: string; password: string;
} }
// Optional fields for creating a new user // Optional fields for creating a new user
interface UserCreationAttributes extends Optional<UserAttributes, 'id'> {} interface UserCreationAttributes extends Optional<UserAttributes, 'id'> { }
class User extends Model<UserAttributes, UserCreationAttributes> implements UserAttributes { class User extends Model<UserAttributes, UserCreationAttributes> implements UserAttributes {
public id!: number; public id!: number;
public email!: string; public email!: string;
public password!: string; public password!: string;
public async isValidPassword(password: string): Promise<boolean> { public async isValidPassword(password: string): Promise<boolean> {
return bcrypt.compare(password, this.password); return bcrypt.compare(password, this.password);
} }
} }
User.init( User.init(
{ {
id: { id: {
type: DataTypes.INTEGER.UNSIGNED, type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true, autoIncrement: true,
primaryKey: true, primaryKey: true,
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true,
},
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
}, },
email: { {
type: DataTypes.STRING, sequelize,
allowNull: false, tableName: 'user',
unique: true, hooks: {
validate: { beforeCreate: async (user: User) => {
isEmail: true, if (user.password) {
}, const salt = await bcrypt.genSalt(10);
}, user.password = await bcrypt.hash(user.password, salt);
password: { }
type: DataTypes.STRING, },
allowNull: false, },
}, }
},
{
sequelize,
tableName: 'user',
hooks: {
beforeCreate: async (user: User) => {
if (user.password) {
const salt = await bcrypt.genSalt(10);
user.password = await bcrypt.hash(user.password, salt);
}
},
},
}
); );
export default User; export default User;