|
|
@@ -24,8 +24,9 @@ import {
|
|
|
TransitionPaymentToStateResult,
|
|
|
} from '@vendure/common/lib/generated-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 { Order } from '../../../entity/order/order.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 { PaymentState } from '../../../service/helpers/payment-state-machine/payment-state';
|
|
|
import { OrderService } from '../../../service/services/order.service';
|
|
|
-import { ShippingMethodService } from '../../../service/services/shipping-method.service';
|
|
|
import { RequestContext } from '../../common/request-context';
|
|
|
import { Allow } from '../../decorators/allow.decorator';
|
|
|
import { Ctx } from '../../decorators/request-context.decorator';
|
|
|
@@ -42,7 +42,10 @@ import { Transaction } from '../../decorators/transaction.decorator';
|
|
|
|
|
|
@Resolver()
|
|
|
export class OrderResolver {
|
|
|
- constructor(private orderService: OrderService, private shippingMethodService: ShippingMethodService) {}
|
|
|
+ constructor(
|
|
|
+ private orderService: OrderService,
|
|
|
+ private connection: TransactionalConnection
|
|
|
+ ) {}
|
|
|
|
|
|
@Query()
|
|
|
@Allow(Permission.ReadOrder)
|
|
|
@@ -165,7 +168,16 @@ export class OrderResolver {
|
|
|
@Mutation()
|
|
|
@Allow(Permission.UpdateOrder)
|
|
|
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()
|