Skip to content

Commit

Permalink
Fix adding user properties to UserInfo context (#243)
Browse files Browse the repository at this point in the history
* Fix updating the user preferences

* Fix adding user properties to UserInfo context

* Fix adding user properties to UserInfo context

* Make the dictionaries merge code more imperative
  • Loading branch information
Arciiix authored Jun 25, 2024
1 parent fe94068 commit 573c097
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion backend/src/Notifo.Domain/Integrations/IntegrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@
// ==========================================================================

using Notifo.Domain.Users;
using Notifo.Infrastructure.Collections;
using System.Collections.Generic;

namespace Notifo.Domain.Integrations;

public static class IntegrationExtensions
{
public static UserInfo ToContext(this User user)
{
return new UserInfo { Id = user.Id, EmailAddress = user.EmailAddress, PhoneNumber = user.PhoneNumber, Properties = user.SystemProperties };
var properties = new Dictionary<string, string>(user.Properties);

if (user.SystemProperties != null)
{
foreach (var (key, value) in user.SystemProperties)
{
properties[key] = value;
}
}

return new UserInfo
{
Id = user.Id,
EmailAddress = user.EmailAddress,
PhoneNumber = user.PhoneNumber,
Properties = properties.ToReadonlyDictionary()
};
}
}

0 comments on commit 573c097

Please sign in to comment.