Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-1460: use current/default organization ID #117

Merged
merged 10 commits into from
Jan 30, 2025
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 @@ -13,8 +13,9 @@
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.XCatalog.Core" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.XCart.Data" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.817.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtoCommerce.QuoteModule.Core\VirtoCommerce.QuoteModule.Core.csproj" />
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion src/VirtoCommerce.QuoteModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<dependency id="VirtoCommerce.Cart" version="3.810.0" />
<dependency id="VirtoCommerce.Catalog" version="3.800.0" />
<dependency id="VirtoCommerce.Core" version="3.800.0" />
<dependency id="VirtoCommerce.Customer" version="3.817.0" />
<dependency id="VirtoCommerce.Xapi" version="3.900.0" />
<dependency id="VirtoCommerce.XCart" version="3.900.0" />
<dependency id="VirtoCommerce.XCatalog" version="3.900.0" />
Expand All @@ -34,7 +35,7 @@
<iconUrl>Modules/$(VirtoCommerce.Quote)/Content/logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>First version.</releaseNotes>
<copyright>Copyright © 2011–2024 Virto Commerce. All rights reserved</copyright>
<copyright>Copyright © 2011–2025 Virto Commerce. All rights reserved</copyright>
<tags>b2b quotes</tags>
<assemblyFile>VirtoCommerce.QuoteModule.Web.dll</assemblyFile>
<moduleType>VirtoCommerce.QuoteModule.Web.Module, VirtoCommerce.QuoteModule.Web</moduleType>
Expand Down
Loading
Loading