Enhance FalukantService to include certificate attribute: Add 'certificate' to user attributes and ensure default value is set if absent. Update product type retrieval logic to utilize effective certificate value for filtering.

This commit is contained in:
Torsten Schulz (local)
2026-03-25 11:51:25 +01:00
parent de52b6f26d
commit b61a533eac

View File

@@ -847,9 +847,12 @@ class FalukantService extends BaseService {
]
},
],
attributes: ['id', 'money', 'creditAmount', 'todayCreditTaken']
attributes: ['id', 'money', 'creditAmount', 'todayCreditTaken', 'certificate']
});
if (!u) throw new Error('User not found');
if (u.certificate == null) {
u.setDataValue('certificate', 1);
}
// Load UserHouse and HouseType in separate queries to avoid EagerLoadingError
let userHouse = null;
if (u.id != null) {
@@ -897,7 +900,7 @@ class FalukantService extends BaseService {
const nobility = await TitleOfNobility.findOne({ where: { labelTr: 'noncivil' } });
if (!nobility) throw new Error('No title of nobility found with the label "noncivil".');
const falukantUser = await FalukantUser.create({
userId: user.id, money: 50, creditAmount: 0, todayCreditTaken: 0, creditInterestRate: 0, mainBranchRegionId: region.id
userId: user.id, money: 50, creditAmount: 0, todayCreditTaken: 0, creditInterestRate: 0, certificate: 1, mainBranchRegionId: region.id
});
const date = new Date(); date.setDate(date.getDate() - 14);
const ch = await FalukantCharacter.create({
@@ -2017,8 +2020,9 @@ class FalukantService extends BaseService {
if (!c) {
throw new Error(`No FalukantCharacter found for user with id ${u.id}`);
}
const effectiveCertificate = u.certificate ?? 1;
const ps = await ProductType.findAll({
where: { category: { [Op.lte]: u.certificate } },
where: { category: { [Op.lte]: effectiveCertificate } },
include: [{ model: Knowledge, as: 'knowledges', attributes: ['knowledge'], where: { characterId: c.id } }],
attributes: ['labelTr', 'id', 'sellCost', 'productionTime', 'category']
});