Refactor trigger creation logic: Update the created_at and updated_at fields to use the election date instead of the current timestamp, ensuring accurate term end calculations. Enhance socket event handling in StatusBar component by implementing setup and teardown methods for improved event management and user notifications.

This commit is contained in:
Torsten Schulz (local)
2026-02-02 07:48:53 +01:00
parent 4bf1bc35ae
commit b648175205
3 changed files with 57 additions and 21 deletions

View File

@@ -350,15 +350,16 @@ export async function createTriggers() {
SELECT * FROM random_fill SELECT * FROM random_fill
), ),
-- 8) Neue Ämter anlegen und sofort zurückliefern -- 8) Neue Ämter anlegen created_at = Wahldatum (Amtsbeginn), nicht NOW()
-- damit termEnds = Amtsbeginn + termLength korrekt berechnet werden kann
created_offices AS ( created_offices AS (
INSERT INTO falukant_data.political_office INSERT INTO falukant_data.political_office
(office_type_id, character_id, created_at, updated_at, region_id) (office_type_id, character_id, created_at, updated_at, region_id)
SELECT SELECT
tp.tp_office_type_id, tp.tp_office_type_id,
fw.character_id, fw.character_id,
NOW() AS created_at, tp.tp_election_date AS created_at,
NOW() AS updated_at, tp.tp_election_date AS updated_at,
tp.tp_region_id tp.tp_region_id
FROM final_winners fw FROM final_winners fw
JOIN to_process tp JOIN to_process tp

View File

@@ -3535,8 +3535,9 @@ class FalukantService extends BaseService {
firstName: firstNameObject.id, firstName: firstNameObject.id,
}); });
updateFalukantUserMoney(falukantUser.id, -50, 'Baptism', falukantUser.id); updateFalukantUserMoney(falukantUser.id, -50, 'Baptism', falukantUser.id);
// Trigger status bar refresh for the user after baptism // Trigger status bar refresh (children count) and family view update
notifyUser(hashedUserId, 'falukantUpdateStatus', {}); await notifyUser(hashedUserId, 'falukantUpdateStatus', {});
await notifyUser(hashedUserId, 'familychanged', {});
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
throw new Error(error.message); throw new Error(error.message);

View File

@@ -64,6 +64,17 @@ export default {
this.preloadQuickAccessImages(); this.preloadQuickAccessImages();
}, },
deep: true deep: true
},
socket(newVal, oldVal) {
if (oldVal) this.teardownSocketListeners();
if (newVal) this.setupSocketListeners();
},
daemonSocket(newVal, oldVal) {
if (oldVal && this._daemonHandler) {
oldVal.removeEventListener('message', this._daemonHandler);
this._daemonHandler = null;
}
if (newVal) this.setupDaemonListeners();
} }
}, },
async mounted() { async mounted() {
@@ -72,24 +83,13 @@ export default {
// Bilder für Schnellzugriff vorladen und cachen // Bilder für Schnellzugriff vorladen und cachen
this.preloadQuickAccessImages(); this.preloadQuickAccessImages();
// Live-Socket-Events // Socket.IO (Backend notifyUser) Hauptkanal für Falukant-Events
["falukantUpdateStatus", "stock_change", "familychanged"].forEach(eventName => { this.setupSocketListeners();
if (this.daemonSocket) { this.setupDaemonListeners();
this.daemonSocket.addEventListener('message', (event) => {
try {
const data = JSON.parse(event.data);
if (data.event === eventName) {
this.handleEvent(data);
}
} catch (error) {
// Ignore non-JSON messages like ping/pong
}
});
}
});
}, },
beforeUnmount() { beforeUnmount() {
// Daemon WebSocket wird automatisch beim Logout geschlossen this.teardownSocketListeners();
this.teardownDaemonListeners();
}, },
methods: { methods: {
preloadQuickAccessImages() { preloadQuickAccessImages() {
@@ -155,6 +155,40 @@ export default {
// Error fetching status // Error fetching status
} }
}, },
setupSocketListeners() {
this.teardownSocketListeners();
if (!this.socket) return;
this.socket.on('falukantUpdateStatus', (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data }));
this.socket.on('stock_change', (data) => this.handleEvent({ event: 'stock_change', ...data }));
this.socket.on('familychanged', (data) => this.handleEvent({ event: 'familychanged', ...data }));
},
teardownSocketListeners() {
if (this.socket) {
this.socket.off('falukantUpdateStatus');
this.socket.off('stock_change');
this.socket.off('familychanged');
}
},
setupDaemonListeners() {
this.teardownDaemonListeners();
if (!this.daemonSocket) return;
this._daemonHandler = (event) => {
try {
const data = JSON.parse(event.data);
if (['falukantUpdateStatus', 'stock_change', 'familychanged'].includes(data.event)) {
this.handleEvent(data);
}
} catch (_) {}
};
this.daemonSocket.addEventListener('message', this._daemonHandler);
},
teardownDaemonListeners() {
const sock = this.daemonSocket;
if (sock && this._daemonHandler) {
sock.removeEventListener('message', this._daemonHandler);
this._daemonHandler = null;
}
},
handleEvent(eventData) { handleEvent(eventData) {
switch (eventData.event) { switch (eventData.event) {
case 'falukantUpdateStatus': case 'falukantUpdateStatus':