// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table’s columns.
// Learn more here: Enrich your models - Developer Guide
const ChargePoints = sequelize.define(‘chargePoints’, {
externalId: {
type: DataTypes.STRING,
field: ‘external_id’,
},
state: {
type: DataTypes.ENUM(‘disconnected’,‘available’,‘busy’, ‘error’, ‘passive’),
defaultValue: “disconnected”,
allowNull: false,
},
name: {
type: DataTypes.STRING,
},
operatorName: {
type: DataTypes.STRING,
field: ‘operator_name’,
},
identifier: {
type: DataTypes.STRING,
allowNull: false,
},
roaming: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
field: ‘roaming’,
},
address1: {
type: DataTypes.STRING,
},
address2: {
type: DataTypes.STRING,
},
address3: {
type: DataTypes.STRING,
},
city: {
type: DataTypes.STRING,
},
zip: {
type: DataTypes.STRING,
},
parkingSpot: {
type: DataTypes.STRING,
field: ‘parking_spot’,
},
note: {
type: DataTypes.STRING,
},
visibility: {
type: DataTypes.ENUM(‘public’,‘private’),
allowNull: false,
},
type: {
type: DataTypes.ENUM(‘ac’,‘dc’),
},
maxKw: {
type: DataTypes.DOUBLE,
field: ‘max_kw’,
},
kwhCostType: {
type: DataTypes.ENUM(‘fixed’,‘spot’),
field: ‘kwh_cost_type’,
defaultValue: “fixed”,
allowNull: false,
},
kwhCostFixedPrice: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_fixed_price’,
},
kwhCostSpotOverheadPercentage: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_spot_overhead_percentage’,
},
kwhCostSpotOverheadValue: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_spot_overhead_value’,
},
kwhSalesType: {
type: DataTypes.ENUM(‘fixed’,‘spot’),
field: ‘kwh_sales_type’,
defaultValue: “fixed”,
allowNull: false,
},
kwhSalesFixedPrice: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_fixed_price’,
},
kwhSalesSpotOverheadPercentage: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_spot_overhead_percentage’,
},
kwhSalesSpotOverheadValue: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_spot_overhead_value’,
},
hasCable: {
type: DataTypes.INTEGER,
field: ‘has_cable’,
},
hasAuthTokens: {
type: DataTypes.INTEGER,
field: ‘has_auth_tokens’,
defaultValue: 0,
allowNull: false,
},
chargePointModelCustom: {
type: DataTypes.STRING,
field: ‘charge_point_model_custom’,
},
smartChargeSetting: {
type: DataTypes.ENUM(‘off’,‘optional’,‘forced’,‘forced-setting’),
field: ‘smart_charge_setting’,
allowNull: false,
},
smartChargePriorityPrice: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_price’,
defaultValue: 0,
allowNull: false,
},
smartChargePriorityCo2: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_co2’,
defaultValue: 0,
allowNull: false,
},
smartChargePriorityRenewable: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_renewable’,
defaultValue: 0,
allowNull: false,
},
activeAt: {
type: DataTypes.DATE,
field: ‘active_at’,
},
chatActiveAt: {
type: DataTypes.DATE,
field: ‘chat_active_at’,
},
autoMovedToGroup: {
type: DataTypes.INTEGER,
field: ‘auto_moved_to_group’,
defaultValue: 0,
allowNull: false,
},
autoStart: {
type: DataTypes.ENUM(‘off’,‘instant-start’,‘instant-schedule’,‘request-start’,‘request-schedule’),
field: ‘auto_start’,
defaultValue: “off”,
allowNull: false,
},
lastActiveAt: {
type: DataTypes.DATE,
field: ‘last_active_at’,
},
integrationActiveAt: {
type: DataTypes.DATE,
field: ‘integration_active_at’,
},
chargingStartedAt: {
type: DataTypes.DATE,
field: ‘charging_started_at’,
},
integrationCount: {
type: DataTypes.INTEGER,
field: ‘integration_count’,
defaultValue: 0,
allowNull: false,
},
staticMapPath: {
type: DataTypes.STRING,
field: ‘static_map_path’,
},
staticMapPathUpdatedAt: {
type: DataTypes.DATE,
field: ‘static_map_path_updated_at’,
},
nextScheduleAt: {
type: DataTypes.DATE,
field: ‘next_schedule_at’,
},
timezone: {
type: DataTypes.STRING,
},
operatorCutPercentage: {
type: DataTypes.DOUBLE,
field: ‘operator_cut_percentage’,
defaultValue: Sequelize.literal(‘0.0000’),
allowNull: false,
},
operatorCutAbsolute: {
type: DataTypes.DOUBLE,
field: ‘operator_cut_absolute’,
allowNull: false,
},
log: {
type: DataTypes.JSON,
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
field: ‘created_at’,
},
updatedAt: {
type: DataTypes.DATE,
field: ‘updated_at’,
},
deletedAt: {
type: DataTypes.DATE,
field: ‘deleted_at’,
},
location: {
type: DataTypes.BLOB,
field: ‘location’,
},
maxReservationMin: {
type: DataTypes.INTEGER,
field: ‘max_reservation_min’,
allowNull: true,
defaultValue: null,
},
}, {
tableName: ‘charge_points’,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
ChargePoints.associate = (models) => {
ChargePoints.belongsTo(models.chargePointGroups, {
foreignKey: {
name: ‘chargePointGroupIdKey’,
field: ‘charge_point_group_id’,
},
as: ‘chargePointGroup’,
});
ChargePoints.belongsTo(models.serverChargePointModels, {
foreignKey: {
name: ‘chargePointModelIdKey’,
field: ‘charge_point_model_id’,
},
as: ‘chargePointModel’,
});
ChargePoints.belongsTo(models.countryAreas, {
foreignKey: {
name: ‘countryAreaIdKey’,
field: ‘country_area_id’,
},
as: ‘countryArea’,
});
ChargePoints.belongsTo(models.countries, {
foreignKey: {
name: ‘countryIdKey’,
field: ‘country_id’,
},
as: ‘country’,
});
ChargePoints.belongsTo(models.currencies, {
foreignKey: {
name: ‘currencyIdKey’,
field: ‘currency_id’,
},
as: ‘currency’,
});
ChargePoints.belongsTo(models.operators, {
foreignKey: {
name: ‘operatorIdKey’,
field: ‘operator_id’,
},
as: ‘operator’,
});
ChargePoints.belongsTo(models.teams, {
foreignKey: {
name: ‘teamIdKey’,
field: ‘team_id’,
},
as: ‘team’,
});
ChargePoints.belongsTo(models.users, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘user’,
});
ChargePoints.belongsToMany(models.connectors, {
through: ‘chargePointConnector’,
foreignKey: ‘charge_point_id’,
otherKey: ‘connector_id’,
as: ‘connectorsThroughChargePointConnectors’,
});
ChargePoints.belongsToMany(models.users, {
through: ‘sponsoredChargePointUser’,
foreignKey: ‘sponsored_charge_point_id’,
otherKey: ‘user_id’,
as: ‘usersThroughSponsoredChargePointUsers’,
});
ChargePoints.hasMany(models.chargePointAssets, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointAssets’,
});
ChargePoints.hasMany(models.chargePointIntegration, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointIntegrations’,
});
ChargePoints.hasMany(models.chargePointReadings, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointReadings’,
});
ChargePoints.hasMany(models.chargePointSchedules, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointSchedules’,
});
ChargePoints.hasMany(models.charges, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointCharges’,
});
ChargePoints.hasMany(models.hubjectOperators, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointHubjectOperators’,
});
ChargePoints.hasMany(models.notificationEventUser, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘userNotificationEventUsers’,
});
ChargePoints.hasMany(models.notifications, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘userNotifications’,
});
ChargePoints.hasMany(models.sponsoredChargePoints, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointSponsoredChargePoints’,
});
};
return ChargePoints;
};