Add lastNobilityAdvanceAt field and update logic in FalukantService
- Introduced a new field `lastNobilityAdvanceAt` in the FalukantUser model to track the last time a user advanced in nobility. - Updated the `FalukantService` to enforce a one-week cooldown between nobility advancements, throwing an error if the user attempts to advance too soon. - Ensured the `lastNobilityAdvanceAt` field is updated with the current date upon a successful nobility advancement.
This commit is contained in:
@@ -2931,8 +2931,16 @@ class FalukantService extends BaseService {
|
||||
if (!nobility || !nobility.next) {
|
||||
throw new Error('User does not have a nobility');
|
||||
}
|
||||
const nextTitle = nobility.next.toJSON();
|
||||
const user = await this.getFalukantUserByHashedId(hashedUserId);
|
||||
const now = new Date();
|
||||
if (user.lastNobilityAdvanceAt) {
|
||||
const oneWeekAgo = new Date(now.getTime());
|
||||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
|
||||
if (user.lastNobilityAdvanceAt > oneWeekAgo) {
|
||||
throw new Error('too soon');
|
||||
}
|
||||
}
|
||||
const nextTitle = nobility.next.toJSON();
|
||||
let fulfilled = true;
|
||||
let cost = 0;
|
||||
for (const requirement of nextTitle.requirements) {
|
||||
@@ -2959,6 +2967,7 @@ class FalukantService extends BaseService {
|
||||
});
|
||||
const character = await FalukantCharacter.findOne({ where: { userId: user.id } });
|
||||
await character.update({ titleOfNobility: newTitle.id });
|
||||
await user.update({ lastNobilityAdvanceAt: now });
|
||||
if (cost > 0) {
|
||||
updateFalukantUserMoney(user.id, -cost, 'new nobility title', user.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user