diff --git a/modules/auth/rol.model.js b/modules/auth/rol.model.js new file mode 100644 index 0000000..defdf3f --- /dev/null +++ b/modules/auth/rol.model.js @@ -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; +}; + \ No newline at end of file diff --git a/modules/auth/user.model.js b/modules/auth/user.model.js index 04bbee7..5729347 100644 --- a/modules/auth/user.model.js +++ b/modules/auth/user.model.js @@ -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' }); }; diff --git a/modules/auth/user_device.model.js b/modules/auth/user_device.model.js new file mode 100644 index 0000000..4f9b3df --- /dev/null +++ b/modules/auth/user_device.model.js @@ -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; +}; + \ No newline at end of file diff --git a/modules/auth/users_roles.model.js b/modules/auth/users_roles.model.js new file mode 100644 index 0000000..cbba1b9 --- /dev/null +++ b/modules/auth/users_roles.model.js @@ -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; +}; + \ No newline at end of file diff --git a/modules/entities/entities_types.model.js b/modules/entities/entities_types.model.js new file mode 100644 index 0000000..afa3388 --- /dev/null +++ b/modules/entities/entities_types.model.js @@ -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; +}; \ No newline at end of file diff --git a/modules/entities/entity.model.js b/modules/entities/entity.model.js new file mode 100644 index 0000000..57422ac --- /dev/null +++ b/modules/entities/entity.model.js @@ -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; +}; \ No newline at end of file diff --git a/modules/entities/entity_type.model.js b/modules/entities/entity_type.model.js new file mode 100644 index 0000000..39a4e76 --- /dev/null +++ b/modules/entities/entity_type.model.js @@ -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; +}; \ No newline at end of file