Füge Unterstützung für QTTR-Listenaktualisierungen hinzu: Implementiere Push-Benachrichtigung für aktualisierte QTTR-Listen und verbessere die Importlogik.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import { getServerDataPath } from './paths.js'
|
||||
import { sendOwnTtrChangePush } from './push-notifications.js'
|
||||
import { sendOwnTtrChangePush, sendQttrListUpdatedPush } from './push-notifications.js'
|
||||
import { fetchClubRankings } from './mytischtennis-client.js'
|
||||
import { readMyTischtennisConnection, saveMyTischtennisConnection } from './mytischtennis-connection.js'
|
||||
|
||||
@@ -244,6 +244,8 @@ async function importAuthenticatedTtrValues(connection) {
|
||||
}).filter(row => row.playerName && (row.currentTtr != null || row.currentQttr != null))
|
||||
|
||||
if (!rows.length) throw new Error('Keine verwertbaren TTR-Werte in der myTischtennis-Rangliste gefunden.')
|
||||
const previousQttrSignature = qttrListSignature(previousPayload.rows)
|
||||
const nextQttrSignature = qttrListSignature(rows)
|
||||
const importedAt = new Date().toISOString()
|
||||
const payload = {
|
||||
format: 'harheimertc.qttr.v2', importedAt,
|
||||
@@ -262,6 +264,21 @@ async function importAuthenticatedTtrValues(connection) {
|
||||
: []
|
||||
})
|
||||
await sendOwnTtrChangePush(changes)
|
||||
if (previousQttrSignature && previousQttrSignature !== nextQttrSignature) {
|
||||
await sendQttrListUpdatedPush({ importedAt, rowCount: rows.length })
|
||||
}
|
||||
await saveMyTischtennisConnection({ ...connection, lastSuccessfulImportAt: importedAt, lastImportError: null })
|
||||
return { outputFile: OUTPUT_FILE, tableCount: 1, ...payload }
|
||||
}
|
||||
|
||||
function qttrListSignature(rows) {
|
||||
if (!Array.isArray(rows) || rows.length === 0) return ''
|
||||
return rows
|
||||
.map(row => [
|
||||
String(row?.playerName || '').trim().toLocaleLowerCase('de-DE'),
|
||||
row?.rank ?? '',
|
||||
row?.currentQttr ?? ''
|
||||
].join('|'))
|
||||
.sort()
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user