1
0
Эх сурвалжийг харах

chore(core): Clean up commented-out code & unused files

Michael Bromley 3 жил өмнө
parent
commit
0139ab1336

+ 0 - 87
packages/core/e2e/order.e2e-spec.ts

@@ -1084,34 +1084,6 @@ describe('Orders resolver', () => {
                 { id: f3Id, method: 'Test3', state: 'Delivered', nextStates: ['Cancelled'] },
             ]);
         });
-
-        // it('order.fulfillments.orderItems resolver', async () => {
-        //     const { order } = await adminClient.query<
-        //         Codegen.GetOrderFulfillmentItemsQuery,
-        //         Codegen.GetOrderFulfillmentItemsQueryVariables
-        //     >(GET_ORDER_FULFILLMENT_ITEMS, {
-        //         id: orderId,
-        //     });
-        //     const sortedFulfillments = order!.fulfillments!.sort(sortById);
-        //     expect(sortedFulfillments[0].orderItems).toEqual([{ id: 'T_3' }]);
-        //     expect(sortedFulfillments[1].orderItems).toEqual([{ id: 'T_4' }, { id: 'T_5' }, { id: 'T_6' }]);
-        //     expect(sortedFulfillments[2].orderItems).toEqual([{ id: 'T_4' }, { id: 'T_5' }, { id: 'T_6' }]);
-        // });
-
-        // it('order.line.items.fulfillment resolver', async () => {
-        //     const { order } = await adminClient.query<Codegen.GetOrderQuery, Codegen.GetOrderQueryVariables>(
-        //         GET_ORDER,
-        //         {
-        //             id: orderId,
-        //         },
-        //     );
-        //     const { activeCustomer } = await shopClient.query<
-        //         CodegenShop.GetActiveCustomerOrderWithItemFulfillmentsQuery,
-        //         CodegenShop.GetActiveCustomerOrderWithItemFulfillmentsQueryVariables
-        //     >(GET_ACTIVE_ORDER_CUSTOMER_WITH_ITEM_FULFILLMENTS);
-        //     const firstCustomerOrder = activeCustomer!.orders.items[0]!;
-        //     expect(firstCustomerOrder.lines[0].items[0].fulfillment).not.toBeNull();
-        // });
     });
 
     describe('cancellation by orderId', () => {
@@ -2542,65 +2514,6 @@ describe('Orders resolver', () => {
                     .price,
             ).toBe(108720);
         });
-
-        // TODO: is this needed?
-        // https://github.com/vendure-ecommerce/vendure/issues/1558
-        // it('cancelling OrderItem avoids items that have been fulfilled', async () => {
-        //     await shopClient.asUserWithCredentials(customers[0].emailAddress, password);
-        //     const { addItemToOrder } = await shopClient.query<
-        //         CodegenShop.AddItemToOrderMutation,
-        //         CodegenShop.AddItemToOrderMutationVariables
-        //     >(ADD_ITEM_TO_ORDER, {
-        //         productVariantId: 'T_1',
-        //         quantity: 2,
-        //     });
-        //
-        //     await proceedToArrangingPayment(shopClient);
-        //     const order = await addPaymentToOrder(shopClient, singleStageRefundablePaymentMethod);
-        //     orderGuard.assertSuccess(order);
-        //
-        //     await adminClient.query<
-        //         Codegen.CreateFulfillmentMutation,
-        //         Codegen.CreateFulfillmentMutationVariables
-        //     >(CREATE_FULFILLMENT, {
-        //         input: {
-        //             lines: [
-        //                 {
-        //                     orderLineId: order.lines[0].id,
-        //                     quantity: 1,
-        //                 },
-        //             ],
-        //             handler: {
-        //                 code: manualFulfillmentHandler.code,
-        //                 arguments: [{ name: 'method', value: 'Test' }],
-        //             },
-        //         },
-        //     });
-        //
-        //     const { cancelOrder } = await adminClient.query<
-        //         Codegen.CancelOrderMutation,
-        //         Codegen.CancelOrderMutationVariables
-        //     >(CANCEL_ORDER, {
-        //         input: {
-        //             orderId: order.id,
-        //             lines: [{ orderLineId: order.lines[0].id, quantity: 1 }],
-        //         },
-        //     });
-        //     orderGuard.assertSuccess(cancelOrder);
-        //
-        //     const { order: order2 } = await adminClient.query<
-        //         Codegen.GetOrderQuery,
-        //         Codegen.GetOrderQueryVariables
-        //     >(GET_ORDER, {
-        //         id: order.id,
-        //     });
-        //
-        //     const items = order2!.lines[0].items;
-        //     const itemWhichIsCancelledAndFulfilled = items.find(
-        //         i => i.cancelled === true && i.fulfillment != null,
-        //     );
-        //     expect(itemWhichIsCancelledAndFulfilled).toBeUndefined();
-        // });
     });
 });
 

+ 0 - 2
packages/core/src/api/api-internal-modules.ts

@@ -56,7 +56,6 @@ import {
 import { FulfillmentLineEntityResolver } from './resolvers/entity/fulfillment-line-entity.resolver';
 import { JobEntityResolver } from './resolvers/entity/job-entity.resolver';
 import { OrderAdminEntityResolver, OrderEntityResolver } from './resolvers/entity/order-entity.resolver';
-import { OrderItemEntityResolver } from './resolvers/entity/order-item-entity.resolver';
 import { OrderLineEntityResolver } from './resolvers/entity/order-line-entity.resolver';
 import {
     PaymentAdminEntityResolver,
@@ -135,7 +134,6 @@ export const entityResolvers = [
     FulfillmentEntityResolver,
     FulfillmentLineEntityResolver,
     OrderEntityResolver,
-    OrderItemEntityResolver,
     OrderLineEntityResolver,
     PaymentEntityResolver,
     ProductEntityResolver,

+ 0 - 34
packages/core/src/api/resolvers/entity/order-item-entity.resolver.ts

@@ -1,34 +0,0 @@
-import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
-
-import { RequestContextCacheService } from '../../../cache/index';
-import { Fulfillment } from '../../../entity';
-import { FulfillmentService } from '../../../service';
-import { RequestContext } from '../../common/request-context';
-import { Ctx } from '../../decorators/request-context.decorator';
-
-@Resolver('OrderItem')
-export class OrderItemEntityResolver {
-    constructor(
-        private fulfillmentService: FulfillmentService,
-        private requestContextCache: RequestContextCacheService,
-    ) {}
-
-    // @ResolveField()
-    // async fulfillment(
-    //     @Ctx() ctx: RequestContext,
-    //     @Parent() orderItem: OrderItem,
-    // ): Promise<Fulfillment | undefined> {
-    //     if (orderItem.fulfillment) {
-    //         return orderItem.fulfillment;
-    //     }
-    //     const lineFulfillments = await this.requestContextCache.get(
-    //         ctx,
-    //         `OrderItemEntityResolver.fulfillment(${orderItem.lineId})`,
-    //         () => this.fulfillmentService.getFulfillmentsByOrderLineId(ctx, orderItem.lineId),
-    //     );
-    //     const otherResult = lineFulfillments.find(({ orderItemIds }) =>
-    //         orderItemIds.has(orderItem.id),
-    //     )?.fulfillment;
-    //     return otherResult;
-    // }
-}

+ 1 - 12
packages/core/src/api/resolvers/entity/refund-entity.resolver.ts

@@ -1,20 +1,9 @@
-import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
+import { Resolver } from '@nestjs/graphql';
 
 import { Refund } from '../../../entity/refund/refund.entity';
 import { OrderService } from '../../../service/services/order.service';
-import { RequestContext } from '../../common/request-context';
-import { Ctx } from '../../decorators/request-context.decorator';
 
 @Resolver('Refund')
 export class RefundEntityResolver {
     constructor(private orderService: OrderService) {}
-
-    // @ResolveField()
-    // async orderItems(@Ctx() ctx: RequestContext, @Parent() refund: Refund): Promise<OrderItem[]> {
-    //     if (refund.orderItems) {
-    //         return refund.orderItems;
-    //     } else {
-    //         return this.orderService.getRefundOrderItems(ctx, refund.id);
-    //     }
-    // }
 }

+ 0 - 30
packages/core/src/entity/order-line/order-line.entity.ts

@@ -228,24 +228,6 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
         );
     }
 
-    /*@Calculated()
-    get quantity(): number {
-        return this.activeItems.length;
-    }*/
-
-    // @Calculated({relations: ['items']})
-    // get adjustments(): Adjustment[] {
-    //     return this.activeItems.reduce(
-    //         (adjustments, item) => [...adjustments, ...(item.adjustments || [])],
-    //         [] as Adjustment[],
-    //     );
-    // }
-
-    // @Calculated({relations: ['items']})
-    // get taxLines(): TaxLine[] {
-    //     return this.firstActiveItemPropOr('taxLines', []);
-    // }
-
     @Calculated()
     get taxRate(): number {
         return summate(this.taxLines, 'taxRate');
@@ -351,18 +333,6 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
         return this.proratedUnitTax * this.quantity;
     }
 
-    /**
-     * Returns all non-cancelled OrderItems on this line.
-     */
-    // get activeItems(): OrderItem[] {
-    //     if (this.items == null) {
-    //         Logger.warn(
-    //             `Attempted to access OrderLine.items without first joining the relation: `,
-    //         );
-    //     }
-    //     return (this.items || []).filter(i => !i.cancelled);
-    // }
-
     addAdjustment(adjustment: Adjustment) {
         this.adjustments = this.adjustments.concat(adjustment);
     }

+ 1 - 53
packages/core/src/service/helpers/order-calculator/order-calculator.ts

@@ -5,13 +5,11 @@ import { AdjustmentType } from '@vendure/common/lib/generated-types';
 import { RequestContext } from '../../../api/common/request-context';
 import { RequestContextCacheService } from '../../../cache/request-context-cache.service';
 import { InternalServerError } from '../../../common/error/errors';
-import { netPriceOf } from '../../../common/tax-utils';
 import { idsAreEqual } from '../../../common/utils';
 import { ConfigService } from '../../../config/config.service';
 import { OrderLine, TaxCategory, TaxRate } from '../../../entity';
 import { Order } from '../../../entity/order/order.entity';
 import { Promotion } from '../../../entity/promotion/promotion.entity';
-import { ShippingLine } from '../../../entity/shipping-line/shipping-line.entity';
 import { Zone } from '../../../entity/zone/zone.entity';
 import { ShippingMethodService } from '../../services/shipping-method.service';
 import { TaxRateService } from '../../services/tax-rate.service';
@@ -177,7 +175,7 @@ export class OrderCalculator {
      * @description
      * Applies promotions to OrderItems. This is a quite complex function, due to the inherent complexity
      * of applying the promotions, and also due to added complexity in the name of performance
-     * optimization. Therefore it is heavily annotated so that the purpose of each step is clear.
+     * optimization. Therefore, it is heavily annotated so that the purpose of each step is clear.
      */
     private async applyOrderItemPromotions(
         ctx: RequestContext,
@@ -188,21 +186,7 @@ export class OrderCalculator {
             // Must be re-calculated for each line, since the previous lines may have triggered promotions
             // which affected the order price.
             const applicablePromotions = await filterAsync(promotions, p => p.test(ctx, order).then(Boolean));
-
-            // const lineHasExistingPromotions = !!line.adjustments?.find(
-            //     a => a.type === AdjustmentType.PROMOTION,
-            // );
-            // const forceUpdateItems = this.orderLineHasInapplicablePromotions(applicablePromotions, line);
-            //
-            // if (forceUpdateItems || lineHasExistingPromotions) {
             line.clearAdjustments();
-            // }
-            // if (forceUpdateItems) {
-            //     // This OrderLine contains Promotion adjustments for Promotions that are no longer
-            //     // applicable. So we know for sure we will need to update these OrderItems in the
-            //     // DB. Therefore add them to the `updatedOrderItems` set.
-            //     line.items.forEach(i => updatedOrderItems.add(i));
-            // }
 
             for (const promotion of applicablePromotions) {
                 let priceAdjusted = false;
@@ -226,46 +210,11 @@ export class OrderCalculator {
                     this.addPromotion(order, promotion);
                 }
             }
-            // const lineNoLongerHasPromotions = !line?.adjustments?.find(
-            //     a => a.type === AdjustmentType.PROMOTION,
-            // );
-            // if (lineHasExistingPromotions && lineNoLongerHasPromotions) {
-            //     line.items.forEach(i => updatedOrderItems.add(i));
-            // }
-
-            // if (forceUpdateItems) {
-            // If we are forcing an update, we need to ensure that totals get
-            // re-calculated *even if* there are no applicable promotions (i.e.
-            // the other call to `this.calculateOrderTotals()` inside the `for...of`
-            // loop was never invoked).
             this.calculateOrderTotals(order);
-            // }
         }
         return;
     }
 
-    /**
-     * @description
-     * An OrderLine may have promotion adjustments from Promotions which are no longer applicable.
-     * For example, a coupon code might have caused a discount to be applied, and now that code has
-     * been removed from the order. The adjustment will still be there on each OrderItem it was applied
-     * to, even though that Promotion is no longer found in the `applicablePromotions` array.
-     *
-     * We need to know about this because it means that all OrderItems in the OrderLine must be
-     * updated.
-     */
-    // private orderLineHasInapplicablePromotions(applicablePromotions: Promotion[], line: OrderLine) {
-    //     const applicablePromotionIds = applicablePromotions.map(p => p.getSourceId());
-    //
-    //     const linePromotionIds = line.adjustments
-    //         .filter(a => a.type === AdjustmentType.PROMOTION)
-    //         .map(a => a.adjustmentSource);
-    //     const hasPromotionsThatAreNoLongerApplicable = !linePromotionIds.every(id =>
-    //         applicablePromotionIds.includes(id),
-    //     );
-    //     return hasPromotionsThatAreNoLongerApplicable;
-    // }
-
     private async applyOrderPromotions(
         ctx: RequestContext,
         order: Order,
@@ -282,7 +231,6 @@ export class OrderCalculator {
             // to be saved.
             order.lines.forEach(line => {
                 line.clearAdjustments(AdjustmentType.DISTRIBUTED_ORDER_PROMOTION);
-                // line.items.forEach(item => updatedItems.add(item));
             });
         }
 

+ 0 - 20
packages/core/src/service/helpers/order-modifier/order-modifier.ts

@@ -481,14 +481,6 @@ export class OrderModifier {
                         orderLineId: orderLine.id,
                         quantity: qtyDelta,
                     });
-                    // const cancelledOrderItems = orderLine.items.filter(i => i.cancelled).slice(0, qtyDelta);
-                    // refundInput.orderItems.push(...cancelledOrderItems);
-                    // modification.orderItems.push(...cancelledOrderItems);
-                } else {
-                    // const addedOrderItems = orderLine.items
-                    //     .filter(i => !i.cancelled)
-                    //     .slice(initialLineQuantity);
-                    // modification.orderItems.push(...addedOrderItems);
                 }
             }
             updatedOrderLineIds.push(orderLine.id);
@@ -640,18 +632,6 @@ export class OrderModifier {
             .getRepository(ctx, OrderModification)
             .save(modification);
         await this.connection.getRepository(ctx, Order).save(order);
-        // if (input.couponCodes) {
-        //     // When coupon codes have changed, this will likely affect the adjustments applied to
-        //     // OrderItems. So in this case we need to save all of them.
-        //     const orderItems = order.lines.reduce((all, line) => all.concat(line.items), [] as OrderItem[]);
-        //     await this.connection.getRepository(ctx, OrderItem).save(orderItems, { reload: false });
-        // } else {
-        //     // Otherwise, just save those OrderItems that were specifically added/removed
-        //     // or updated when applying `OrderCalculator.applyPriceAdjustments()`
-        //     await this.connection
-        //         .getRepository(ctx, OrderItem)
-        //         .save([...modification.orderItems, ...updatedOrderItems], { reload: false });
-        // }
         await this.connection.getRepository(ctx, ShippingLine).save(order.shippingLines, { reload: false });
         return { order, modification: createdModification };
     }

+ 0 - 44
packages/core/src/service/services/order.service.ts

@@ -1345,26 +1345,6 @@ export class OrderService {
         }
     }
 
-    // private async getAllocatedItems(ctx: RequestContext, items: OrderItem[]): Promise<OrderItem[]> {
-    //     const allocatedItems: OrderItem[] = [];
-    //     const allocationMap = new Map<ID, Allocation | false>();
-    //     for (const item of items) {
-    //         let allocation = allocationMap.get(item.lineId);
-    //         if (!allocation) {
-    //             allocation = await this.connection
-    //                 .getRepository(ctx, Allocation)
-    //                 .createQueryBuilder('allocation')
-    //                 .where('allocation.orderLine = :lineId', { lineId: item.lineId })
-    //                 .getOne();
-    //             allocationMap.set(item.lineId, allocation || false);
-    //         }
-    //         if (allocation && !item.fulfillment) {
-    //             allocatedItems.push(item);
-    //         }
-    //     }
-    //     return allocatedItems;
-    // }
-
     /**
      * @description
      * Creates a {@link Refund} against the order and in doing so invokes the `createRefund()` method of the
@@ -1384,30 +1364,6 @@ export class OrderService {
         if (1 < orders.length) {
             return new MultipleOrderError();
         }
-        // const refundLines = await this.connection
-        //     .getRepository(ctx, RefundLine)
-        //     .createQueryBuilder('refundLine')
-        //     .leftJoinAndSelect('refundLine.refund', 'refund')
-        //     .where('refundLine.orderLineId IN (:...orderLineIds)', {
-        //         orderLineIds: input.lines?.map(l => l.orderLineId) ?? [],
-        //     })
-        //     .andWhere('refund.state != :state', { state: 'Failed' })
-        //     .getMany();
-        // const orderLines = await this.connection
-        //     .getRepository(ctx, OrderLine)
-        //     .findByIds(input.lines?.map(l => l.orderLineId) ?? []);
-        // for (const lineInput of input.lines) {
-        //     const refundLinesForOrderLine = refundLines.filter(l =>
-        //         idsAreEqual(l.orderLineId, lineInput.orderLineId),
-        //     );
-        //     const orderLine = orderLines.find(l => idsAreEqual(l.id, lineInput.orderLineId));
-        //     const orderLineQuantity = orderLine ? orderLine.quantity - orderLine.cancelledCount : 0;
-        //     const quantityRefunded = summate(refundLinesForOrderLine, 'quantity');
-        //
-        //     if (orderLineQuantity - quantityRefunded < lineInput.quantity) {
-        //         return new QuantityTooGreatError();
-        //     }
-        // }
         const payment = await this.connection.getEntityOrThrow(ctx, Payment, input.paymentId, {
             relations: ['order'],
         });

+ 0 - 19
packages/core/src/service/services/stock-movement.service.ts

@@ -158,19 +158,6 @@ export class StockMovementService {
     async createSalesForOrder(ctx: RequestContext, lines: OrderLineInput[]): Promise<Sale[]> {
         const sales: Sale[] = [];
         const globalTrackInventory = (await this.globalSettingsService.getSettings(ctx)).trackInventory;
-        // const orderLinesMap = new Map<ID, { line: OrderLine; items: OrderItem[] }>();
-
-        // for (const orderItem of orderItems) {
-        //     let value = orderLinesMap.get(orderItem.lineId);
-        //     if (!value) {
-        //         const line = await this.connection.getEntityOrThrow(ctx, OrderLine, orderItem.lineId, {
-        //             relations: ['productVariant'],
-        //         });
-        //         value = { line, items: [] };
-        //         orderLinesMap.set(orderItem.lineId, value);
-        //     }
-        //     value.items.push(orderItem);
-        // }
         const orderLines = await this.connection
             .getRepository(ctx, OrderLine)
             .findByIds(lines.map(line => line.orderLineId));
@@ -258,12 +245,6 @@ export class StockMovementService {
      * reduced, indicating that this stock is once again available to buy.
      */
     async createReleasesForOrderLines(ctx: RequestContext, lineInputs: OrderLineInput[]): Promise<Release[]> {
-        // const orderItems = await this.connection.getRepository(ctx, OrderItem).findByIds(
-        //     items.map(i => i.id),
-        //     {
-        //         relations: ['line', 'line.productVariant'],
-        //     },
-        // );
         const releases: Release[] = [];
         const orderLines = await this.connection.getRepository(ctx, OrderLine).findByIds(
             lineInputs.map(line => line.orderLineId),