summaryrefslogblamecommitdiffstats
path: root/server/models/backend.js
blob: 2a039e68e4156889e2f7d2c59722cf813cae44b0 (plain) (tree)
1
2
3
4
5
6
7
8
            


                                             



                             


                           




                                   
                 



                                   
                  






                                   

                     

                                         


                                                               
                                                                    




                                                               
                                                                    

                                                    


                                                                                                                                         

                                                                                      


                
'use strict'
module.exports = (sequelize, DataTypes) => {
  var backend = sequelize.define('backend', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: DataTypes.INTEGER
    },
    name: DataTypes.STRING,
    type: DataTypes.STRING,
    credentials: {
      allowNull: false,
      type: DataTypes.STRING(2048),
      defaultValue: '[]'
    },
    groupTypes: {
      allowNull: false,
      type: DataTypes.STRING(4096),
      defaultValue: '[]'
    },
    clientTypes: {
      allowNull: false,
      type: DataTypes.STRING(4096),
      defaultValue: '[]'
    },
    sync: {
      type: DataTypes.STRING(1024)
    }
  }, {
    timestamps: false
  })
  backend.associate = function (models) {
    var BackendXGroup = sequelize.define('backend_x_group', {
      backendId: { type: DataTypes.INTEGER, primaryKey: true },
      groupId: { type: DataTypes.INTEGER, primaryKey: false },
      externalId: { type: DataTypes.STRING(128), primaryKey: true },
      externalType: DataTypes.STRING
    }, { timestamps: false, freezeTableName: true })
    var BackendXClient = sequelize.define('backend_x_client', {
      backendId: { type: DataTypes.INTEGER, primaryKey: true },
      clientId: { type: DataTypes.INTEGER, primaryKey: false },
      externalId: { type: DataTypes.STRING(128), primaryKey: true },
      externalType: DataTypes.STRING
    }, { timestamps: false, freezeTableName: true })

    backend.belongsToMany(models.group, { as: 'mappedGroups', through: BackendXGroup, foreignKey: 'backendId', otherKey: 'groupId' })
    backend.belongsToMany(models.client, { as: 'mappedClients', through: BackendXClient, foreignKey: 'backendId', otherKey: 'clientId' })
    backend.hasMany(BackendXGroup, { as: 'groupMappings', foreignKey: 'backendId' })
    backend.hasMany(BackendXClient, { as: 'clientMappings', foreignKey: 'backendId' })
  }
  return backend
}