fix: Socket.io real-time güncelleme sistemi tamamen düzeltildi

- Socket.IO client modülü oluşturuldu (socketClient.js)
- SvelteKit API route'larından Socket.IO event gönderimi için client kullanımı
- fuel-slips API'de HTTP fetch yerine Socket.IO client kullanımı
- Server'da API event'larını dinleyip broadcast etme eklendi
- GoodsManagerContent component'inde Socket.IO dinleyicileri düzeltildi
- Dashboard'da Mal Sorumlusu content render düzeltmesi
- İbrahim Kara kullanıcısı ve mal sorumlusu kaydı eklendi
- Login endpoint'inde goods_manager ID mapping düzeltmesi
- fuel-slips/+page.svelte'de eksik fonksiyonlar eklendi
- Kapsamlı debug logları tüm Socket.IO işlemlerine eklendi

Çalışma prensibi:
1. Yakıt fişi oluşturulduğunda -> api-fuel-slip-assigned -> broadcast fuel-slip-assigned
2. Fiş onaylandığında/reddedildiğinde -> api-fuel-slip-updated -> broadcast fuel-slip-updated
3. Tüm değişiklikler anlık olarak ilgili ekranlarda güncelleniyor
This commit is contained in:
2025-11-05 23:13:07 +03:00
parent 2a224f2f02
commit 2b0c9e82cd
7 changed files with 238 additions and 80 deletions

View File

@@ -0,0 +1,44 @@
import { io } from 'socket.io-client';
let socket = null;
export function getSocketClient() {
if (!socket) {
socket = io('http://localhost:3000', {
transports: ['websocket', 'polling']
});
socket.on('connect', () => {
console.log('✅ Server-side Socket.IO client connected:', socket.id);
});
socket.on('disconnect', () => {
console.log('❌ Server-side Socket.IO client disconnected');
});
socket.on('connect_error', (err) => {
console.error('❌ Socket.IO connection error:', err.message);
});
}
return socket;
}
export function emitSocketEvent(event, data) {
const client = getSocketClient();
console.log(`📢 Attempting to emit event: ${event}, connected: ${client?.connected}`);
if (client && client.connected) {
console.log(`📢 Emitting API event to server: api-${event}`, data);
// API event olarak gönder, server broadcast edecek
client.emit(`api-${event}`, data);
return true;
} else {
console.warn('⚠️ Socket not connected, cannot emit event');
// Bağlantı yoksa yeniden bağlanmayı dene
if (client && !client.connected) {
client.connect();
}
return false;
}
}