Füge neue Modelle für Produktion, Inventar und kaufbare Bestände hinzu; aktualisiere bestehende Modelle und Routen

This commit is contained in:
Torsten Schulz
2024-12-23 10:37:43 +01:00
parent 1bb2bd49d5
commit 6f7d97672e
15 changed files with 1143 additions and 44 deletions

View File

@@ -42,6 +42,9 @@ import TitleOfNobility from './falukant/type/title_of_nobility.js';
import TitleRequirement from './falukant/type/title_requirement.js';
import Branch from './falukant/data/branch.js';
import BranchType from './falukant/type/branch.js';
import Production from './falukant/data/production.js';
import Inventory from './falukant/data/inventory.js';
import BuyableStock from './falukant/data/buayble_stock.js';
export default function setupAssociations() {
@@ -205,21 +208,15 @@ export default function setupAssociations() {
FalukantCharacter.belongsTo(TitleOfNobility, { foreignKey: 'titleOfNobility', as: 'nobleTitle' });
TitleOfNobility.hasMany(FalukantCharacter, { foreignKey: 'titleOfNobility', as: 'charactersWithNobleTitle' });
FalukantCharacter.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' });
RegionData.hasMany(FalukantCharacter, { foreignKey: 'regionId', as: 'charactersInRegion' });
FalukantStock.belongsTo(FalukantStockType, { foreignKey: 'stockTypeId', as: 'stockType' });
FalukantStockType.hasMany(FalukantStock, { foreignKey: 'stockTypeId', as: 'stocks' });
FalukantStock.belongsTo(FalukantUser, { foreignKey: 'userId', as: 'user' });
FalukantUser.hasMany(FalukantStock, { foreignKey: 'userId', as: 'stocks' });
FalukantStock.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' });
RegionData.hasMany(FalukantStock, { foreignKey: 'regionId', as: 'stocksInRegion' });
Knowledge.belongsTo(ProductType, { foreignKey: 'productTypeId', as: 'productType' });
ProductType.hasMany(Knowledge, { foreignKey: 'productTypeId', as: 'knowledges' });
Knowledge.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' });
ProductType.hasMany(Knowledge, { foreignKey: 'productId', as: 'knowledges' });
Knowledge.belongsTo(FalukantCharacter, { foreignKey: 'characterId', as: 'character' });
FalukantCharacter.hasMany(Knowledge, { foreignKey: 'characterId', as: 'knowledges' });
@@ -235,4 +232,23 @@ export default function setupAssociations() {
Branch.belongsTo(BranchType, { foreignKey: 'branchTypeId', as: 'branchType' });
BranchType.hasMany(Branch, { foreignKey: 'branchTypeId', as: 'branches' });
Production.belongsTo(Branch, { foreignKey: 'branchId', as: 'branch' });
Branch.hasMany(Production, { foreignKey: 'branchId', as: 'productions' });
Production.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' });
ProductType.hasMany(Production, { foreignKey: 'productId', as: 'productions' });
Inventory.belongsTo(FalukantStock, { foreignKey: 'stockId', as: 'stock' });
FalukantStock.hasMany(Inventory, { foreignKey: 'stockId', as: 'inventories' });
Inventory.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' });
ProductType.hasMany(Inventory, { foreignKey: 'productId', as: 'inventories' });
BuyableStock.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' });
RegionData.hasMany(BuyableStock, { foreignKey: 'regionId', as: 'buyableStocks' });
Branch.hasMany(FalukantStock, { foreignKey: 'branchId', as: 'stocks' });
FalukantStock.belongsTo(Branch, { foreignKey: 'branchId', as: 'branch' });
}

View File

@@ -0,0 +1,28 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class BuyableStock extends Model { }
BuyableStock.init({
regionId: {
type: DataTypes.INTEGER,
allowNull: false,
},
stockTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
},
}, {
sequelize,
modelName: 'BuyableStock',
tableName: 'buyable_stock',
schema: 'falukant_data',
timestamps: false,
underscored: true,
});
export default BuyableStock;

View File

@@ -0,0 +1,37 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class Inventory extends Model { }
Inventory.init({
stockId: {
type: DataTypes.INTEGER,
allowNull: false,
},
productId: {
type: DataTypes.INTEGER,
allowNull: false,
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
},
quality: {
type: DataTypes.INTEGER,
allowNull: false,
},
producedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
}
}, {
sequelize,
modelName: 'Inventory',
tableName: 'inventory',
schema: 'falukant_data',
timestamps: false,
underscored: true,
});
export default Inventory;

View File

@@ -0,0 +1,33 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class Production extends Model { }
Production.init({
branchId: {
type: DataTypes.INTEGER,
allowNull: false,
},
productId: {
type: DataTypes.INTEGER,
allowNull: false,
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
},
startTimestamp: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
}
}, {
sequelize,
modelName: 'Production',
tableName: 'production',
schema: 'falukant_data',
timestamps: false,
underscored: true,
});
export default Production;

View File

@@ -4,13 +4,10 @@ import { sequelize } from '../../../utils/sequelize.js';
class FalukantStock extends Model { }
FalukantStock.init({
userId: {
type: DataTypes.INTEGER,
allowNull: false,
},
regionId: {
branchId: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
stockTypeId: {
type: DataTypes.INTEGER,

View File

@@ -37,6 +37,11 @@ FalukantUser.init({
allowNull: false,
defaultValue: 0.00,
},
certificate: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
mainBranchRegionId: {
type: DataTypes.INTEGER,
allowNull: true,

View File

@@ -46,6 +46,9 @@ import TitleRequirement from './falukant/type/title_requirement.js';
import TitleOfNobility from './falukant/type/title_of_nobility.js';
import BranchType from './falukant/type/branch.js';
import Branch from './falukant/data/branch.js';
import Production from './falukant/data/production.js';
import Inventory from './falukant/data/inventory.js';
import BuyableStock from './falukant/data/buayble_stock.js';
const models = {
SettingsType,
@@ -54,10 +57,10 @@ const models = {
UserRightType,
User,
UserParam,
Login,
Login,
UserRight,
InterestType,
InterestTranslationType,
InterestTranslationType,
Interest,
ContactMessage,
UserParamVisibilityType,
@@ -96,6 +99,9 @@ const models = {
TitleRequirement,
BranchType,
Branch,
Production,
Inventory,
BuyableStock,
};
export default models;