From 90b4f51dcb99af7ba2d5b689fcf12117ea21f8f3 Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Tue, 28 Jan 2025 09:55:36 +0100 Subject: [PATCH] Some extensions and fixes --- backend/controllers/falukantController.js | 26 ++ backend/models/associations.js | 56 ++++ backend/models/falukant/data/character.js | 58 ++-- .../falukant/data/falukant_character_trait.js | 27 ++ .../models/falukant/data/marriage_proposal.js | 34 +++ backend/models/falukant/data/production.js | 2 +- .../falukant/data/town_product_worth.js | 34 +++ backend/models/falukant/log/dayproduction.js | 44 +++ backend/models/falukant/log/daysell.js | 43 +++ backend/models/falukant/log/notification | 29 ++ .../promotional_gift_character_trait.js | 45 +++ .../predefine/promotional_gift_mood.js | 45 +++ .../models/falukant/type/character_trait.js | 23 ++ backend/models/falukant/type/mood.js | 23 ++ .../models/falukant/type/promotional_gift.js | 32 +++ backend/models/falukant/type/relationship.js | 23 ++ backend/models/index.js | 24 ++ backend/routers/falukantRouter.js | 2 +- backend/services/falukantService.js | 97 ++++++- .../falukant/initializeFalukantPredefines.js | 11 + .../utils/falukant/initializeFalukantTypes.js | 265 +++++++++++++++++- backend/utils/initializeFalukant.js | 7 +- backend/utils/socket.js | 1 - dump.rdb | Bin 301 -> 88 bytes frontend/public/favicon.ico | Bin 0 -> 1150 bytes frontend/src/store/index.js | 5 - frontend/src/views/falukant/BranchView.vue | 7 +- 27 files changed, 910 insertions(+), 53 deletions(-) create mode 100644 backend/models/falukant/data/falukant_character_trait.js create mode 100644 backend/models/falukant/data/marriage_proposal.js create mode 100644 backend/models/falukant/data/town_product_worth.js create mode 100644 backend/models/falukant/log/dayproduction.js create mode 100644 backend/models/falukant/log/daysell.js create mode 100644 backend/models/falukant/log/notification create mode 100644 backend/models/falukant/predefine/promotional_gift_character_trait.js create mode 100644 backend/models/falukant/predefine/promotional_gift_mood.js create mode 100644 backend/models/falukant/type/character_trait.js create mode 100644 backend/models/falukant/type/mood.js create mode 100644 backend/models/falukant/type/promotional_gift.js create mode 100644 backend/models/falukant/type/relationship.js create mode 100644 frontend/public/favicon.ico diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js index 7da6b0c..d7598a0 100644 --- a/backend/controllers/falukantController.js +++ b/backend/controllers/falukantController.js @@ -21,6 +21,7 @@ class FalukantController { this.convertProposalToDirector = this.convertProposalToDirector.bind(this); this.getDirectorForBranch = this.getDirectorForBranch.bind(this); this.setSetting = this.setSetting.bind(this); + this.getMarriageProposals = this.getMarriageProposals.bind(this); } async getUser(req, res) { @@ -30,6 +31,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -42,6 +44,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -52,6 +55,7 @@ class FalukantController { res.status(200).json({ name: result }); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -61,6 +65,7 @@ class FalukantController { res.status(200).json({ name: result }); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -71,6 +76,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -81,6 +87,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -93,6 +100,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -104,6 +112,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -115,6 +124,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -126,6 +136,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -138,6 +149,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -148,6 +160,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -159,6 +172,7 @@ class FalukantController { res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -170,6 +184,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -181,6 +196,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -195,6 +211,7 @@ class FalukantController { res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); + console.log(error); } } @@ -312,6 +329,15 @@ class FalukantController { } } + async getMarriageProposals(req, res) { + try { + const { userid: hashedUserId } = req.headers; + const result = await FalukantService.getMarriageProposals(hashedUserId); + res.status(200).json(result); + } catch (error) { + res.status(500).json({ error: error.message }); + } + } } export default FalukantController; diff --git a/backend/models/associations.js b/backend/models/associations.js index fd2fa09..81368aa 100644 --- a/backend/models/associations.js +++ b/backend/models/associations.js @@ -48,6 +48,17 @@ 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'; +import TownProductWorth from './falukant/data/town_product_worth.js'; +import DayProduction from './falukant/log/dayproduction.js'; +import DaySell from './falukant/log/daysell.js'; +import MarriageProposal from './falukant/data/marriage_proposal.js'; +import Notification from './falukant/log/notification'; +import CharacterTrait from './falukant/type/character_trait.js'; +import FalukantCharacterTrait from './falukant/data/falukant_character_trait.js'; +import Mood from './falukant/type/mood.js'; +import PromotionalGift from './falukant/type/promotional_gift.js'; +import PromotionalGiftCharacterTrait from './falukant/predefine/promotional_gift_character_trait.js'; +import PromotionalGiftMood from './falukant/predefine/promotional_gift_mood.js'; export default function setupAssociations() { // UserParam related associations @@ -270,4 +281,49 @@ export default function setupAssociations() { DirectorProposal.belongsTo(FalukantCharacter, { foreignKey: 'directorCharacterId', as: 'character' }); FalukantCharacter.hasMany(DirectorProposal, { foreignKey: 'directorCharacterId', as: 'directorProposals' }); + + TownProductWorth.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' }); + ProductType.hasMany(TownProductWorth, { foreignKey: 'productId', as: 'townProductWorths' }); + + TownProductWorth.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' }); + RegionData.hasMany(TownProductWorth, { foreignKey: 'regionId', as: 'townProductWorths' }); + + DayProduction.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' }); + ProductType.hasMany(DayProduction, { foreignKey: 'productId', as: 'dayProductions' }); + + DayProduction.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' }); + RegionData.hasMany(DayProduction, { foreignKey: 'regionId', as: 'dayProductions' }); + + DayProduction.belongsTo(FalukantUser, { foreignKey: 'producerId', as: 'user' }); + FalukantUser.hasMany(DayProduction, { foreignKey: 'producerId', as: 'dayProductions' }); + + DaySell.belongsTo(ProductType, { foreignKey: 'productId', as: 'productType' }); + ProductType.hasMany(DaySell, { foreignKey: 'productId', as: 'daySells' }); + + DaySell.belongsTo(RegionData, { foreignKey: 'regionId', as: 'region' }); + RegionData.hasMany(DaySell, { foreignKey: 'regionId', as: 'daySells' }); + + DaySell.belongsTo(FalukantUser, { foreignKey: 'sellerId', as: 'user' }); + FalukantUser.hasMany(DaySell, { foreignKey: 'sellerId', as: 'daySells' }); + + Notification.belongsTo(FalukantUser, { foreignKey: 'userId', as: 'user' }); + FalukantUser.hasMany(Notification, { foreignKey: 'userId', as: 'notifications' }); + + MarriageProposal.belongsTo(FalukantCharacter, {foreignKey: 'requesterCharacterId', as: 'requesterCharacter', }); + FalukantCharacter.hasMany(MarriageProposal, { foreignKey: 'requesterCharacterId', as: 'initiatedProposals' }); + + MarriageProposal.belongsTo(FalukantCharacter, {foreignKey: 'proposedCharacterId', as: 'proposedCharacter', }); + FalukantCharacter.hasMany(MarriageProposal, {foreignKey: 'proposedCharacterId', as: 'receivedProposals' }); + + FalukantCharacter.belongsToMany(CharacterTrait, {through: FalukantCharacterTrait, foreignKey: 'character_id', as: 'traits', }); + CharacterTrait.belongsToMany(FalukantCharacter, {through: FalukantCharacterTrait, foreignKey: 'trait_id', as: 'characters', }); + + Mood.hasMany(FalukantCharacter, {foreignKey: 'mood_id', as: 'moods'}); + FalukantCharacter.belongsTo(Mood, {foreignKey: 'mood_id', as: 'mood'}); + + PromotionalGift.belongsToMany(CharacterTrait, {through: PromotionalGiftCharacterTrait, foreignKey: 'gift_id', as: 'traits',}); + CharacterTrait.belongsToMany(PromotionalGift, {through: PromotionalGiftCharacterTrait, foreignKey: 'trait_id', as: 'gifts',}); + + PromotionalGift.belongsToMany(Mood, {through: PromotionalGiftMood, foreignKey: 'gift_id', as: 'moods',}); + Mood.belongsToMany(PromotionalGift, {through: PromotionalGiftMood, foreignKey: 'mood_id', as: 'gifts',}); } diff --git a/backend/models/falukant/data/character.js b/backend/models/falukant/data/character.js index 450199b..0778c33 100644 --- a/backend/models/falukant/data/character.js +++ b/backend/models/falukant/data/character.js @@ -1,49 +1,57 @@ import { Model, DataTypes } from 'sequelize'; import { sequelize } from '../../../utils/sequelize.js'; -class FalukantCharacter extends Model {}; +class FalukantCharacter extends Model {} -FalukantCharacter.init({ - userId: { - type: DataTypes.INTEGER, - allowNull: true, +FalukantCharacter.init( + { + user_id: { + type: DataTypes.INTEGER, + allowNull: true, }, - regionId: { - type: DataTypes.INTEGER, - allowNull: false, + region_id: { + type: DataTypes.INTEGER, + allowNull: false, }, - firstName: { - type: DataTypes.INTEGER, - allowNull: false, + first_name: { + type: DataTypes.INTEGER, + allowNull: false, }, - lastName: { - type: DataTypes.INTEGER, - allowNull: false, + last_name: { + type: DataTypes.INTEGER, + allowNull: false, }, birthdate: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW + type: DataTypes.DATE, + allowNull: false, + defaultValue: DataTypes.NOW, }, gender: { - type: DataTypes.STRING + type: DataTypes.STRING, }, health: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: 100 + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 100, }, titleOfNobility: { - type: DataTypes.INTEGER, - allowNull: false, + type: DataTypes.INTEGER, + allowNull: false, + }, + moodId: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 1, } -}, { + }, + { sequelize, modelName: 'FalukantCharacter', tableName: 'character', schema: 'falukant_data', timestamps: true, underscored: true, -}); + } +); export default FalukantCharacter; diff --git a/backend/models/falukant/data/falukant_character_trait.js b/backend/models/falukant/data/falukant_character_trait.js new file mode 100644 index 0000000..fa562a6 --- /dev/null +++ b/backend/models/falukant/data/falukant_character_trait.js @@ -0,0 +1,27 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class FalukantCharacterTrait extends Model {} + +FalukantCharacterTrait.init( + { + character_id: { + type: DataTypes.INTEGER, + allowNull: false, + }, + trait_id: { + type: DataTypes.INTEGER, + allowNull: false, + }, + }, + { + sequelize, + modelName: 'FalukantCharacterTrait', + tableName: 'falukant_character_trait', + schema: 'falukant_data', + timestamps: false, + underscored: true, + } +); + +export default FalukantCharacterTrait; diff --git a/backend/models/falukant/data/marriage_proposal.js b/backend/models/falukant/data/marriage_proposal.js new file mode 100644 index 0000000..fc645d4 --- /dev/null +++ b/backend/models/falukant/data/marriage_proposal.js @@ -0,0 +1,34 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class MarriageProposal extends Model {} + +MarriageProposal.init( + { + requesterCharacterId: { + type: DataTypes.INTEGER, + allowNull: false, + onDelete: 'CASCADE', + }, + proposedCharacterId: { + type: DataTypes.INTEGER, + allowNull: false, + onDelete: 'CASCADE', + }, + cost: { + type: DataTypes.FLOAT, + allowNull: false, + defaultValue: 0, + }, + }, + { + sequelize, + modelName: 'MarriageProposal', + tableName: 'marriage_proposals', + schema: 'falukant_data', + timestamps: true, + underscored: true, + } +); + +export default MarriageProposal; diff --git a/backend/models/falukant/data/production.js b/backend/models/falukant/data/production.js index 6651661..e097e50 100644 --- a/backend/models/falukant/data/production.js +++ b/backend/models/falukant/data/production.js @@ -19,7 +19,7 @@ Production.init({ startTimestamp: { type: DataTypes.DATE, allowNull: false, - defaultValue: DataTypes.NOW, + defaultValue: sequelize.literal('CURRENT_TIMESTAMP'), } }, { sequelize, diff --git a/backend/models/falukant/data/town_product_worth.js b/backend/models/falukant/data/town_product_worth.js new file mode 100644 index 0000000..8ebf547 --- /dev/null +++ b/backend/models/falukant/data/town_product_worth.js @@ -0,0 +1,34 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class TownProductWorth extends Model { } + +TownProductWorth.init({ + productId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + regionId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + worthPercent: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, + } +}, { + sequelize, + modelName: 'TownProductWorth', + tableName: 'town_product_worth', + schema: 'falukant_data', + timestamps: false, + underscored: true, + hooks: { + beforeCreate: (worthPercent) => { + worthPercent.worthPercent = Math.floor(Math.random() * 20) + 40; + } + } +}); + +export default TownProductWorth; diff --git a/backend/models/falukant/log/dayproduction.js b/backend/models/falukant/log/dayproduction.js new file mode 100644 index 0000000..a0686d6 --- /dev/null +++ b/backend/models/falukant/log/dayproduction.js @@ -0,0 +1,44 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class DayProduction extends Model { } + +DayProduction.init({ + regionId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + productId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + quantity: { + type: DataTypes.INTEGER, + allowNull: false, + }, + producerId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + productionTimestamp: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: sequelize.literal('CURRENT_TIMESTAMP'), + } +}, { + sequelize, + modelName: 'DayProduction', + tableName: 'production', + schema: 'falukant_log', + timestamps: false, + underscored: true, + indexes: [ + { + unique: true, + fields: ['producer_id', 'product_id', 'region_id'] + } + ] + +}); + +export default DayProduction; diff --git a/backend/models/falukant/log/daysell.js b/backend/models/falukant/log/daysell.js new file mode 100644 index 0000000..9102809 --- /dev/null +++ b/backend/models/falukant/log/daysell.js @@ -0,0 +1,43 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class DaySell extends Model { } + +DaySell.init({ + regionId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + productId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + quantity: { + type: DataTypes.INTEGER, + allowNull: false, + }, + sellerId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + sellTimestamp: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: sequelize.literal('CURRENT_TIMESTAMP'), + } +}, { + sequelize, + modelName: 'DaySell', + tableName: 'sell', + schema: 'falukant_log', + timestamps: false, + underscored: true, + indexes: [ + { + unique: true, + fields: ['seller_id', 'product_id', 'region_id'] + } + ] +}); + +export default DaySell; diff --git a/backend/models/falukant/log/notification b/backend/models/falukant/log/notification new file mode 100644 index 0000000..6086864 --- /dev/null +++ b/backend/models/falukant/log/notification @@ -0,0 +1,29 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class Notification extends Model { } + +Notification.init({ + userId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + tr: { + type: DataTypes.STRING, + allowNull: false, + }, + shown: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false, + }, +}, { + sequelize, + modelName: 'Notification', + tableName: 'notification', + schema: 'falukant_log', + timestamps: true, + underscored: true, +}); + +export default Notification; diff --git a/backend/models/falukant/predefine/promotional_gift_character_trait.js b/backend/models/falukant/predefine/promotional_gift_character_trait.js new file mode 100644 index 0000000..68b37a9 --- /dev/null +++ b/backend/models/falukant/predefine/promotional_gift_character_trait.js @@ -0,0 +1,45 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; +import PromotionalGift from '../type/promotional_gift.js'; +import CharacterTrait from '../type/character_trait.js'; + +class PromotionalGiftCharacterTrait extends Model {} + +PromotionalGiftCharacterTrait.init( + { + gift_id: { + type: DataTypes.INTEGER, + references: { + model: PromotionalGift, + key: 'id', + }, + allowNull: false, + }, + trait_id: { + type: DataTypes.INTEGER, + references: { + model: CharacterTrait, + key: 'id', + }, + allowNull: false, + }, + suitability: { + type: DataTypes.INTEGER, + allowNull: false, + validate: { + min: 1, + max: 5, + }, + }, + }, + { + sequelize, + modelName: 'PromotionalGiftCharacterTrait', + tableName: 'promotional_gift_character_trait', + schema: 'falukant_predefine', + timestamps: false, + underscored: true, + } +); + +export default PromotionalGiftCharacterTrait; diff --git a/backend/models/falukant/predefine/promotional_gift_mood.js b/backend/models/falukant/predefine/promotional_gift_mood.js new file mode 100644 index 0000000..94998fd --- /dev/null +++ b/backend/models/falukant/predefine/promotional_gift_mood.js @@ -0,0 +1,45 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; +import PromotionalGift from '../type/promotional_gift.js'; +import Mood from '../type/mood.js'; + +class PromotionalGiftMood extends Model {} + +PromotionalGiftMood.init( + { + gift_id: { + type: DataTypes.INTEGER, + references: { + model: PromotionalGift, + key: 'id', + }, + allowNull: false, + }, + mood_id: { + type: DataTypes.INTEGER, + references: { + model: Mood, + key: 'id', + }, + allowNull: false, + }, + suitability: { + type: DataTypes.INTEGER, + allowNull: false, + validate: { + min: 1, + max: 5, + }, + }, + }, + { + sequelize, + modelName: 'PromotionalGiftMood', + tableName: 'promotional_gift_mood', + schema: 'falukant_predefine', + timestamps: false, + underscored: true, + } +); + +export default PromotionalGiftMood; diff --git a/backend/models/falukant/type/character_trait.js b/backend/models/falukant/type/character_trait.js new file mode 100644 index 0000000..778287d --- /dev/null +++ b/backend/models/falukant/type/character_trait.js @@ -0,0 +1,23 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class CharacterTrait extends Model {} + +CharacterTrait.init( + { + tr: { + type: DataTypes.STRING, + allowNull: false, + }, + }, + { + sequelize, + modelName: 'CharacterTrait', + tableName: 'character_trait', + schema: 'falukant_type', + timestamps: false, + underscored: true, + } +); + +export default CharacterTrait; diff --git a/backend/models/falukant/type/mood.js b/backend/models/falukant/type/mood.js new file mode 100644 index 0000000..d3be72a --- /dev/null +++ b/backend/models/falukant/type/mood.js @@ -0,0 +1,23 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class Mood extends Model {} + +Mood.init( + { + tr: { + type: DataTypes.STRING, + allowNull: false, + }, + }, + { + sequelize, + modelName: 'Mood', + tableName: 'mood', + schema: 'falukant_type', + timestamps: false, + underscored: true, + } +); + +export default Mood; diff --git a/backend/models/falukant/type/promotional_gift.js b/backend/models/falukant/type/promotional_gift.js new file mode 100644 index 0000000..d2ce4e7 --- /dev/null +++ b/backend/models/falukant/type/promotional_gift.js @@ -0,0 +1,32 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class PromotionalGift extends Model {} + +PromotionalGift.init( + { + name: { + type: DataTypes.STRING, + allowNull: false, + }, + description: { + type: DataTypes.TEXT, + allowNull: true, + }, + value: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, // Wert des Geschenks + }, + }, + { + sequelize, + modelName: 'PromotionalGift', + tableName: 'promotional_gift', + schema: 'falukant_type', + timestamps: false, + underscored: true, + } +); + +export default PromotionalGift; diff --git a/backend/models/falukant/type/relationship.js b/backend/models/falukant/type/relationship.js new file mode 100644 index 0000000..ea4214f --- /dev/null +++ b/backend/models/falukant/type/relationship.js @@ -0,0 +1,23 @@ +import { Model, DataTypes } from 'sequelize'; +import { sequelize } from '../../../utils/sequelize.js'; + +class Relationship extends Model {} + +Relationship.init( + { + tr: { + type: DataTypes.STRING, + allowNull: false, + } + }, + { + sequelize, + modelName: 'Relationship', + tableName: 'relationship', + schema: 'falukant_type', + timestamps: false, + underscored: true, + } +); + +export default Relationship; diff --git a/backend/models/index.js b/backend/models/index.js index a3ce448..0cf9a5b 100644 --- a/backend/models/index.js +++ b/backend/models/index.js @@ -52,6 +52,18 @@ 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'; +import TownProductWorth from './falukant/data/town_product_worth.js'; +import DayProduction from './falukant/log/dayproduction.js'; +import DaySell from './falukant/log/daysell.js'; +import Notification from './falukant/log/notification'; +import MarriageProposal from './falukant/data/marriage_proposal.js'; +import Relationship from './falukant/type/relationship.js'; +import CharacterTrait from './falukant/type/character_trait.js'; +import FalukantCharacterTrait from './falukant/data/falukant_character_trait.js'; +import Mood from './falukant/type/mood.js'; +import PromotionalGift from './falukant/type/promotional_gift.js'; +import PromotionalGiftCharacterTrait from './falukant/predefine/promotional_gift_character_trait.js'; +import PromotionalGiftMood from './falukant/predefine/promotional_gift_mood.js'; const models = { SettingsType, @@ -108,6 +120,18 @@ const models = { MoneyFlow, Director, DirectorProposal, + TownProductWorth, + DayProduction, + DaySell, + Notification, + MarriageProposal, + Relationship, + CharacterTrait, + FalukantCharacterTrait, + Mood, + PromotionalGift, + PromotionalGiftCharacterTrait, + PromotionalGiftMood, }; export default models; diff --git a/backend/routers/falukantRouter.js b/backend/routers/falukantRouter.js index d2b2cf0..0650f84 100644 --- a/backend/routers/falukantRouter.js +++ b/backend/routers/falukantRouter.js @@ -30,5 +30,5 @@ router.post('/director/proposal', falukantController.getDirectorProposals); router.post('/director/convertproposal', falukantController.convertProposalToDirector); router.post('/director/settings', falukantController.setSetting); router.get('/director/:branchId', falukantController.getDirectorForBranch); - +router.get('/marriage/proposals', falukantController.getMarriageProposals); export default router; diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 4ac208f..96c8848 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -24,6 +24,7 @@ import { updateFalukantUserMoney } from '../utils/sequelize.js'; import BuyableStock from '../models/falukant/data/buyable_stock.js'; import DirectorProposal from '../models/falukant/data/director_proposal.js'; import Director from '../models/falukant/data/director.js'; +import DaySell from '../models/falukant/log/daysell.js'; function calcAge(birthdate) { @@ -227,7 +228,12 @@ class FalukantService extends BaseService { async getProducts(hashedUserId) { const u = await getFalukantUserOrFail(hashedUserId); + console.log(u); const c = await FalukantCharacter.findOne({ where: { userId: u.id } }); + console.log(c); + if (!c) { + throw new Error(`No FalukantCharacter found for user with id ${u.id}`); + } const ps = await ProductType.findAll({ where: { category: { [Op.lte]: u.certificate } }, include: [{ model: Knowledge, as: 'knowledges', attributes: ['knowledge'], where: { characterId: c.id } }], @@ -284,10 +290,8 @@ class FalukantService extends BaseService { const branch = await getBranchOrFail(user.id, branchId); const character = await FalukantCharacter.findOne({ where: { userId: user.id } }); if (!character) throw new Error('No character found for user'); - const stock = await FalukantStock.findOne({ where: { branchId: branch.id } }); if (!stock) throw new Error('Stock not found'); - const inventory = await Inventory.findAll({ where: { stockId: stock.id, quality }, include: [ @@ -307,18 +311,14 @@ class FalukantService extends BaseService { } ] }); - if (!inventory.length) throw new Error('No inventory found'); const available = inventory.reduce((sum, i) => sum + i.quantity, 0); if (available < quantity) throw new Error('Not enough inventory available'); - const item = inventory[0].productType; const knowledgeVal = item.knowledges?.[0]?.knowledge || 0; const revenue = quantity * calcSellPrice(item, knowledgeVal); - const moneyResult = await updateFalukantUserMoney(user.id, revenue, 'Product sale', user.id); if (!moneyResult.success) throw new Error('Failed to update money'); - let remaining = quantity; for (const inv of inventory) { if (inv.quantity <= remaining) { @@ -330,7 +330,7 @@ class FalukantService extends BaseService { break; } } - + await this.addSellItem(branchId, falukantUser.id, productId, quantity); notifyUser(user.user.hashedId, 'falukantUpdateStatus', {}); notifyUser(user.user.hashedId, 'falukantBranchUpdate', { branchId: branch.id }); return { success: true }; @@ -384,6 +384,7 @@ class FalukantService extends BaseService { for (const item of inventory) { const knowledgeVal = item.productType.knowledges[0]?.knowledge || 0; total += item.quantity * calcSellPrice(item.productType, knowledgeVal); + await this.addSellItem(item.stock[0].branch[0].id, falukantUser.id, item.productType.id, item.quantity); } const moneyResult = await updateFalukantUserMoney( falukantUser.id, @@ -396,10 +397,35 @@ class FalukantService extends BaseService { await Inventory.destroy({ where: { id: item.id } }); } notifyUser(falukantUser.user.hashedId, 'falukantUpdateStatus', {}); - notifyUser(falukantUser.user.hashedId, 'falukantBranchUpdate', { branchId: branch.id }); + notifyUser(falukantUser.user.hashedId, 'falukantBranchUpdate', {}); return { success: true, revenue: total }; } + async addSellItem(branchId, userId, productId, quantity) { + const branch = await Branch.findOne({ + where: { id: branchId }, + }) + ; + const daySell = await DaySell.findOne({ + where: { + regionId: regionId, + productId: productId, + sellerId: userId, + } + }); + if (daySell) { + daySell.quantity += quantity; + await daySell.save(); + } else { + await DaySell.create({ + regionId: regionId, + productId: productId, + sellerId: userId, + quantity: quantity, + }); + } + } + async moneyHistory(hashedUserId, page = 1, filter = '') { const u = await getFalukantUserOrFail(hashedUserId); const limit = 25, offset = (page - 1) * limit; @@ -905,6 +931,61 @@ class FalukantService extends BaseService { }); return { result: 'ok' }; } + + async getMarriageProposals(hashedUserId) { + const user = await this.getFalukantUserByHashedId(hashedUserId); + const character = await FalukantCharacter.findOne({ where: { userId: user.id } }); + if (!character) { + throw new Error('Character not found for this user'); + } + const midnight = new Date(); + midnight.setHours(0, 0, 0, 0); + await MarriageProposal.destroy({ + where: { + [Op.or]: [ + { requesterCharacterId: character.id }, + { proposedCharacterId: character.id }, + ], + createdAt: { + [Op.lt]: midnight, + }, + }, + }); + let proposals = await MarriageProposal.findAll({ + where: { + [Op.or]: [ + { requesterCharacterId: character.id }, + { proposedCharacterId: character.id }, + ], + }, + }); + if (proposals.length === 0) { + const proposalCount = Math.floor(Math.random() * 4) + 3; // 3–6 + const thirteenDaysAgo = new Date(Date.now() - 13 * 24 * 60 * 60 * 1000); + const possiblePartners = await FalukantCharacter.findAll({ + where: { + id: { [Op.ne]: character.id }, + createdAt: { [Op.lt]: thirteenDaysAgo }, + }, + order: [sequelize.fn('RANDOM')], + }); + if (possiblePartners.length === 0) { + return []; + } + const newProposals = []; + for (let i = 0; i < proposalCount; i++) { + const partner = possiblePartners[i % possiblePartners.length]; + const createdProposal = await MarriageProposal.create({ + requesterCharacterId: character.id, + proposedCharacterId: partner.id, + courtingProgress: 0, + }); + newProposals.push(createdProposal); + } + proposals = newProposals; + } + return proposals; + } } export default new FalukantService(); diff --git a/backend/utils/falukant/initializeFalukantPredefines.js b/backend/utils/falukant/initializeFalukantPredefines.js index 9e92cd8..aa441dc 100644 --- a/backend/utils/falukant/initializeFalukantPredefines.js +++ b/backend/utils/falukant/initializeFalukantPredefines.js @@ -5,6 +5,7 @@ import ProductType from "../../models/falukant/type/product.js"; import FalukantStockType from "../../models/falukant/type/stock.js"; import TitleOfNobility from "../../models/falukant/type/title_of_nobility.js"; import TitleRequirement from "../../models/falukant/type/title_requirement.js"; +import { sequelize } from "../sequelize.js"; export const initializeFalukantPredefines = async () => { await initializeFalukantFirstnames(); @@ -14,6 +15,7 @@ export const initializeFalukantPredefines = async () => { await initializeFalukantTitles(); await initializeFalukantTitleRequirements(); await initializeFalukantBranchTypes(); + await initializeFalukantTownProductWorth(); } const initializeFalukantFirstnames = async () => { @@ -342,3 +344,12 @@ async function initializeFalukantBranchTypes() { { labelTr: 'fullstack', baseCost: 4500}, ], { ignoreDuplicates: true }); } + +async function initializeFalukantTownProductWorth() { + const deleteQuery = 'delete from \"falukant_data\".\"town_product_worth\"'; + const createQuery = 'insert into \"falukant_data\".\"town_product_worth\" (\"product_id\", \"region_id\", \"worth_percent\") \ + select ftp.\"id\", fdr.\"id\", ROUND(40 + RANDOM() * 20) \ + from \"falukant_type\".\"product\" ftp, \"falukant_data\".\"region\" fdr'; + sequelize.query(deleteQuery); + sequelize.query(createQuery); +} \ No newline at end of file diff --git a/backend/utils/falukant/initializeFalukantTypes.js b/backend/utils/falukant/initializeFalukantTypes.js index fc2b284..8d63dbb 100644 --- a/backend/utils/falukant/initializeFalukantTypes.js +++ b/backend/utils/falukant/initializeFalukantTypes.js @@ -1,5 +1,11 @@ import RegionData from "../../models/falukant/data/region.js"; import RegionType from "../../models/falukant/type/region.js"; +import Relationship from "../../models/falukant/type/relationship.js"; +import Mood from "../../models/falukant/type/mood.js"; +import CharacterTrait from "../../models/falukant/type/character_trait.js"; +import PromotionalGift from "../../models/falukant/type/promotional_gift.js"; +import PromotionalGiftCharacterTrait from "../../models/falukant/predefine/promotional_gift_character_trait.js"; +import PromotionalGiftMood from "../../models/falukant/predefine/promotional_gift_mood.js"; const regionTypes = []; const regionTypeTrs = [ @@ -10,6 +16,7 @@ const regionTypeTrs = [ "county", "city" ]; + const regions = [ { labelTr: "falukant", regionType: "country", parentTr: null }, { labelTr: "duchy1", regionType: "duchy", parentTr: "falukant" }, @@ -22,10 +29,179 @@ const regions = [ { labelTr: "town4", regionType: "city", parentTr: "county1" }, ]; -// Step 1: Initialize region types +const relationships = [ + { tr: "wooing" }, + { tr: "engaged" }, + { tr: "married" }, + { tr: "widowed" } +]; + +const moods = [ + { name: "happy", description: "Feeling joyful and content." }, + { name: "sad", description: "Feeling down or unhappy." }, + { name: "angry", description: "Feeling annoyed or upset." }, + { name: "calm", description: "Feeling peaceful and relaxed." }, + { name: "nervous", description: "Feeling anxious or tense." }, + { name: "excited", description: "Feeling thrilled and enthusiastic." }, + { name: "bored", description: "Feeling uninterested or tired of something." }, + { name: "fearful", description: "Feeling scared or worried about something." }, + { name: "confident", description: "Feeling self-assured and positive." }, + { name: "curious", description: "Eager to learn or know more about something." }, + { name: "hopeful", description: "Feeling optimistic about the future." }, + { name: "frustrated", description: "Feeling irritated or annoyed due to obstacles." }, + { name: "lonely", description: "Feeling isolated or missing companionship." }, + { name: "grateful", description: "Feeling thankful and appreciative." }, + { name: "jealous", description: "Feeling envious of someone or something." }, + { name: "guilty", description: "Feeling regretful or responsible for wrongdoing." }, + { name: "apathetic", description: "Feeling indifferent or lacking emotion." }, + { name: "relieved", description: "Feeling a sense of ease after a problem is resolved." }, + { name: "proud", description: "Feeling satisfaction about achievements." }, + { name: "ashamed", description: "Feeling embarrassed or guilty about something." }, +]; + +const characterTraits = [ + { name: "brave", description: "Courageous and willing to take risks." }, + { name: "kind", description: "Compassionate and caring for others." }, + { name: "greedy", description: "Focused on acquiring material wealth." }, + { name: "wise", description: "Possesses deep understanding and insight." }, + { name: "loyal", description: "Faithful to friends or obligations." }, + { name: "cunning", description: "Skilled in achieving goals through cleverness or deceit." }, + { name: "generous", description: "Willing to give and share with others." }, + { name: "arrogant", description: "Overly proud and dismissive of others." }, + { name: "honest", description: "Truthful and sincere." }, + { name: "ambitious", description: "Driven by a strong desire to achieve success." }, + { name: "patient", description: "Able to endure delays or problems without frustration." }, + { name: "impatient", description: "Eager to act or react quickly, often without waiting." }, + { name: "selfish", description: "Focused on one's own needs and desires over others'." }, + { name: "charismatic", description: "Charming and able to inspire others." }, + { name: "empathetic", description: "Able to understand and share the feelings of others." }, + { name: "timid", description: "Shy and lacking confidence." }, + { name: "stubborn", description: "Unwilling to change one's attitude or opinion." }, + { name: "resourceful", description: "Able to find quick and clever solutions to problems." }, + { name: "reckless", description: "Acting without considering the consequences." }, + { name: "disciplined", description: "Able to control oneself and follow rules." }, + { name: "optimistic", description: "Expecting the best possible outcome." }, + { name: "pessimistic", description: "Expecting the worst possible outcome." }, + { name: "manipulative", description: "Skilled at influencing others for one's benefit." }, + { name: "independent", description: "Self-reliant and not needing others' help." }, + { name: "dependent", description: "Relying on others for support or assistance." }, + { name: "adventurous", description: "Willing to take risks and seek new experiences." }, + { name: "humble", description: "Modest and not overly proud of oneself." }, + { name: "vengeful", description: "Driven by a desire to seek revenge." }, + { name: "pragmatic", description: "Focused on practical and realistic approaches." }, + { name: "idealistic", description: "Guided by ideals and principles rather than practicality." }, +]; + +const promotionalGifts = [ + { name: "Gold Coin", description: "A shiny gold coin as a token of appreciation.", value: 100 }, + { name: "Silk Scarf", description: "A luxurious silk scarf with elegant patterns.", value: 50 }, + { name: "Exotic Perfume", description: "A rare and enchanting fragrance.", value: 200 }, + { name: "Crystal Pendant", description: "A beautiful pendant made of pure crystal.", value: 150 }, + { name: "Leather Journal", description: "A high-quality leather-bound journal.", value: 75 }, + { name: "Fine Wine", description: "An exquisite bottle of fine wine.", value: 120 }, + { name: "Artisan Chocolate", description: "A box of handcrafted chocolates.", value: 40 }, + { name: "Pearl Necklace", description: "A stunning necklace made with real pearls.", value: 300 }, + { name: "Rare Painting", description: "A rare painting by a renowned artist.", value: 500 }, + { name: "Silver Watch", description: "An elegant silver wristwatch.", value: 250 }, + { name: "Cat", description: "A cuddly and affectionate companion.", value: 70 }, + { name: "Dog", description: "A loyal and loving pet.", value: 150 }, + { name: "Horse", description: "A majestic animal for riding or companionship.", value: 1000 }, +]; + +const promotionalGiftTraitLinks = [ + { gift: "Gold Coin", trait: "brave", suitability: 3 }, + { gift: "Gold Coin", trait: "kind", suitability: 2 }, + { gift: "Gold Coin", trait: "greedy", suitability: 5 }, + { gift: "Gold Coin", trait: "wise", suitability: 3 }, + { gift: "Gold Coin", trait: "loyal", suitability: 2 }, + { gift: "Silk Scarf", trait: "brave", suitability: 2 }, + { gift: "Silk Scarf", trait: "kind", suitability: 5 }, + { gift: "Silk Scarf", trait: "greedy", suitability: 3 }, + { gift: "Silk Scarf", trait: "wise", suitability: 4 }, + { gift: "Silk Scarf", trait: "loyal", suitability: 3 }, + { gift: "Exotic Perfume", trait: "brave", suitability: 2 }, + { gift: "Exotic Perfume", trait: "kind", suitability: 3 }, + { gift: "Exotic Perfume", trait: "greedy", suitability: 4 }, + { gift: "Exotic Perfume", trait: "wise", suitability: 3 }, + { gift: "Exotic Perfume", trait: "loyal", suitability: 1 }, + { gift: "Crystal Pendant", trait: "brave", suitability: 4 }, + { gift: "Crystal Pendant", trait: "kind", suitability: 4 }, + { gift: "Crystal Pendant", trait: "greedy", suitability: 3 }, + { gift: "Crystal Pendant", trait: "wise", suitability: 5 }, + { gift: "Crystal Pendant", trait: "loyal", suitability: 4 }, + { gift: "Leather Journal", trait: "brave", suitability: 3 }, + { gift: "Leather Journal", trait: "kind", suitability: 3 }, + { gift: "Leather Journal", trait: "greedy", suitability: 2 }, + { gift: "Leather Journal", trait: "wise", suitability: 5 }, + { gift: "Leather Journal", trait: "loyal", suitability: 3 }, + { gift: "Cat", trait: "brave", suitability: 2 }, + { gift: "Cat", trait: "kind", suitability: 5 }, + { gift: "Cat", trait: "greedy", suitability: 2 }, + { gift: "Cat", trait: "wise", suitability: 3 }, + { gift: "Cat", trait: "loyal", suitability: 4 }, + { gift: "Dog", trait: "brave", suitability: 4 }, + { gift: "Dog", trait: "kind", suitability: 4 }, + { gift: "Dog", trait: "greedy", suitability: 1 }, + { gift: "Dog", trait: "wise", suitability: 3 }, + { gift: "Dog", trait: "loyal", suitability: 5 }, + { gift: "Horse", trait: "brave", suitability: 5 }, + { gift: "Horse", trait: "kind", suitability: 3 }, + { gift: "Horse", trait: "greedy", suitability: 2 }, + { gift: "Horse", trait: "wise", suitability: 4 }, + { gift: "Horse", trait: "loyal", suitability: 4 }, +]; + +const promotionalGiftMoodLinks = [ + { gift: "Gold Coin", mood: "happy", suitability: 5 }, + { gift: "Gold Coin", mood: "sad", suitability: 1 }, + { gift: "Gold Coin", mood: "angry", suitability: 2 }, + { gift: "Gold Coin", mood: "calm", suitability: 3 }, + { gift: "Gold Coin", mood: "nervous", suitability: 3 }, + { gift: "Silk Scarf", mood: "happy", suitability: 4 }, + { gift: "Silk Scarf", mood: "sad", suitability: 3 }, + { gift: "Silk Scarf", mood: "angry", suitability: 2 }, + { gift: "Silk Scarf", mood: "calm", suitability: 5 }, + { gift: "Silk Scarf", mood: "nervous", suitability: 4 }, + { gift: "Exotic Perfume", mood: "happy", suitability: 5 }, + { gift: "Exotic Perfume", mood: "sad", suitability: 2 }, + { gift: "Exotic Perfume", mood: "angry", suitability: 1 }, + { gift: "Exotic Perfume", mood: "calm", suitability: 3 }, + { gift: "Exotic Perfume", mood: "nervous", suitability: 5 }, + { gift: "Crystal Pendant", mood: "happy", suitability: 4 }, + { gift: "Crystal Pendant", mood: "sad", suitability: 2 }, + { gift: "Crystal Pendant", mood: "angry", suitability: 2 }, + { gift: "Crystal Pendant", mood: "calm", suitability: 4 }, + { gift: "Crystal Pendant", mood: "nervous", suitability: 3 }, + { gift: "Leather Journal", mood: "happy", suitability: 3 }, + { gift: "Leather Journal", mood: "sad", suitability: 3 }, + { gift: "Leather Journal", mood: "angry", suitability: 1 }, + { gift: "Leather Journal", mood: "calm", suitability: 4 }, + { gift: "Leather Journal", mood: "nervous", suitability: 2 }, + { gift: "Cat", mood: "happy", suitability: 5 }, + { gift: "Cat", mood: "sad", suitability: 4 }, + { gift: "Cat", mood: "angry", suitability: 2 }, + { gift: "Cat", mood: "calm", suitability: 5 }, + { gift: "Cat", mood: "nervous", suitability: 3 }, + { gift: "Dog", mood: "happy", suitability: 5 }, + { gift: "Dog", mood: "sad", suitability: 3 }, + { gift: "Dog", mood: "angry", suitability: 4 }, + { gift: "Dog", mood: "calm", suitability: 4 }, + { gift: "Dog", mood: "nervous", suitability: 3 }, + { gift: "Horse", mood: "happy", suitability: 4 }, + { gift: "Horse", mood: "sad", suitability: 3 }, + { gift: "Horse", mood: "angry", suitability: 2 }, + { gift: "Horse", mood: "calm", suitability: 5 }, + { gift: "Horse", mood: "nervous", suitability: 4 }, +]; + export const initializeFalukantTypes = async () => { await initializeFalukantTypeRegions(); -} + await initializeFalukantRelationships(); + await initializeFalukantMoods(); + await initializeFalukantCharacterTraits(); + await initializeFalukantPromotionalGifts(); + await initializePromotionalGiftMoodLinks(); +}; const initializeFalukantTypeRegions = async () => { for (const regionType of regionTypeTrs) { @@ -40,17 +216,14 @@ const initializeFalukantTypeRegions = async () => { } }; -// Utility: Find region type object by region type const findRegionTypeObjectByRegionType = async (regionType) => { return regionTypes.find(region => region.labelTr === regionType) || null; }; -// Utility: Find region object by label const findRegionObjectByLabelTr = async (labelTr) => { return await RegionData.findOne({ where: { name: labelTr } }); }; -// Step 2: Initialize regions export const initializeFalukantRegions = async () => { for (const region of regions) { const regionType = await findRegionTypeObjectByRegionType(region.regionType); @@ -58,18 +231,14 @@ export const initializeFalukantRegions = async () => { console.error(`Region type not found for: ${region.regionType}`); continue; } - const parentRegion = region.parentTr ? await findRegionObjectByLabelTr(region.parentTr) : null; - if (region.parentTr && !parentRegion) { console.error(`Parent region not found for: ${region.parentTr}`); continue; } - console.log('Creating/Fetching Region:', region.labelTr, 'Type:', regionType.labelTr, 'Parent:', parentRegion?.name); - await RegionData.findOrCreate({ where: { name: region.labelTr }, defaults: { @@ -79,3 +248,81 @@ export const initializeFalukantRegions = async () => { }); } }; + +export const initializeFalukantRelationships = async () => { + for (const relationship of relationships) { + await Relationship.findOrCreate({ + where: { tr: relationship.tr }, + defaults: {} + }); + } +}; + +export const initializeFalukantMoods = async () => { + for (const mood of moods) { + await Mood.findOrCreate({ + where: { tr: mood.name }, + }); + } +}; + + +export const initializeFalukantCharacterTraits = async () => { + for (const trait of characterTraits) { + await CharacterTrait.findOrCreate({ + where: { tr: trait.name }, + }); + } +}; + +export const initializeFalukantPromotionalGifts = async () => { + for (const gift of promotionalGifts) { + await PromotionalGift.findOrCreate({ + where: { name: gift.name }, + defaults: { + description: gift.description, + value: gift.value, + }, + }); + } +}; + +export const initializePromotionalGiftTraitLinks = async () => { + for (const link of promotionalGiftTraitLinks) { + const gift = await PromotionalGift.findOne({ where: { name: link.gift } }); + const trait = await CharacterTrait.findOne({ where: { tr: link.trait } }); + if (!gift || !trait) { + console.error(`Gift or Trait not found for: ${link.gift}, ${link.trait}`); + continue; + } + await PromotionalGiftCharacterTrait.findOrCreate({ + where: { + gift_id: gift.id, + trait_id: trait.id, + }, + defaults: { + suitability: link.suitability, + }, + }); + } +}; + +export const initializePromotionalGiftMoodLinks = async () => { + for (const link of promotionalGiftMoodLinks) { + const gift = await PromotionalGift.findOne({ where: { name: link.gift } }); + const mood = await Mood.findOne({ where: { tr: link.mood } }); + if (!gift || !mood) { + console.error(`Gift or Mood not found for: ${link.gift}, ${link.mood}`); + continue; + } + await PromotionalGiftMood.findOrCreate({ + where: { + gift_id: gift.id, + mood_id: mood.id, + }, + defaults: { + suitability: link.suitability, + }, + }); + } +}; diff --git a/backend/utils/initializeFalukant.js b/backend/utils/initializeFalukant.js index 37337b0..d8565f4 100644 --- a/backend/utils/initializeFalukant.js +++ b/backend/utils/initializeFalukant.js @@ -1,10 +1,15 @@ -import { initializeFalukantTypes, initializeFalukantRegions } from './falukant/initializeFalukantTypes.js'; +import { initializeFalukantTypes, initializeFalukantRegions, initializeFalukantRelationships, + initializeFalukantMoods, initializeFalukantCharacterTraits, initializePromotionalGiftTraitLinks } from './falukant/initializeFalukantTypes.js'; import { initializeFalukantPredefines } from './falukant/initializeFalukantPredefines.js'; const initializeFalukant = async () => { await initializeFalukantTypes(); await initializeFalukantRegions(); await initializeFalukantPredefines(); + await initializeFalukantRelationships(); + await initializeFalukantMoods(); + await initializeFalukantCharacterTraits(); + await initializePromotionalGiftTraitLinks(); } export default initializeFalukant; \ No newline at end of file diff --git a/backend/utils/socket.js b/backend/utils/socket.js index 1d2101a..d1a2dfc 100644 --- a/backend/utils/socket.js +++ b/backend/utils/socket.js @@ -42,7 +42,6 @@ export function getUserSockets() { export async function notifyUser(recipientHashedUserId, event, data) { const io = getIo(); const userSockets = getUserSockets(); - try { const recipientUser = await baseService.getUserByHashedId(recipientHashedUserId); if (recipientUser) { diff --git a/dump.rdb b/dump.rdb index b1e94d9137e4548caf827dd586ef62bbdad8c5a1..bfc94cf2b5322781bb1343a7f3adc6c542c79c9e 100644 GIT binary patch delta 46 zcmV+}0MY-g0$7kRD2p+YXZi?rb7f>LZDno3@TL&}`UqifW-Vf2b7jB)|CHnAv40|_ Eg~Krv#sB~S delta 260 zcmWlRy-EZz6otn>c3WQ|^)BRRa&Iz~AU2j(wl|YxcZxW&Gb5tt;u~n?Q`n0(V&eHYa}zgUf_jZ;Tmcq{&j->qUa%KM@c z`tIoa#C$zWcJ>Zlu36(*#R5nh3A8mHl|(QRYn0$h2U19*qpg)QT5)ALC$d6vf!-nH zG|t~THenn48KsbQb(@+xBdYu6B7=T0gxrRHe%SiW0Yfl=TyQHR$bc9<8BS67l3Zzn kMNrxqlO27NLf2C|XO%z&rQ%wZpv6t`pI&E|SI4_QYXCk{!TF7{`x^5sF_-mh8i}%u-4zu$VYCGmAlBGrGhN+ZWT8zHlqnGITMp4V4MD zg|@g-S~QIECbg7OV1=~>#Vra>rZ6P3Edq0jBwHex8{?(W_MF>i=eEuz`?}oxpObrT ze)s=>o^vlko9MM|8={quw3`un86hO5qFZz)u}>F-=(Cr$CKSJ?rQRk%UCv7M?h%CG zDQun}gQOpCE+yR=oac@CW>apqKH`luE+z-<4^n!pw|JE&PbX1q69AxAiwzmgAE4e& z^D7r^CrT}~8mGDDsM}~@+@@-^_k!tIUt{xeZ_5>pr_H793w%}Q{pE+B`W9yA9Mj+3 z&E+!KFBQD@N%`A>B25-386hZCX)mNw3*k(C1{gXrpxT)MwO8IG-{0%`J-Qx-wWX!U zi}UmQ%k{e|nIb`~K#>Xw37|lpkX$K%a%(ymTq3A;i$K?z3f|$8XOZ;{%n||{D=Y4E zmbZo#OoElmxi!H`q}xGOAdHon#4%kb_4iP|O8}nhnx$}P9kVP8I1-uA)#r@-mzPNS zaQf5t@r~jjVTq~4l4qGALff1Y0=+YSc3GJ1dNR=Bmj z0y{cRL|nd8QC-{4n9ePP?r(~h!=Vs~`(u1hZ_OY5hnLa($F;lJ@$un^zD9yoOeXnx zZYoMJi8+VVY!&tQ-YBO2p+tU6CJnay+sb(V0^q!jMg<&T zk?;mk|A#Eb`;IWLqONZb@A{(u;3ZqvfuO~eH&lB$Z_wDfKUmY88*Cdn81URb6zrZp zH0YgvFL3vXEr6quMuPF4C`-^Ys6g%44sgE`S_D_}1F&zMg@%-e(8PNT9m&5!chU^B d@Mf?hWfiV%iNMSjD6=E_{Ufpwj&uK~{0)nlb { - console.log('Socket.io connected'); socket.emit('setUserId', state.user.id); // Sende user.id, wenn user vorhanden ist }); @@ -138,19 +136,16 @@ const store = createStore({ daemonSocket.onerror = (error) => { console.error('Daemon WebSocket error:', error); - console.log('WebSocket readyState:', daemonSocket.readyState); retryConnection(connectDaemonSocket); }; daemonSocket.addEventListener('message', (event) => { const message = event.data; - console.log(message); if (message === "ping") { daemonSocket.send("pong"); } else { try { const data = JSON.parse(message); - console.log("Message received:", data); } catch (error) { console.error("Error parsing message:", error); } diff --git a/frontend/src/views/falukant/BranchView.vue b/frontend/src/views/falukant/BranchView.vue index e25c396..3bc0c31 100644 --- a/frontend/src/views/falukant/BranchView.vue +++ b/frontend/src/views/falukant/BranchView.vue @@ -409,12 +409,15 @@ export default { return; } const message = JSON.parse(event.data); - if (message.event === 'production_ready' && message.branch_id === this.selectedBranch?.id) { + if ((message.event === 'production_ready' || message.event === 'production_started') && message.branch_id == this.selectedBranch?.id) { this.handleProductionReadyEvent(message); } - if (message.event === 'stock_change' && message.branch_id === this.selectedBranch?.id) { + if (message.event === 'stock_change' && message.branch_id == this.selectedBranch?.id) { this.stockChange(); } + if (message.event === 'selled_items' && message.branch_id == this.selectedBranch?.id) { + this.loadInventory(); + } } catch (error) { console.error('Error processing WebSocket message in BranchView:', error); }