Add product weather effects and regional pricing enhancements
- Introduced a new endpoint in FalukantController to retrieve product prices based on region and product ID. - Implemented logic in FalukantService to calculate product prices considering user knowledge and regional factors. - Added weather-related data models and associations to enhance product pricing accuracy based on weather conditions. - Updated frontend components to cache and display regional product prices effectively, improving user experience.
This commit is contained in:
@@ -99,6 +99,9 @@ import VehicleType from './falukant/type/vehicle.js';
|
||||
import Vehicle from './falukant/data/vehicle.js';
|
||||
import Transport from './falukant/data/transport.js';
|
||||
import RegionDistance from './falukant/data/region_distance.js';
|
||||
import WeatherType from './falukant/type/weather.js';
|
||||
import Weather from './falukant/data/weather.js';
|
||||
import ProductWeatherEffect from './falukant/type/product_weather_effect.js';
|
||||
import Blog from './community/blog.js';
|
||||
import BlogPost from './community/blog_post.js';
|
||||
import Campaign from './match3/campaign.js';
|
||||
@@ -288,6 +291,21 @@ export default function setupAssociations() {
|
||||
RegionData.belongsTo(RegionType, { foreignKey: 'regionTypeId', as: 'regionType' });
|
||||
RegionType.hasMany(RegionData, { foreignKey: 'regionTypeId', as: 'regions' });
|
||||
|
||||
Weather.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' });
|
||||
RegionData.hasOne(Weather, { foreignKey: 'regionId', as: 'weather' });
|
||||
|
||||
Weather.belongsTo(WeatherType, { foreignKey: 'weatherTypeId', as: 'weatherType' });
|
||||
WeatherType.hasMany(Weather, { foreignKey: 'weatherTypeId', as: 'weathers' });
|
||||
|
||||
ProductWeatherEffect.belongsTo(ProductType, { foreignKey: 'productId', as: 'product' });
|
||||
ProductType.hasMany(ProductWeatherEffect, { foreignKey: 'productId', as: 'weatherEffects' });
|
||||
|
||||
ProductWeatherEffect.belongsTo(WeatherType, { foreignKey: 'weatherTypeId', as: 'weatherType' });
|
||||
WeatherType.hasMany(ProductWeatherEffect, { foreignKey: 'weatherTypeId', as: 'productEffects' });
|
||||
|
||||
Production.belongsTo(WeatherType, { foreignKey: 'weatherTypeId', as: 'weatherType' });
|
||||
WeatherType.hasMany(Production, { foreignKey: 'weatherTypeId', as: 'productions' });
|
||||
|
||||
FalukantUser.belongsTo(RegionData, { foreignKey: 'mainBranchRegionId', as: 'mainBranchRegion' });
|
||||
RegionData.hasMany(FalukantUser, { foreignKey: 'mainBranchRegionId', as: 'users' });
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import WeatherType from '../type/weather.js';
|
||||
|
||||
class Production extends Model { }
|
||||
|
||||
@@ -13,6 +14,16 @@ Production.init({
|
||||
quantity: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false},
|
||||
weatherTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: WeatherType,
|
||||
key: 'id',
|
||||
schema: 'falukant_type'
|
||||
},
|
||||
comment: 'Wetter zum Zeitpunkt der Produktionserstellung'
|
||||
},
|
||||
startTimestamp: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
|
||||
40
backend/models/falukant/data/weather.js
Normal file
40
backend/models/falukant/data/weather.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import RegionData from './region.js';
|
||||
import WeatherType from '../type/weather.js';
|
||||
|
||||
class Weather extends Model {}
|
||||
|
||||
Weather.init(
|
||||
{
|
||||
regionId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: RegionData,
|
||||
key: 'id',
|
||||
schema: 'falukant_data'
|
||||
},
|
||||
unique: true // Jede Stadt hat nur ein Wetter
|
||||
},
|
||||
weatherTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: WeatherType,
|
||||
key: 'id',
|
||||
schema: 'falukant_type'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Weather',
|
||||
tableName: 'weather',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
underscored: true}
|
||||
);
|
||||
|
||||
export default Weather;
|
||||
|
||||
51
backend/models/falukant/type/product_weather_effect.js
Normal file
51
backend/models/falukant/type/product_weather_effect.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import ProductType from './product.js';
|
||||
import WeatherType from './weather.js';
|
||||
|
||||
class ProductWeatherEffect extends Model {}
|
||||
|
||||
ProductWeatherEffect.init(
|
||||
{
|
||||
productId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: ProductType,
|
||||
key: 'id',
|
||||
schema: 'falukant_type'
|
||||
}
|
||||
},
|
||||
weatherTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: WeatherType,
|
||||
key: 'id',
|
||||
schema: 'falukant_type'
|
||||
}
|
||||
},
|
||||
qualityEffect: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: 'Effekt auf Qualität: -2 (sehr negativ), -1 (negativ), 0 (neutral), 1 (positiv), 2 (sehr positiv)'
|
||||
}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'ProductWeatherEffect',
|
||||
tableName: 'product_weather_effect',
|
||||
schema: 'falukant_type',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['product_id', 'weather_type_id']
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
export default ProductWeatherEffect;
|
||||
|
||||
25
backend/models/falukant/type/weather.js
Normal file
25
backend/models/falukant/type/weather.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class WeatherType extends Model {}
|
||||
|
||||
WeatherType.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true},
|
||||
tr: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false}},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'WeatherType',
|
||||
tableName: 'weather',
|
||||
schema: 'falukant_type',
|
||||
timestamps: false,
|
||||
underscored: true}
|
||||
);
|
||||
|
||||
export default WeatherType;
|
||||
|
||||
@@ -117,6 +117,9 @@ import VehicleType from './falukant/type/vehicle.js';
|
||||
import Vehicle from './falukant/data/vehicle.js';
|
||||
import Transport from './falukant/data/transport.js';
|
||||
import RegionDistance from './falukant/data/region_distance.js';
|
||||
import WeatherType from './falukant/type/weather.js';
|
||||
import Weather from './falukant/data/weather.js';
|
||||
import ProductWeatherEffect from './falukant/type/product_weather_effect.js';
|
||||
|
||||
import Room from './chat/room.js';
|
||||
import ChatUser from './chat/user.js';
|
||||
@@ -228,6 +231,9 @@ const models = {
|
||||
ElectionHistory,
|
||||
UndergroundType,
|
||||
Underground,
|
||||
WeatherType,
|
||||
Weather,
|
||||
ProductWeatherEffect,
|
||||
Room,
|
||||
ChatUser,
|
||||
ChatRight,
|
||||
|
||||
Reference in New Issue
Block a user