Browse Source

Merge branch 'master' into minor

Michael Bromley 3 years ago
parent
commit
24a2987e9d

+ 16 - 4
packages/core/src/api/resolvers/admin/order.resolver.ts

@@ -24,8 +24,9 @@ import {
     TransitionPaymentToStateResult,
     TransitionPaymentToStateResult,
 } from '@vendure/common/lib/generated-types';
 } from '@vendure/common/lib/generated-types';
 import { PaginatedList } from '@vendure/common/lib/shared-types';
 import { PaginatedList } from '@vendure/common/lib/shared-types';
+import { TransactionalConnection } from '../../../connection';
 
 
-import { ErrorResultUnion } from '../../../common/error/error-result';
+import { ErrorResultUnion, isGraphQlErrorResult } from '../../../common/error/error-result';
 import { Fulfillment } from '../../../entity/fulfillment/fulfillment.entity';
 import { Fulfillment } from '../../../entity/fulfillment/fulfillment.entity';
 import { Order } from '../../../entity/order/order.entity';
 import { Order } from '../../../entity/order/order.entity';
 import { Payment } from '../../../entity/payment/payment.entity';
 import { Payment } from '../../../entity/payment/payment.entity';
@@ -34,7 +35,6 @@ import { FulfillmentState } from '../../../service/helpers/fulfillment-state-mac
 import { OrderState } from '../../../service/helpers/order-state-machine/order-state';
 import { OrderState } from '../../../service/helpers/order-state-machine/order-state';
 import { PaymentState } from '../../../service/helpers/payment-state-machine/payment-state';
 import { PaymentState } from '../../../service/helpers/payment-state-machine/payment-state';
 import { OrderService } from '../../../service/services/order.service';
 import { OrderService } from '../../../service/services/order.service';
-import { ShippingMethodService } from '../../../service/services/shipping-method.service';
 import { RequestContext } from '../../common/request-context';
 import { RequestContext } from '../../common/request-context';
 import { Allow } from '../../decorators/allow.decorator';
 import { Allow } from '../../decorators/allow.decorator';
 import { RelationPaths, Relations } from '../../decorators/relations.decorator';
 import { RelationPaths, Relations } from '../../decorators/relations.decorator';
@@ -43,7 +43,10 @@ import { Transaction } from '../../decorators/transaction.decorator';
 
 
 @Resolver()
 @Resolver()
 export class OrderResolver {
 export class OrderResolver {
-    constructor(private orderService: OrderService, private shippingMethodService: ShippingMethodService) {}
+    constructor(
+        private orderService: OrderService, 
+        private connection: TransactionalConnection
+    ) {}
 
 
     @Query()
     @Query()
     @Allow(Permission.ReadOrder)
     @Allow(Permission.ReadOrder)
@@ -174,7 +177,16 @@ export class OrderResolver {
     @Mutation()
     @Mutation()
     @Allow(Permission.UpdateOrder)
     @Allow(Permission.UpdateOrder)
     async modifyOrder(@Ctx() ctx: RequestContext, @Args() args: MutationModifyOrderArgs) {
     async modifyOrder(@Ctx() ctx: RequestContext, @Args() args: MutationModifyOrderArgs) {
-        return this.orderService.modifyOrder(ctx, args.input);
+        await this.connection.startTransaction(ctx);
+        const result = await this.orderService.modifyOrder(ctx, args.input);
+
+        if (args.input.dryRun || isGraphQlErrorResult(result)) {
+            await this.connection.rollBackTransaction(ctx);
+        } else {
+            await this.connection.commitOpenTransaction(ctx);
+        }
+
+        return result
     }
     }
 
 
     @Transaction()
     @Transaction()

+ 10 - 8
packages/core/src/service/services/order.service.ts

@@ -908,23 +908,26 @@ export class OrderService {
      * * Shipping or billing address changes
      * * Shipping or billing address changes
      *
      *
      * Setting the `dryRun` input property to `true` will apply all changes, including updating the price of the
      * Setting the `dryRun` input property to `true` will apply all changes, including updating the price of the
-     * Order, but will not actually persist any of those changes to the database.
+     * Order, except history entry and additional payment actions. 
+     * 
+     * __Using dryRun option, you must wrap function call in transaction manually.__
+     * 
      */
      */
     async modifyOrder(
     async modifyOrder(
         ctx: RequestContext,
         ctx: RequestContext,
         input: ModifyOrderInput,
         input: ModifyOrderInput,
     ): Promise<ErrorResultUnion<ModifyOrderResult, Order>> {
     ): Promise<ErrorResultUnion<ModifyOrderResult, Order>> {
-        await this.connection.startTransaction(ctx);
         const order = await this.getOrderOrThrow(ctx, input.orderId);
         const order = await this.getOrderOrThrow(ctx, input.orderId);
         const result = await this.orderModifier.modifyOrder(ctx, input, order);
         const result = await this.orderModifier.modifyOrder(ctx, input, order);
-        if (input.dryRun) {
-            await this.connection.rollBackTransaction(ctx);
-            return isGraphQlErrorResult(result) ? result : result.order;
-        }
+
         if (isGraphQlErrorResult(result)) {
         if (isGraphQlErrorResult(result)) {
-            await this.connection.rollBackTransaction(ctx);
             return result;
             return result;
         }
         }
+
+        if (input.dryRun) {
+            return result.order;
+        }
+
         await this.historyService.createHistoryEntryForOrder({
         await this.historyService.createHistoryEntryForOrder({
             ctx,
             ctx,
             orderId: input.orderId,
             orderId: input.orderId,
@@ -933,7 +936,6 @@ export class OrderService {
                 modificationId: result.modification.id,
                 modificationId: result.modification.id,
             },
             },
         });
         });
-        await this.connection.commitOpenTransaction(ctx);
         return this.getOrderOrThrow(ctx, input.orderId);
         return this.getOrderOrThrow(ctx, input.orderId);
     }
     }
 
 

+ 1 - 1
packages/ui-devkit/src/compiler/compile.ts

@@ -66,7 +66,7 @@ function runCompileMode(
     const compile = () =>
     const compile = () =>
         new Promise<void>(async (resolve, reject) => {
         new Promise<void>(async (resolve, reject) => {
             await setupScaffold(outputPath, extensions);
             await setupScaffold(outputPath, extensions);
-            const commandArgs = ['run', 'build', `--outputPath=${distPath}`, `--base-href=${baseHref}`, ...buildProcessArguments(args)];
+            const commandArgs = ['run', 'build', `--outputPath="${distPath}"`, `--base-href=${baseHref}`, ...buildProcessArguments(args)];
             if (!usingYarn) {
             if (!usingYarn) {
                 // npm requires `--` before any command line args being passed to a script
                 // npm requires `--` before any command line args being passed to a script
                 commandArgs.splice(2, 0, '--');
                 commandArgs.splice(2, 0, '--');