AI-Tennis-Coach/server/model/user.js
2025-02-11 11:23:59 +05:30

71 lines
1.8 KiB
JavaScript

import { sequelize } from './../loaders/index.js'; // Import the sequelize instance
import { DataTypes } from 'sequelize';
// Define the 'User' model
const User = sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
username: {
type: DataTypes.STRING(100),
allowNull: false,
},
full_name: {
type: DataTypes.STRING(100),
allowNull: false,
},
email: {
type: DataTypes.STRING(255),
allowNull: false,
unique: true, // Email should be unique
validate: {
isEmail: true, // Validate email format
},
},
password: {
type: DataTypes.STRING(255),
allowNull: false, // Password must be provided
},
profile_pic: {
type: DataTypes.TEXT, // Profile picture can be a URL or base64 string
allowNull: true,
},
phone_number: {
type: DataTypes.STRING(15),
allowNull: true, // Phone number is optional
},
age: {
type: DataTypes.STRING(15),
allowNull: true,
},
gender: {
type: DataTypes.STRING(15),
allowNull: true,
},
location: {
type: DataTypes.STRING(255),
allowNull: true,
}
}, {
tableName: 'users', // Define the name of the table
timestamps: true,
});
// Sync the model with the database (creates the table if it doesn't exist)
const syncDb = async () => {
try {
await sequelize.sync({ force: false });
console.log('User table created (or already exists)');
} catch (err) {
console.error('Error syncing the database:', err);
}
};
// Call the sync function
syncDb();
// Export the model to use it in other parts of your application
export { User };