better show where the creator is set

multistore
Laurent 1 year ago
parent 538c20b751
commit a691755d29
  1. 2
      PadelClub/Data/Club.swift
  2. 15
      PadelClub/Views/Club/CreateClubView.swift

@ -237,7 +237,7 @@ extension Club {
if clubs.isEmpty == false { if clubs.isEmpty == false {
return clubs.first! return clubs.first!
} else { } else {
return Club(creator: Store.main.userId, name: name, code: code, city: city, zipCode: zipCode) return Club(name: name, code: code, city: city, zipCode: zipCode)
} }
} }

@ -45,26 +45,27 @@ struct CreateClubView: View {
Logger.error(error) Logger.error(error)
} }
let existingOrCreatedClub = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) let club = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode)
club.creator = Store.main.userId
//update existing club if rights ok / freshly created club with data input from user //update existing club if rights ok / freshly created club with data input from user
if existingOrCreatedClub.hasBeenCreated(by: Store.main.userId) { if club.hasBeenCreated(by: Store.main.userId) {
existingOrCreatedClub.update(fromClub: club) club.update(fromClub: club)
} }
do { do {
try dataStore.clubs.addOrUpdate(instance: existingOrCreatedClub) try dataStore.clubs.addOrUpdate(instance: club)
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
//save into user //save into user
if dataStore.user.clubs.contains(where: { $0 == existingOrCreatedClub.id }) == false { if dataStore.user.clubs.contains(where: { $0 == club.id }) == false {
dataStore.user.clubs.append(existingOrCreatedClub.id) dataStore.user.clubs.append(club.id)
self.dataStore.saveUser() self.dataStore.saveUser()
} }
dismiss() dismiss()
selection?(existingOrCreatedClub) selection?(club)
} }
} }
} }

Loading…
Cancel
Save