|
|
|
|
@ -66,99 +66,10 @@ class Patcher { |
|
|
|
|
|
|
|
|
|
fileprivate static func _importDataFromDev() throws { |
|
|
|
|
|
|
|
|
|
let devServices = Services(url: "https://xlr.alwaysdata.net/roads/") |
|
|
|
|
guard devServices.hasToken() else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
guard StoreCenter.main.synchronizationApiURL == "https://padelclub.app/roads/" else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
guard let userId = StoreCenter.main.userId else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try StoreCenter.main.migrateToken(devServices) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let myClubs: [Club] = DataStore.shared.clubs.filter { $0.creator == userId } |
|
|
|
|
let clubIds: [String] = myClubs.map { $0.id } |
|
|
|
|
|
|
|
|
|
myClubs.forEach { club in |
|
|
|
|
DataStore.shared.clubs.insertIntoCurrentService(item: club) |
|
|
|
|
|
|
|
|
|
let courts = DataStore.shared.courts.filter { clubIds.contains($0.club) } |
|
|
|
|
for court in courts { |
|
|
|
|
DataStore.shared.courts.insertIntoCurrentService(item: court) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DataStore.shared.user.clubs = Array(clubIds) |
|
|
|
|
DataStore.shared.saveUser() |
|
|
|
|
|
|
|
|
|
DataStore.shared.events.insertAllIntoCurrentService() |
|
|
|
|
DataStore.shared.tournaments.insertAllIntoCurrentService() |
|
|
|
|
DataStore.shared.dateIntervals.insertAllIntoCurrentService() |
|
|
|
|
|
|
|
|
|
for tournament in DataStore.shared.tournaments { |
|
|
|
|
let store = tournament.tournamentStore |
|
|
|
|
|
|
|
|
|
Task { // need to wait for the collections to load |
|
|
|
|
try await Task.sleep(until: .now + .seconds(2)) |
|
|
|
|
|
|
|
|
|
store.teamRegistrations.insertAllIntoCurrentService() |
|
|
|
|
store.rounds.insertAllIntoCurrentService() |
|
|
|
|
store.groupStages.insertAllIntoCurrentService() |
|
|
|
|
store.matches.insertAllIntoCurrentService() |
|
|
|
|
store.playerRegistrations.insertAllIntoCurrentService() |
|
|
|
|
store.teamScores.insertAllIntoCurrentService() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate static func _patchMissingMatches() { |
|
|
|
|
|
|
|
|
|
guard let url = StoreCenter.main.synchronizationApiURL else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
guard url == "https://padelclub.app/roads/" else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
let services = Services(url: url) |
|
|
|
|
|
|
|
|
|
for tournament in DataStore.shared.tournaments { |
|
|
|
|
|
|
|
|
|
let store = tournament.tournamentStore |
|
|
|
|
let identifier = tournament.id |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
// if nothing is online we upload the data |
|
|
|
|
let matches: [Match] = try await services.get(identifier: identifier) |
|
|
|
|
if matches.isEmpty { |
|
|
|
|
store.matches.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let playerRegistrations: [PlayerRegistration] = try await services.get(identifier: identifier) |
|
|
|
|
if playerRegistrations.isEmpty { |
|
|
|
|
store.playerRegistrations.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let teamScores: [TeamScore] = try await services.get(identifier: identifier) |
|
|
|
|
if teamScores.isEmpty { |
|
|
|
|
store.teamScores.insertAllIntoCurrentService() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|