Director hiring added
This commit is contained in:
@@ -44,8 +44,10 @@ 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';
|
||||
|
||||
import BuyableStock from './falukant/data/buyable_stock.js';
|
||||
import MoneyFlow from './falukant/log/moneyflow.js';
|
||||
import Director from './falukant/data/director.js';
|
||||
import DirectorProposal from './falukant/data/director_proposal.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
// UserParam related associations
|
||||
@@ -251,4 +253,21 @@ export default function setupAssociations() {
|
||||
Branch.hasMany(FalukantStock, { foreignKey: 'branchId', as: 'stocks' });
|
||||
FalukantStock.belongsTo(Branch, { foreignKey: 'branchId', as: 'branch' });
|
||||
|
||||
MoneyFlow.belongsTo(FalukantUser, { foreignKey: 'falukantUserId', as: 'user' });
|
||||
FalukantUser.hasMany(MoneyFlow, { foreignKey: 'falukantUserId', as: 'flows' });
|
||||
|
||||
BuyableStock.belongsTo(FalukantStockType, { foreignKey: 'stockTypeId', as: 'stockType' });
|
||||
FalukantStockType.hasMany(BuyableStock, { foreignKey: 'stockTypeId', as: 'buyableStocks' });
|
||||
|
||||
Director.belongsTo(FalukantUser, { foreignKey: 'employerUserId', as: 'user' });
|
||||
FalukantUser.hasMany(Director, { foreignKey: 'employerUserId', as: 'directors' });
|
||||
|
||||
Director.belongsTo(FalukantCharacter, { foreignKey: 'directorCharacterId', as: 'character' });
|
||||
FalukantCharacter.hasMany(Director, { foreignKey: 'directorCharacterId', as: 'directors' });
|
||||
|
||||
DirectorProposal.belongsTo(FalukantUser, { foreignKey: 'employerUserId', as: 'user' });
|
||||
FalukantUser.hasMany(DirectorProposal, { foreignKey: 'employerUserId', as: 'directorProposals' });
|
||||
|
||||
DirectorProposal.belongsTo(FalukantCharacter, { foreignKey: 'directorCharacterId', as: 'character' });
|
||||
FalukantCharacter.hasMany(DirectorProposal, { foreignKey: 'directorCharacterId', as: 'directorProposals' });
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Branch.init({
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'BranchType',
|
||||
modelName: 'Branch',
|
||||
tableName: 'branch',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
|
||||
48
backend/models/falukant/data/director.js
Normal file
48
backend/models/falukant/data/director.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class Director extends Model { }
|
||||
|
||||
Director.init({
|
||||
directorCharacterId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
employerUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
income: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
satisfaction: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 100,
|
||||
},
|
||||
mayProduce: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
maySell: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
mayStartTransport: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Director',
|
||||
tableName: 'director',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default Director;
|
||||
28
backend/models/falukant/data/director_proposal.js
Normal file
28
backend/models/falukant/data/director_proposal.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class DirectorProposal extends Model { }
|
||||
|
||||
DirectorProposal.init({
|
||||
directorCharacterId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
employerUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
proposedIncome: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'DirectorProposal',
|
||||
tableName: 'director_proposal',
|
||||
schema: 'falukant_data',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default DirectorProposal;
|
||||
@@ -19,7 +19,7 @@ FalukantStock.init({
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'StockType',
|
||||
modelName: 'StockData',
|
||||
tableName: 'stock',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
|
||||
45
backend/models/falukant/log/moneyflow.js
Normal file
45
backend/models/falukant/log/moneyflow.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class MoneyFlow extends Model { }
|
||||
|
||||
MoneyFlow.init({
|
||||
falukantUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
activity: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
moneyBefore: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: false,
|
||||
},
|
||||
moneyAfter: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: true,
|
||||
},
|
||||
time: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
changeValue: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: false,
|
||||
},
|
||||
changedBy: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'MoneyFlow',
|
||||
tableName: 'moneyflow',
|
||||
schema: 'falukant_log',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default MoneyFlow;
|
||||
@@ -48,7 +48,10 @@ 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';
|
||||
import BuyableStock from './falukant/data/buyable_stock.js';
|
||||
import MoneyFlow from './falukant/log/moneyflow.js';
|
||||
import Director from './falukant/data/director.js';
|
||||
import DirectorProposal from './falukant/data/director_proposal.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
@@ -102,6 +105,9 @@ const models = {
|
||||
Production,
|
||||
Inventory,
|
||||
BuyableStock,
|
||||
MoneyFlow,
|
||||
Director,
|
||||
DirectorProposal,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
@@ -124,6 +124,62 @@ export async function createTriggers() {
|
||||
EXECUTE FUNCTION falukant_data.create_knowledge_trigger();
|
||||
`;
|
||||
|
||||
const updateMoney = `
|
||||
CREATE OR REPLACE FUNCTION falukant_data.update_money(
|
||||
p_falukant_user_id integer,
|
||||
p_money_change numeric,
|
||||
p_activity text,
|
||||
p_changed_by integer DEFAULT NULL
|
||||
)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
v_money_before numeric(10,2);
|
||||
v_money_after numeric(10,2);
|
||||
v_moneyflow_id bigint;
|
||||
BEGIN
|
||||
SELECT money
|
||||
INTO v_money_before
|
||||
FROM falukant_data.falukant_user
|
||||
WHERE id = p_falukant_user_id;
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'FalukantUser mit ID % nicht gefunden', p_falukant_user_id;
|
||||
END IF;
|
||||
v_money_after := v_money_before + p_money_change;
|
||||
INSERT INTO falukant_log.moneyflow (
|
||||
falukant_user_id,
|
||||
activity,
|
||||
money_before,
|
||||
money_after,
|
||||
change_value,
|
||||
changed_by,
|
||||
time
|
||||
)
|
||||
VALUES (
|
||||
p_falukant_user_id,
|
||||
p_activity,
|
||||
v_money_before,
|
||||
NULL, -- Wird gleich aktualisiert
|
||||
p_money_change,
|
||||
p_changed_by,
|
||||
NOW()
|
||||
)
|
||||
RETURNING id INTO v_moneyflow_id;
|
||||
UPDATE falukant_data.falukant_user
|
||||
SET money = v_money_after
|
||||
WHERE id = p_falukant_user_id;
|
||||
UPDATE falukant_log.moneyflow
|
||||
SET money_after = (
|
||||
SELECT money
|
||||
FROM falukant_data.falukant_user
|
||||
WHERE id = p_falukant_user_id
|
||||
)
|
||||
WHERE id = v_moneyflow_id;
|
||||
END;
|
||||
$function$;
|
||||
`;
|
||||
|
||||
try {
|
||||
await sequelize.query(createTriggerFunction);
|
||||
await sequelize.query(createInsertTrigger);
|
||||
@@ -136,6 +192,7 @@ export async function createTriggers() {
|
||||
await sequelize.query(createCharacterCreationTrigger);
|
||||
await sequelize.query(createKnowledgeTriggerMethod);
|
||||
await sequelize.query(createKnowledgeTrigger);
|
||||
await sequelize.query(updateMoney);
|
||||
|
||||
console.log('Triggers created successfully');
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user