|
@@ -36,7 +36,7 @@ import {
|
|
|
} from '../../../common/error/generated-graphql-shop-errors';
|
|
} from '../../../common/error/generated-graphql-shop-errors';
|
|
|
import { Translated } from '../../../common/types/locale-types';
|
|
import { Translated } from '../../../common/types/locale-types';
|
|
|
import { idsAreEqual } from '../../../common/utils';
|
|
import { idsAreEqual } from '../../../common/utils';
|
|
|
-import { ConfigService, LogLevel } from '../../../config';
|
|
|
|
|
|
|
+import { ACTIVE_ORDER_INPUT_FIELD_NAME, ConfigService, LogLevel } from '../../../config';
|
|
|
import { Country } from '../../../entity';
|
|
import { Country } from '../../../entity';
|
|
|
import { Order } from '../../../entity/order/order.entity';
|
|
import { Order } from '../../../entity/order/order.entity';
|
|
|
import { ActiveOrderService, CountryService } from '../../../service';
|
|
import { ActiveOrderService, CountryService } from '../../../service';
|
|
@@ -50,6 +50,8 @@ import { RelationPaths, Relations } from '../../decorators/relations.decorator';
|
|
|
import { Ctx } from '../../decorators/request-context.decorator';
|
|
import { Ctx } from '../../decorators/request-context.decorator';
|
|
|
import { Transaction } from '../../decorators/transaction.decorator';
|
|
import { Transaction } from '../../decorators/transaction.decorator';
|
|
|
|
|
|
|
|
|
|
+type ActiveOrderArgs = { [ACTIVE_ORDER_INPUT_FIELD_NAME]?: any };
|
|
|
|
|
+
|
|
|
@Resolver()
|
|
@Resolver()
|
|
|
export class ShopOrderResolver {
|
|
export class ShopOrderResolver {
|
|
|
constructor(
|
|
constructor(
|
|
@@ -97,9 +99,13 @@ export class ShopOrderResolver {
|
|
|
async activeOrder(
|
|
async activeOrder(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
@Relations(Order) relations: RelationPaths<Order>,
|
|
@Relations(Order) relations: RelationPaths<Order>,
|
|
|
|
|
+ @Args() args: ActiveOrderArgs,
|
|
|
): Promise<Order | undefined> {
|
|
): Promise<Order | undefined> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.findOne(ctx, sessionOrder.id);
|
|
return this.orderService.findOne(ctx, sessionOrder.id);
|
|
|
} else {
|
|
} else {
|
|
@@ -140,10 +146,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async setOrderShippingAddress(
|
|
async setOrderShippingAddress(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationSetOrderShippingAddressArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationSetOrderShippingAddressArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.setShippingAddress(ctx, sessionOrder.id, args.input);
|
|
return this.orderService.setShippingAddress(ctx, sessionOrder.id, args.input);
|
|
|
}
|
|
}
|
|
@@ -156,10 +165,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async setOrderBillingAddress(
|
|
async setOrderBillingAddress(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationSetOrderBillingAddressArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationSetOrderBillingAddressArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.setBillingAddress(ctx, sessionOrder.id, args.input);
|
|
return this.orderService.setBillingAddress(ctx, sessionOrder.id, args.input);
|
|
|
}
|
|
}
|
|
@@ -169,9 +181,15 @@ export class ShopOrderResolver {
|
|
|
|
|
|
|
|
@Query()
|
|
@Query()
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
- async eligibleShippingMethods(@Ctx() ctx: RequestContext): Promise<ShippingMethodQuote[]> {
|
|
|
|
|
|
|
+ async eligibleShippingMethods(
|
|
|
|
|
+ @Ctx() ctx: RequestContext,
|
|
|
|
|
+ @Args() args: ActiveOrderArgs,
|
|
|
|
|
+ ): Promise<ShippingMethodQuote[]> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.getEligibleShippingMethods(ctx, sessionOrder.id);
|
|
return this.orderService.getEligibleShippingMethods(ctx, sessionOrder.id);
|
|
|
}
|
|
}
|
|
@@ -181,9 +199,15 @@ export class ShopOrderResolver {
|
|
|
|
|
|
|
|
@Query()
|
|
@Query()
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
- async eligiblePaymentMethods(@Ctx() ctx: RequestContext): Promise<PaymentMethodQuote[]> {
|
|
|
|
|
|
|
+ async eligiblePaymentMethods(
|
|
|
|
|
+ @Ctx() ctx: RequestContext,
|
|
|
|
|
+ @Args() args: ActiveOrderArgs,
|
|
|
|
|
+ ): Promise<PaymentMethodQuote[]> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.getEligiblePaymentMethods(ctx, sessionOrder.id);
|
|
return this.orderService.getEligiblePaymentMethods(ctx, sessionOrder.id);
|
|
|
}
|
|
}
|
|
@@ -196,10 +220,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async setOrderShippingMethod(
|
|
async setOrderShippingMethod(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationSetOrderShippingMethodArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationSetOrderShippingMethodArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<SetOrderShippingMethodResult, Order>> {
|
|
): Promise<ErrorResultUnion<SetOrderShippingMethodResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.setShippingMethod(ctx, sessionOrder.id, args.shippingMethodId);
|
|
return this.orderService.setShippingMethod(ctx, sessionOrder.id, args.shippingMethodId);
|
|
|
}
|
|
}
|
|
@@ -212,10 +239,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async setOrderCustomFields(
|
|
async setOrderCustomFields(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationSetOrderCustomFieldsArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationSetOrderCustomFieldsArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
): Promise<ErrorResultUnion<ActiveOrderResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
return this.orderService.updateCustomFields(ctx, sessionOrder.id, args.input.customFields);
|
|
return this.orderService.updateCustomFields(ctx, sessionOrder.id, args.input.customFields);
|
|
|
}
|
|
}
|
|
@@ -225,9 +255,16 @@ export class ShopOrderResolver {
|
|
|
|
|
|
|
|
@Query()
|
|
@Query()
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
- async nextOrderStates(@Ctx() ctx: RequestContext): Promise<ReadonlyArray<string>> {
|
|
|
|
|
|
|
+ async nextOrderStates(
|
|
|
|
|
+ @Ctx() ctx: RequestContext,
|
|
|
|
|
+ @Args() args: ActiveOrderArgs,
|
|
|
|
|
+ ): Promise<ReadonlyArray<string>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.getNextOrderStates(sessionOrder);
|
|
return this.orderService.getNextOrderStates(sessionOrder);
|
|
|
}
|
|
}
|
|
|
return [];
|
|
return [];
|
|
@@ -238,10 +275,14 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async transitionOrderToState(
|
|
async transitionOrderToState(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationTransitionOrderToStateArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationTransitionOrderToStateArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<TransitionOrderToStateResult, Order> | undefined> {
|
|
): Promise<ErrorResultUnion<TransitionOrderToStateResult, Order> | undefined> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return await this.orderService.transitionToState(ctx, sessionOrder.id, args.state as OrderState);
|
|
return await this.orderService.transitionToState(ctx, sessionOrder.id, args.state as OrderState);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -251,9 +292,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async addItemToOrder(
|
|
async addItemToOrder(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationAddItemToOrderArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationAddItemToOrderArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>> {
|
|
): Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>> {
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.addItemToOrder(
|
|
return this.orderService.addItemToOrder(
|
|
|
ctx,
|
|
ctx,
|
|
|
order.id,
|
|
order.id,
|
|
@@ -268,12 +313,16 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async adjustOrderLine(
|
|
async adjustOrderLine(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationAdjustOrderLineArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationAdjustOrderLineArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>> {
|
|
): Promise<ErrorResultUnion<UpdateOrderItemsResult, Order>> {
|
|
|
if (args.quantity === 0) {
|
|
if (args.quantity === 0) {
|
|
|
return this.removeOrderLine(ctx, { orderLineId: args.orderLineId });
|
|
return this.removeOrderLine(ctx, { orderLineId: args.orderLineId });
|
|
|
}
|
|
}
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.adjustOrderLine(
|
|
return this.orderService.adjustOrderLine(
|
|
|
ctx,
|
|
ctx,
|
|
|
order.id,
|
|
order.id,
|
|
@@ -288,9 +337,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async removeOrderLine(
|
|
async removeOrderLine(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationRemoveOrderLineArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationRemoveOrderLineArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>> {
|
|
): Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>> {
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.removeItemFromOrder(ctx, order.id, args.orderLineId);
|
|
return this.orderService.removeItemFromOrder(ctx, order.id, args.orderLineId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -299,8 +352,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async removeAllOrderLines(
|
|
async removeAllOrderLines(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
|
|
+ @Args() args: ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>> {
|
|
): Promise<ErrorResultUnion<RemoveOrderItemsResult, Order>> {
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.removeAllItemsFromOrder(ctx, order.id);
|
|
return this.orderService.removeAllItemsFromOrder(ctx, order.id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -309,9 +367,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async applyCouponCode(
|
|
async applyCouponCode(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationApplyCouponCodeArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationApplyCouponCodeArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<ApplyCouponCodeResult, Order>> {
|
|
): Promise<ErrorResultUnion<ApplyCouponCodeResult, Order>> {
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.applyCouponCode(ctx, order.id, args.couponCode);
|
|
return this.orderService.applyCouponCode(ctx, order.id, args.couponCode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -320,9 +382,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async removeCouponCode(
|
|
async removeCouponCode(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationApplyCouponCodeArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationApplyCouponCodeArgs & ActiveOrderArgs,
|
|
|
): Promise<Order> {
|
|
): Promise<Order> {
|
|
|
- const order = await this.activeOrderService.getOrderFromContext(ctx, true);
|
|
|
|
|
|
|
+ const order = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ true,
|
|
|
|
|
+ );
|
|
|
return this.orderService.removeCouponCode(ctx, order.id, args.couponCode);
|
|
return this.orderService.removeCouponCode(ctx, order.id, args.couponCode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -331,10 +397,13 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
@Allow(Permission.UpdateOrder, Permission.Owner)
|
|
|
async addPaymentToOrder(
|
|
async addPaymentToOrder(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationAddPaymentToOrderArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationAddPaymentToOrderArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<AddPaymentToOrderResult, Order>> {
|
|
): Promise<ErrorResultUnion<AddPaymentToOrderResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
const order = await this.orderService.addPaymentToOrder(ctx, sessionOrder.id, args.input);
|
|
const order = await this.orderService.addPaymentToOrder(ctx, sessionOrder.id, args.input);
|
|
|
if (isGraphQlErrorResult(order)) {
|
|
if (isGraphQlErrorResult(order)) {
|
|
@@ -357,13 +426,16 @@ export class ShopOrderResolver {
|
|
|
@Allow(Permission.Owner)
|
|
@Allow(Permission.Owner)
|
|
|
async setCustomerForOrder(
|
|
async setCustomerForOrder(
|
|
|
@Ctx() ctx: RequestContext,
|
|
@Ctx() ctx: RequestContext,
|
|
|
- @Args() args: MutationSetCustomerForOrderArgs,
|
|
|
|
|
|
|
+ @Args() args: MutationSetCustomerForOrderArgs & ActiveOrderArgs,
|
|
|
): Promise<ErrorResultUnion<SetCustomerForOrderResult, Order>> {
|
|
): Promise<ErrorResultUnion<SetCustomerForOrderResult, Order>> {
|
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
if (ctx.authorizedAsOwnerOnly) {
|
|
|
if (ctx.activeUserId) {
|
|
if (ctx.activeUserId) {
|
|
|
return new AlreadyLoggedInError();
|
|
return new AlreadyLoggedInError();
|
|
|
}
|
|
}
|
|
|
- const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
|
|
|
|
|
+ const sessionOrder = await this.activeOrderService.getActiveOrder(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ args[ACTIVE_ORDER_INPUT_FIELD_NAME],
|
|
|
|
|
+ );
|
|
|
if (sessionOrder) {
|
|
if (sessionOrder) {
|
|
|
const customer = await this.customerService.createOrUpdate(ctx, args.input, true);
|
|
const customer = await this.customerService.createOrUpdate(ctx, args.input, true);
|
|
|
if (isGraphQlErrorResult(customer)) {
|
|
if (isGraphQlErrorResult(customer)) {
|