feat: add network leg position assignment for new users
This commit is contained in:
+23
-1
@@ -1,3 +1,4 @@
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
@@ -75,6 +76,26 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
|
||||
if (await _context.Users.CountAsync(x => x.NetworkParentId == parent.Id, cancellationToken: cancellationToken) > 1)
|
||||
return new VerifyOtpTokenResponseDto() { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
|
||||
|
||||
// تعیین موقعیت در شبکه (چپ یا راست)
|
||||
var existingChildren = await _context.Users
|
||||
.Where(x => x.NetworkParentId == parent.Id && !x.IsDeleted)
|
||||
.Select(x => x.LegPosition)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
NetworkLeg newUserLegPosition;
|
||||
if (!existingChildren.Any(x => x == NetworkLeg.Left))
|
||||
{
|
||||
newUserLegPosition = NetworkLeg.Left;
|
||||
}
|
||||
else if (!existingChildren.Any(x => x == NetworkLeg.Right))
|
||||
{
|
||||
newUserLegPosition = NetworkLeg.Right;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new VerifyOtpTokenResponseDto() { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
|
||||
}
|
||||
|
||||
user = new User
|
||||
{
|
||||
Mobile = mobile,
|
||||
@@ -83,7 +104,8 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
|
||||
MobileVerifiedAt = now,
|
||||
IsRulesAccepted = true,
|
||||
RulesAcceptedAt = now,
|
||||
NetworkParentId = parent.Id
|
||||
NetworkParentId = parent.Id,
|
||||
LegPosition = newUserLegPosition
|
||||
};
|
||||
await _context.Users.AddAsync(user, cancellationToken);
|
||||
user.AddDomainEvent(new CreateNewUserEvent(user));
|
||||
|
||||
Reference in New Issue
Block a user