fix
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using System.Collections.Generic;
|
||||
using Identity;
|
||||
|
||||
public class AccountService
|
||||
{
|
||||
@@ -29,6 +30,7 @@
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly IItemGlobalRepository _itemGlobalRepository;
|
||||
private readonly ItemService _itemService;
|
||||
private readonly IContextProvider _contextProvider;
|
||||
|
||||
public AccountService(
|
||||
ILogger<AccountService> logger,
|
||||
@@ -42,7 +44,8 @@
|
||||
IMotionRepository motionRepository,
|
||||
IItemRepository itemRepository,
|
||||
IItemGlobalRepository itemGlobalRepository,
|
||||
ItemService itemService
|
||||
ItemService itemService,
|
||||
IContextProvider contextProvider
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -57,6 +60,7 @@
|
||||
_itemRepository = itemRepository;
|
||||
_itemGlobalRepository = itemGlobalRepository;
|
||||
_itemService = itemService;
|
||||
_contextProvider = contextProvider;
|
||||
}
|
||||
|
||||
public List<AccountCategoryDto> GetAllCategories(Guid userId)
|
||||
@@ -69,8 +73,8 @@
|
||||
public Exec<AccountCategoryDto, GeneralExecStatus> GetCategory(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<AccountCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var category = _accountCategoryRepository.Get(userId, id);
|
||||
|
||||
var category = _accountCategoryRepository.Get(userId, id);
|
||||
|
||||
if (category == null)
|
||||
{
|
||||
@@ -456,7 +460,7 @@
|
||||
exists.Description = motion.Description;
|
||||
exists.AmountPlus = motion.Plus;
|
||||
exists.AmountMinus = motion.Minus;
|
||||
|
||||
|
||||
if (!_motionRepository.Update(exists))
|
||||
{
|
||||
return result.Set(MotionUpdateStatus.failure);
|
||||
@@ -467,8 +471,8 @@
|
||||
}
|
||||
|
||||
public Exec<List<Motion>, GeneralExecStatus> GetMotions(
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
DateTime dateFrom,
|
||||
DateTime dateTo
|
||||
)
|
||||
@@ -528,13 +532,13 @@
|
||||
|
||||
if (account.AccessRights!.Any(x => x.User!.Email.EqualsIgnoreCase(email)))
|
||||
{
|
||||
return result.Set(AccessInviteStatus.account_not_found);
|
||||
return result.Set(AccessInviteStatus.access_exists);
|
||||
}
|
||||
|
||||
var access = _accountAccessInviteRepository.Get(userId, email);
|
||||
if (access != null)
|
||||
{
|
||||
return result.Set(AccessInviteStatus.access_exists);
|
||||
return result.Set(AccessInviteStatus.invite_exists);
|
||||
}
|
||||
|
||||
var invite = new AccountAccessInvite
|
||||
@@ -542,7 +546,8 @@
|
||||
Id = Guid.NewGuid(),
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
UserId = userId,
|
||||
Email = email,
|
||||
AccountId = account.Id,
|
||||
Email = email.SafeTrim()!,
|
||||
IsAllowWrite = isAllowWrite,
|
||||
};
|
||||
|
||||
@@ -606,5 +611,75 @@
|
||||
return result.Set(_mapper.Map<AccountDto>(account));
|
||||
|
||||
}
|
||||
|
||||
public List<AccountAccessInviteDto> InvitesGet(string email)
|
||||
{
|
||||
return _mapper.Map<List<AccountAccessInviteDto>>(_accountAccessInviteRepository.GetActive(email).ToList());
|
||||
}
|
||||
|
||||
public Exec<AccountDto, InviteAcceptStatus> InviteAccept(Guid userId, Guid id, string name)
|
||||
{
|
||||
var result = new Exec<AccountDto, InviteAcceptStatus>(InviteAcceptStatus.success);
|
||||
|
||||
var invite = _accountAccessInviteRepository.Get(id);
|
||||
if (invite == null
|
||||
|| !invite.Email.EqualsIgnoreCase(_contextProvider.User.Email)
|
||||
|| invite.AcceptedOn.HasValue
|
||||
|| invite.RejectedOn.HasValue
|
||||
)
|
||||
{
|
||||
return result.Set(InviteAcceptStatus.invite_not_found);
|
||||
}
|
||||
|
||||
var account = _accountRepository.Get(invite.UserId, invite.AccountId);
|
||||
if (account == null)
|
||||
{
|
||||
return result.Set(InviteAcceptStatus.account_not_found);
|
||||
}
|
||||
|
||||
if (account.AccessRights!.Any(x => x.UserId == userId))
|
||||
{
|
||||
result.Set(InviteAcceptStatus.already_accepted);
|
||||
}
|
||||
else
|
||||
{
|
||||
_accountAccessRepository.Add(new AccountAccess
|
||||
{
|
||||
UserId = userId,
|
||||
AccountId = account.Id,
|
||||
OwnerId = invite.UserId,
|
||||
Name = name,
|
||||
IsAllowWrite = invite.IsAllowWrite,
|
||||
Type = AccountAccessTypeEnum.external,
|
||||
});
|
||||
}
|
||||
|
||||
invite.AcceptedOn = DateTime.UtcNow;
|
||||
_accountAccessInviteRepository.Update(invite);
|
||||
|
||||
account = _accountRepository.Get(userId, account.Id);
|
||||
|
||||
return result.Set(_mapper.Map<AccountDto>(account));
|
||||
}
|
||||
|
||||
public Exec<AccountAccessInviteDto, GeneralExecStatus> InviteReject(Guid id)
|
||||
{
|
||||
var result = new Exec<AccountAccessInviteDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var invite = _accountAccessInviteRepository.Get(id);
|
||||
if (invite == null
|
||||
|| !invite.Email.EqualsIgnoreCase(_contextProvider.User.Email)
|
||||
|| invite.AcceptedOn.HasValue
|
||||
|| invite.RejectedOn.HasValue
|
||||
)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
invite.RejectedOn = DateTime.UtcNow;
|
||||
_accountAccessInviteRepository.Update(invite);
|
||||
|
||||
return result.Set(_mapper.Map<AccountAccessInviteDto>(invite));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user