Add vehicle management features in Falukant

- Introduced vehicle types and transport management in the backend, including new models and associations for vehicles and transports.
- Implemented service methods to retrieve vehicle types and handle vehicle purchases, ensuring user validation and transaction management.
- Updated the FalukantController and router to expose new endpoints for fetching vehicle types and buying vehicles.
- Enhanced the frontend with a new transport tab in BranchView, allowing users to buy vehicles, and added localization for vehicle-related terms.
- Included initialization logic for vehicle types in the database setup.
This commit is contained in:
Torsten Schulz (local)
2025-11-24 20:15:45 +01:00
parent 5ed27e5a6a
commit 3f043fc315
14 changed files with 544 additions and 12 deletions

View File

@@ -0,0 +1,41 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class Transport extends Model {}
Transport.init(
{
sourceRegionId: {
type: DataTypes.INTEGER,
allowNull: false,
},
targetRegionId: {
type: DataTypes.INTEGER,
allowNull: false,
},
productId: {
type: DataTypes.INTEGER,
allowNull: false,
},
size: {
type: DataTypes.INTEGER,
allowNull: false,
},
vehicleId: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
sequelize,
modelName: 'Transport',
tableName: 'transport',
schema: 'falukant_data',
timestamps: true,
underscored: true,
}
);
export default Transport;

View File

@@ -0,0 +1,33 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class Vehicle extends Model {}
Vehicle.init(
{
vehicleTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
},
falukantUserId: {
type: DataTypes.INTEGER,
allowNull: false,
},
regionId: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
sequelize,
modelName: 'Vehicle',
tableName: 'vehicle',
schema: 'falukant_data',
timestamps: true,
underscored: true,
}
);
export default Vehicle;

View File

@@ -0,0 +1,46 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class VehicleType extends Model {}
VehicleType.init(
{
tr: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
cost: {
// base purchase cost of the vehicle
type: DataTypes.INTEGER,
allowNull: false,
},
capacity: {
// transport capacity (e.g. in units of goods)
type: DataTypes.INTEGER,
allowNull: false,
},
transportMode: {
// e.g. 'land', 'water', 'air'
type: DataTypes.STRING,
allowNull: false,
},
speed: {
// abstract speed value, higher = faster
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
sequelize,
modelName: 'VehicleType',
tableName: 'vehicle',
schema: 'falukant_type',
timestamps: false,
underscored: true,
}
);
export default VehicleType;