Update an entities.User
(ctx context.Context, source string, authUser entities.AuthContext, params UserUpdateParams)
| 192 | |
| 193 | // Update an entities.User |
| 194 | func (service *UserService) Update(ctx context.Context, source string, authUser entities.AuthContext, params UserUpdateParams) (*entities.User, error) { |
| 195 | ctx, span := service.tracer.Start(ctx) |
| 196 | defer span.End() |
| 197 | |
| 198 | ctxLogger := service.tracer.CtxLogger(service.logger, span) |
| 199 | |
| 200 | user, isNew, err := service.repository.LoadOrStore(ctx, authUser) |
| 201 | if err != nil { |
| 202 | msg := fmt.Sprintf("could not get [%T] with from [%+#v]", user, authUser) |
| 203 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 204 | } |
| 205 | |
| 206 | if isNew { |
| 207 | service.dispatchUserCreatedEvent(ctx, source, user) |
| 208 | } |
| 209 | |
| 210 | user.Timezone = params.Timezone.String() |
| 211 | user.ActivePhoneID = params.ActivePhoneID |
| 212 | |
| 213 | if err = service.repository.Update(ctx, user); err != nil { |
| 214 | msg := fmt.Sprintf("cannot save user with id [%s]", user.ID) |
| 215 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 216 | } |
| 217 | |
| 218 | ctxLogger.Info(fmt.Sprintf("user saved with id [%s] in the userRepository", user.ID)) |
| 219 | return user, nil |
| 220 | } |
| 221 | |
| 222 | // UserNotificationUpdateParams are parameters for updating the notifications of a user |
| 223 | type UserNotificationUpdateParams struct { |
nothing calls this directly
no test coverage detected