Presupuestador_web/server/src/contexts/auth/infrastructure/sequelize/authUser.model.ts

69 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-05-15 19:56:22 +00:00
import {
DataTypes,
InferAttributes,
InferCreationAttributes,
Model,
Sequelize,
} from "sequelize";
2024-05-21 16:48:40 +00:00
export type AuthUserCreationAttributes =
InferCreationAttributes<AuthUser_Model>;
2024-05-15 19:56:22 +00:00
2024-05-16 18:16:00 +00:00
export class AuthUser_Model extends Model<
InferAttributes<AuthUser_Model>,
InferCreationAttributes<AuthUser_Model>
2024-05-15 19:56:22 +00:00
> {
// To avoid table creation
/*static async sync(): Promise<any> {
return Promise.resolve();
}*/
static associate(connection: Sequelize) {}
declare id: string;
2024-05-16 11:56:46 +00:00
declare name: string;
2024-05-15 19:56:22 +00:00
declare email: string;
declare password: string;
}
export default (sequelize: Sequelize) => {
2024-05-16 18:16:00 +00:00
AuthUser_Model.init(
2024-05-15 19:56:22 +00:00
{
id: {
type: new DataTypes.UUID(),
primaryKey: true,
},
2024-05-16 11:56:46 +00:00
name: {
type: DataTypes.STRING,
},
2024-05-15 19:56:22 +00:00
email: {
type: DataTypes.STRING,
allowNull: false,
},
2024-05-16 11:56:46 +00:00
2024-05-15 19:56:22 +00:00
password: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
sequelize,
tableName: "users",
2024-05-16 11:56:46 +00:00
paranoid: true, // softs deletes
timestamps: true,
2024-05-15 19:56:22 +00:00
//version: true,
2024-05-16 11:56:46 +00:00
createdAt: "created_at",
updatedAt: "updated_at",
deletedAt: "deleted_at",
2024-05-15 19:56:22 +00:00
2024-05-16 11:56:46 +00:00
indexes: [{ name: "email_idx", fields: ["email"] }],
2024-05-15 19:56:22 +00:00
},
);
2024-05-16 18:16:00 +00:00
return AuthUser_Model;
2024-05-15 19:56:22 +00:00
};