Add Falukant region and transport management features
- Implemented new endpoints in AdminController for managing Falukant regions, including fetching, updating, and deleting region distances. - Enhanced the FalukantService with methods for retrieving region distances and handling upsert operations. - Updated the router to expose new routes for region management and transport creation. - Introduced a transport management interface in the frontend, allowing users to create and manage transports between branches. - Added localization for new transport-related terms and improved the vehicle management interface to include transport options. - Enhanced the database initialization logic to support new region and transport models.
This commit is contained in:
@@ -98,6 +98,7 @@ import UndergroundType from './falukant/type/underground.js';
|
||||
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 Blog from './community/blog.js';
|
||||
import BlogPost from './community/blog_post.js';
|
||||
import Campaign from './match3/campaign.js';
|
||||
@@ -453,6 +454,24 @@ export default function setupAssociations() {
|
||||
as: 'region',
|
||||
});
|
||||
|
||||
// Region distances
|
||||
RegionData.hasMany(RegionDistance, {
|
||||
foreignKey: 'sourceRegionId',
|
||||
as: 'distancesFrom',
|
||||
});
|
||||
RegionData.hasMany(RegionDistance, {
|
||||
foreignKey: 'targetRegionId',
|
||||
as: 'distancesTo',
|
||||
});
|
||||
RegionDistance.belongsTo(RegionData, {
|
||||
foreignKey: 'sourceRegionId',
|
||||
as: 'sourceRegion',
|
||||
});
|
||||
RegionDistance.belongsTo(RegionData, {
|
||||
foreignKey: 'targetRegionId',
|
||||
as: 'targetRegion',
|
||||
});
|
||||
|
||||
Transport.belongsTo(RegionData, {
|
||||
foreignKey: 'sourceRegionId',
|
||||
as: 'sourceRegion',
|
||||
|
||||
51
backend/models/falukant/data/region_distance.js
Normal file
51
backend/models/falukant/data/region_distance.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import RegionData from './region.js';
|
||||
|
||||
class RegionDistance extends Model {}
|
||||
|
||||
RegionDistance.init(
|
||||
{
|
||||
sourceRegionId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: RegionData,
|
||||
key: 'id',
|
||||
schema: 'falukant_data',
|
||||
},
|
||||
},
|
||||
targetRegionId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: RegionData,
|
||||
key: 'id',
|
||||
schema: 'falukant_data',
|
||||
},
|
||||
},
|
||||
transportMode: {
|
||||
// e.g. 'land', 'water', 'air' – should match VehicleType.transportMode
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
distance: {
|
||||
// distance between regions (e.g. in abstract units, used for travel time etc.)
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'RegionDistance',
|
||||
tableName: 'region_distance',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
}
|
||||
);
|
||||
|
||||
export default RegionDistance;
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,18 @@ Vehicle.init(
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
condition: {
|
||||
// current condition of the vehicle (0–100)
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 100,
|
||||
},
|
||||
availableFrom: {
|
||||
// timestamp when the vehicle becomes available for use
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
|
||||
@@ -8,13 +8,19 @@ VehicleType.init(
|
||||
tr: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
unique: true,
|
||||
},
|
||||
cost: {
|
||||
// base purchase cost of the vehicle
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
buildTimeMinutes: {
|
||||
// time to construct the vehicle, in minutes
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
capacity: {
|
||||
// transport capacity (e.g. in units of goods)
|
||||
type: DataTypes.INTEGER,
|
||||
|
||||
@@ -116,6 +116,7 @@ import Underground from './falukant/data/underground.js';
|
||||
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 Room from './chat/room.js';
|
||||
import ChatUser from './chat/user.js';
|
||||
@@ -210,6 +211,7 @@ const models = {
|
||||
Credit,
|
||||
DebtorsPrism,
|
||||
HealthActivity,
|
||||
RegionDistance,
|
||||
VehicleType,
|
||||
Vehicle,
|
||||
Transport,
|
||||
|
||||
Reference in New Issue
Block a user