Some extensions and fixes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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',});
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
FalukantCharacter.init(
|
||||
{
|
||||
user_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
regionId: {
|
||||
region_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
firstName: {
|
||||
first_name: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
lastName: {
|
||||
last_name: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
birthdate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
gender: {
|
||||
type: DataTypes.STRING
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
health: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 100
|
||||
defaultValue: 100,
|
||||
},
|
||||
titleOfNobility: {
|
||||
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;
|
||||
|
||||
27
backend/models/falukant/data/falukant_character_trait.js
Normal file
27
backend/models/falukant/data/falukant_character_trait.js
Normal file
@@ -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;
|
||||
34
backend/models/falukant/data/marriage_proposal.js
Normal file
34
backend/models/falukant/data/marriage_proposal.js
Normal file
@@ -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;
|
||||
@@ -19,7 +19,7 @@ Production.init({
|
||||
startTimestamp: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
|
||||
34
backend/models/falukant/data/town_product_worth.js
Normal file
34
backend/models/falukant/data/town_product_worth.js
Normal file
@@ -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;
|
||||
44
backend/models/falukant/log/dayproduction.js
Normal file
44
backend/models/falukant/log/dayproduction.js
Normal file
@@ -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;
|
||||
43
backend/models/falukant/log/daysell.js
Normal file
43
backend/models/falukant/log/daysell.js
Normal file
@@ -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;
|
||||
29
backend/models/falukant/log/notification
Normal file
29
backend/models/falukant/log/notification
Normal file
@@ -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;
|
||||
@@ -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;
|
||||
45
backend/models/falukant/predefine/promotional_gift_mood.js
Normal file
45
backend/models/falukant/predefine/promotional_gift_mood.js
Normal file
@@ -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;
|
||||
23
backend/models/falukant/type/character_trait.js
Normal file
23
backend/models/falukant/type/character_trait.js
Normal file
@@ -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;
|
||||
23
backend/models/falukant/type/mood.js
Normal file
23
backend/models/falukant/type/mood.js
Normal file
@@ -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;
|
||||
32
backend/models/falukant/type/promotional_gift.js
Normal file
32
backend/models/falukant/type/promotional_gift.js
Normal file
@@ -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;
|
||||
23
backend/models/falukant/type/relationship.js
Normal file
23
backend/models/falukant/type/relationship.js
Normal file
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
|
||||
BIN
frontend/public/favicon.ico
Normal file
BIN
frontend/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -73,7 +73,6 @@ const store = createStore({
|
||||
await dispatch('loadMenu');
|
||||
},
|
||||
logout({ commit }) {
|
||||
console.log('Logging out...');
|
||||
commit('clearSocket');
|
||||
commit('clearDaemonSocket');
|
||||
commit('dologout');
|
||||
@@ -89,7 +88,6 @@ const store = createStore({
|
||||
const socket = io(import.meta.env.VITE_API_BASE_URL);
|
||||
|
||||
socket.on('connect', () => {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user