Skip to content

Commit

Permalink
feat: use current/default organization ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Aug 27, 2024
1 parent 2874c8d commit 87f8e76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GraphQL.Types;
using VirtoCommerce.Xapi.Core.Infrastructure;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Infrastructure;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Commands;

Expand All @@ -10,6 +10,9 @@ public class CreateQuoteCommand : ICommand<QuoteAggregate>
public string UserId { get; set; }
public string CurrencyCode { get; set; }
public string CultureName { get; set; }

// set by the builder
public string CurrentOrganizationId { get; set; }
}

public class CreateQuoteCommandType : InputObjectGraphType<CreateQuoteCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using GraphQL;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using VirtoCommerce.Xapi.Core.BaseQueries;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.QuoteModule.ExperienceApi.Authorization;
using VirtoCommerce.QuoteModule.ExperienceApi.Schemas;
using VirtoCommerce.Xapi.Core.BaseQueries;
using VirtoCommerce.Xapi.Core.Extensions;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Commands;

Expand All @@ -28,4 +29,16 @@ protected virtual Task CheckCanCreateQuote(IResolveFieldContext<object> context,
{
return Authorize(context, userId, new QuoteAuthorizationRequirement());
}

protected override CreateQuoteCommand GetRequest(IResolveFieldContext<object> context)
{
var command = base.GetRequest(context);

if (command != null)
{
command.CurrentOrganizationId = context.GetCurrentOrganizationId();
}

return command;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
Expand Down Expand Up @@ -50,12 +49,12 @@ public async Task<QuoteAggregate> Handle(CreateQuoteCommand request, Cancellatio

var contact = await GetContact(request.UserId);
quote.CustomerName = contact?.Name;
quote.OrganizationId = contact?.Organizations?.FirstOrDefault();
quote.OrganizationId = request.CurrentOrganizationId ?? contact.DefaultOrganizationId;

var organization = await GetOrganization(quote.OrganizationId);
quote.OrganizationName = organization?.Name;

await _quoteRequestService.SaveChangesAsync(new[] { quote });
await _quoteRequestService.SaveChangesAsync([quote]);

return await _quoteAggregateRepository.GetById(quote.Id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="VirtoCommerce.FileExperienceApi.Data" Version="3.803.0" />
<PackageReference Include="VirtoCommerce.OrdersModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.XCart.Data" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.813.0-alpha.843-vcst-1402" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtoCommerce.QuoteModule.Core\VirtoCommerce.QuoteModule.Core.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/VirtoCommerce.QuoteModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<dependency id="VirtoCommerce.Shipping" version="3.800.0" />
<dependency id="VirtoCommerce.Store" version="3.800.0" />
<dependency id="VirtoCommerce.Tax" version="3.800.0" />
<dependency id="VirtoCommerce.Customer" version="3.813.0" />
</dependencies>

<title>Quotes</title>
Expand Down

0 comments on commit 87f8e76

Please sign in to comment.