Modelo usuario para poder empezar con login
This commit is contained in:
parent
2a9ec3a346
commit
dd965f7c0a
26
modules/auth/rol.model.js
Normal file
26
modules/auth/rol.model.js
Normal file
@ -0,0 +1,26 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const Rol = sequelize.define('Rol', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
}, {
|
||||
tableName: 'roles',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
Rol.associate = function (models) {
|
||||
Rol.Users = Rol.belongsToMany(models.User, {
|
||||
through: models.UserRoles,
|
||||
foreignKey: 'rolId'
|
||||
});
|
||||
};
|
||||
return Rol;
|
||||
};
|
||||
|
||||
@ -9,6 +9,11 @@ module.exports = function (sequelize, DataTypes) {
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
phone: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
@ -18,11 +23,31 @@ module.exports = function (sequelize, DataTypes) {
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
fbid: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.TINYINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
surname: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
entityId: {
|
||||
type: DataTypes.UUID,
|
||||
foreignKey : true,
|
||||
},
|
||||
profile_picture: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'media/defaultProfile.png',
|
||||
},
|
||||
accessibility: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
},
|
||||
lastlogin: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: null,
|
||||
},
|
||||
}, {
|
||||
tableName: 'user',
|
||||
@ -31,13 +56,15 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
|
||||
User.associate = function (models) {
|
||||
/*User.Categories = User.belongsToMany(models.Category, {
|
||||
through: models.UserCategory,
|
||||
foreignKey: 'UserId'
|
||||
});*/
|
||||
User.Roles = User.belongsToMany(models.Rol, {
|
||||
through: models.UserRoles,
|
||||
foreignKey: 'userId'
|
||||
});
|
||||
User.Entity = User.belongsTo(models.Entity, { foreignKey: 'entityId' });
|
||||
User.Devices = User.hasMany(models.UserDevice, { foreignKey: 'userId' });
|
||||
|
||||
//User.Comments = User.hasMany(models.UserComment, { foreignKey: 'UserId' });
|
||||
//User.Reactions = User.hasMany(models.UserReaction, { foreignKey: 'UserId' });
|
||||
//User.User = User.belongsTo(models.User, { foreignKey: 'userId' });
|
||||
//User.Reactions = User.hasMany(models.UserReaction, { foreignKey: 'UserId' });
|
||||
};
|
||||
|
||||
|
||||
|
||||
37
modules/auth/user_device.model.js
Normal file
37
modules/auth/user_device.model.js
Normal file
@ -0,0 +1,37 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const UserDevice = sequelize.define('UserDevice', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.UUID,
|
||||
foreignKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
token: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
valid: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
},
|
||||
invalidated: {
|
||||
type: DataTypes.DATE,
|
||||
},
|
||||
platform: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
}, {
|
||||
tableName: 'users_devides',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
UserDevice.associate = function (models) {
|
||||
UserDevice.User = UserDevice.belongsTo(models.User, {foreignKey: 'userId' });
|
||||
};
|
||||
|
||||
return UserDevice;
|
||||
};
|
||||
|
||||
19
modules/auth/users_roles.model.js
Normal file
19
modules/auth/users_roles.model.js
Normal file
@ -0,0 +1,19 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const UserRoles = sequelize.define('UserRoles', {
|
||||
userId: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
},
|
||||
rolId: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
},
|
||||
}, {
|
||||
tableName: 'users_roles',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
return UserRoles;
|
||||
};
|
||||
|
||||
21
modules/entities/entities_types.model.js
Normal file
21
modules/entities/entities_types.model.js
Normal file
@ -0,0 +1,21 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const EntityEntitiesTypes = sequelize.define('EntityEntitiesTypes', {
|
||||
entityId: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
typeId: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
||||
tableName: 'entities_entities_types',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
|
||||
return EntityEntitiesTypes;
|
||||
};
|
||||
28
modules/entities/entity.model.js
Normal file
28
modules/entities/entity.model.js
Normal file
@ -0,0 +1,28 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const Entity = sequelize.define('Entity', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
}, {
|
||||
tableName: 'entities',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
Entity.associate = function (models) {
|
||||
Entity.EntityTypes = Entity.belongsToMany(models.EntityType, {
|
||||
through: models.EntityEntitiesTypes,
|
||||
foreignKey: 'entityId'
|
||||
});
|
||||
Entity.Users = Entity.hasMany(models.User, {
|
||||
foreignKey: 'entityId'
|
||||
});
|
||||
};
|
||||
return Entity;
|
||||
};
|
||||
29
modules/entities/entity_type.model.js
Normal file
29
modules/entities/entity_type.model.js
Normal file
@ -0,0 +1,29 @@
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const EntityType = sequelize.define('EntityType', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
}, {
|
||||
tableName: 'entities_types',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
EntityType.associate = function (models) {
|
||||
EntityType.Entities = EntityType.belongsToMany(models.Entity, {
|
||||
through: models.EntityEntitiesTypes,
|
||||
foreignKey: 'typeId'
|
||||
});
|
||||
//Post.Comments = Post.hasMany(models.Comment, { foreignKey: 'postId' });
|
||||
//Post.Reactions = Post.hasMany(models.PostReaction, { foreignKey: 'postId' });
|
||||
//Post.User = Post.belongsTo(models.User, { foreignKey: 'userId' });
|
||||
};
|
||||
|
||||
return EntityType;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user