backend updateUser fix

This commit is contained in:
Alex
2025-02-07 21:43:54 +01:00
parent 67ef3a2fca
commit 77619c42bd
6 changed files with 32 additions and 11 deletions

View File

@@ -41,6 +41,29 @@ func (service *UserService) UpdateUser(user *models.User) (*models.User, error)
setPassword(user.Password, user)
}
// Validate subscription model
selectedModel, err := repositories.GetModelByName(&user.Membership.SubscriptionModel.Name)
if err != nil {
return nil, errors.ErrSubscriptionNotFound
}
user.Membership.SubscriptionModel = *selectedModel
user.Membership.SubscriptionModelID = selectedModel.ID
existingUser, err := service.GetUserByID(user.ID)
if err != nil {
return nil, err
}
user.Membership.ID = existingUser.Membership.ID
user.MembershipID = existingUser.MembershipID
if existingUser.Licence != nil {
user.Licence.ID = existingUser.Licence.ID
}
user.LicenceID = existingUser.LicenceID
user.BankAccount.ID = existingUser.BankAccount.ID
user.BankAccountID = existingUser.BankAccountID
// if user.Licence.Status == 0 {
// // This is a new drivers licence
// user.Licence.Status = constants.UnverifiedStatus