|
|
@@ -139,7 +139,7 @@ export class OrderService {
|
|
|
.addOrderBy('items.createdAt', 'ASC')
|
|
|
.getOne();
|
|
|
if (order) {
|
|
|
- order.lines.forEach((line) => {
|
|
|
+ order.lines.forEach(line => {
|
|
|
line.productVariant = translateDeep(
|
|
|
this.productVariantService.applyChannelPriceAndTax(line.productVariant, ctx),
|
|
|
ctx.languageCode,
|
|
|
@@ -179,8 +179,8 @@ export class OrderService {
|
|
|
.andWhere('order.customer.id = :customerId', { customerId })
|
|
|
.getManyAndCount()
|
|
|
.then(([items, totalItems]) => {
|
|
|
- items.forEach((item) => {
|
|
|
- item.lines.forEach((line) => {
|
|
|
+ items.forEach(item => {
|
|
|
+ item.lines.forEach(line => {
|
|
|
line.productVariant = translateDeep(line.productVariant, ctx.languageCode, [
|
|
|
'options',
|
|
|
]);
|
|
|
@@ -276,7 +276,7 @@ export class OrderService {
|
|
|
this.assertAddingItemsState(order);
|
|
|
this.assertNotOverOrderItemsLimit(order, quantity);
|
|
|
const productVariant = await this.getProductVariantOrThrow(ctx, productVariantId);
|
|
|
- let orderLine = order.lines.find((line) => {
|
|
|
+ let orderLine = order.lines.find(line => {
|
|
|
return (
|
|
|
idsAreEqual(line.productVariant.id, productVariantId) &&
|
|
|
JSON.stringify(line.customFields) === JSON.stringify(customFields)
|
|
|
@@ -347,7 +347,7 @@ export class OrderService {
|
|
|
const order = await this.getOrderOrThrow(ctx, orderId);
|
|
|
this.assertAddingItemsState(order);
|
|
|
const orderLine = this.getOrderLineOrThrow(order, orderLineId);
|
|
|
- order.lines = order.lines.filter((line) => !idsAreEqual(line.id, orderLineId));
|
|
|
+ order.lines = order.lines.filter(line => !idsAreEqual(line.id, orderLineId));
|
|
|
const updatedOrder = await this.applyPriceAdjustments(ctx, order);
|
|
|
await this.connection.getRepository(OrderLine).remove(orderLine);
|
|
|
return updatedOrder;
|
|
|
@@ -384,7 +384,7 @@ export class OrderService {
|
|
|
async removeCouponCode(ctx: RequestContext, orderId: ID, couponCode: string) {
|
|
|
const order = await this.getOrderOrThrow(ctx, orderId);
|
|
|
if (order.couponCodes.includes(couponCode)) {
|
|
|
- order.couponCodes = order.couponCodes.filter((cc) => cc !== couponCode);
|
|
|
+ order.couponCodes = order.couponCodes.filter(cc => cc !== couponCode);
|
|
|
await this.historyService.createHistoryEntryForOrder({
|
|
|
ctx,
|
|
|
orderId: order.id,
|
|
|
@@ -425,8 +425,8 @@ export class OrderService {
|
|
|
async getEligibleShippingMethods(ctx: RequestContext, orderId: ID): Promise<ShippingMethodQuote[]> {
|
|
|
const order = await this.getOrderOrThrow(ctx, orderId);
|
|
|
const eligibleMethods = await this.shippingCalculator.getEligibleShippingMethods(ctx, order);
|
|
|
- return eligibleMethods.map((eligible) => ({
|
|
|
- id: eligible.method.id as string,
|
|
|
+ return eligibleMethods.map(eligible => ({
|
|
|
+ id: eligible.method.id,
|
|
|
price: eligible.result.price,
|
|
|
priceWithTax: eligible.result.priceWithTax,
|
|
|
description: eligible.method.description,
|
|
|
@@ -438,7 +438,7 @@ export class OrderService {
|
|
|
const order = await this.getOrderOrThrow(ctx, orderId);
|
|
|
this.assertAddingItemsState(order);
|
|
|
const eligibleMethods = await this.shippingCalculator.getEligibleShippingMethods(ctx, order);
|
|
|
- const selectedMethod = eligibleMethods.find((m) => idsAreEqual(m.method.id, shippingMethodId));
|
|
|
+ const selectedMethod = eligibleMethods.find(m => idsAreEqual(m.method.id, shippingMethodId));
|
|
|
if (!selectedMethod) {
|
|
|
throw new UserInputError(`error.shipping-method-unavailable`);
|
|
|
}
|
|
|
@@ -517,7 +517,7 @@ export class OrderService {
|
|
|
const { items, orders } = await this.getOrdersAndItemsFromLines(
|
|
|
ctx,
|
|
|
input.lines,
|
|
|
- (i) => !i.fulfillment,
|
|
|
+ i => !i.fulfillment,
|
|
|
'error.create-fulfillment-items-already-fulfilled',
|
|
|
);
|
|
|
|
|
|
@@ -583,7 +583,7 @@ export class OrderService {
|
|
|
});
|
|
|
}
|
|
|
const items = lines.reduce((acc, l) => [...acc, ...l.items], [] as OrderItem[]);
|
|
|
- return unique(items.map((i) => i.fulfillment).filter(notNullOrUndefined), 'id');
|
|
|
+ return unique(items.map(i => i.fulfillment).filter(notNullOrUndefined), 'id');
|
|
|
}
|
|
|
|
|
|
async getFulfillmentOrderItems(id: ID): Promise<OrderItem[]> {
|
|
|
@@ -611,8 +611,8 @@ export class OrderService {
|
|
|
if (order.state === 'AddingItems' || order.state === 'ArrangingPayment') {
|
|
|
return true;
|
|
|
} else {
|
|
|
- const lines: OrderLineInput[] = order.lines.map((l) => ({
|
|
|
- orderLineId: l.id as string,
|
|
|
+ const lines: OrderLineInput[] = order.lines.map(l => ({
|
|
|
+ orderLineId: l.id,
|
|
|
quantity: l.quantity,
|
|
|
}));
|
|
|
return this.cancelOrderByOrderLines(ctx, input, lines);
|
|
|
@@ -630,7 +630,7 @@ export class OrderService {
|
|
|
const { items, orders } = await this.getOrdersAndItemsFromLines(
|
|
|
ctx,
|
|
|
lines,
|
|
|
- (i) => !i.cancelled,
|
|
|
+ i => !i.cancelled,
|
|
|
'error.cancel-order-lines-quantity-too-high',
|
|
|
);
|
|
|
if (1 < orders.length) {
|
|
|
@@ -648,7 +648,7 @@ export class OrderService {
|
|
|
|
|
|
// Perform the cancellation
|
|
|
await this.stockMovementService.createCancellationsForOrderItems(items);
|
|
|
- items.forEach((i) => (i.cancelled = true));
|
|
|
+ items.forEach(i => (i.cancelled = true));
|
|
|
await this.connection.getRepository(OrderItem).save(items, { reload: false });
|
|
|
|
|
|
const orderWithItems = await this.connection.getRepository(Order).findOne(order.id, {
|
|
|
@@ -662,7 +662,7 @@ export class OrderService {
|
|
|
orderId: order.id,
|
|
|
type: HistoryEntryType.ORDER_CANCELLATION,
|
|
|
data: {
|
|
|
- orderItemIds: items.map((i) => i.id),
|
|
|
+ orderItemIds: items.map(i => i.id),
|
|
|
reason: input.reason || undefined,
|
|
|
},
|
|
|
});
|
|
|
@@ -681,7 +681,7 @@ export class OrderService {
|
|
|
const { items, orders } = await this.getOrdersAndItemsFromLines(
|
|
|
ctx,
|
|
|
input.lines,
|
|
|
- (i) => !i.cancelled,
|
|
|
+ i => !i.cancelled,
|
|
|
'error.refund-order-lines-quantity-too-high',
|
|
|
);
|
|
|
if (1 < orders.length) {
|
|
|
@@ -703,7 +703,7 @@ export class OrderService {
|
|
|
state: order.state,
|
|
|
});
|
|
|
}
|
|
|
- if (items.some((i) => !!i.refundId)) {
|
|
|
+ if (items.some(i => !!i.refundId)) {
|
|
|
throw new IllegalOperationError('error.refund-order-item-already-refunded');
|
|
|
}
|
|
|
|
|
|
@@ -737,7 +737,7 @@ export class OrderService {
|
|
|
try {
|
|
|
await this.promotionService.validateCouponCode(couponCode, customer.id);
|
|
|
} catch (err) {
|
|
|
- order.couponCodes = order.couponCodes.filter((c) => c !== couponCode);
|
|
|
+ order.couponCodes = order.couponCodes.filter(c => c !== couponCode);
|
|
|
codesRemoved = true;
|
|
|
}
|
|
|
}
|
|
|
@@ -842,7 +842,7 @@ export class OrderService {
|
|
|
}
|
|
|
|
|
|
private getOrderLineOrThrow(order: Order, orderLineId: ID): OrderLine {
|
|
|
- const orderItem = order.lines.find((line) => idsAreEqual(line.id, orderLineId));
|
|
|
+ const orderItem = order.lines.find(line => idsAreEqual(line.id, orderLineId));
|
|
|
if (!orderItem) {
|
|
|
throw new UserInputError(`error.order-does-not-contain-line-with-id`, { id: orderLineId });
|
|
|
}
|
|
|
@@ -924,19 +924,19 @@ export class OrderService {
|
|
|
const items = new Map<ID, OrderItem>();
|
|
|
|
|
|
const lines = await this.connection.getRepository(OrderLine).findByIds(
|
|
|
- orderLinesInput.map((l) => l.orderLineId),
|
|
|
+ orderLinesInput.map(l => l.orderLineId),
|
|
|
{
|
|
|
relations: ['order', 'items', 'items.fulfillment', 'order.channels'],
|
|
|
order: { id: 'ASC' },
|
|
|
},
|
|
|
);
|
|
|
for (const line of lines) {
|
|
|
- const inputLine = orderLinesInput.find((l) => idsAreEqual(l.orderLineId, line.id));
|
|
|
+ const inputLine = orderLinesInput.find(l => idsAreEqual(l.orderLineId, line.id));
|
|
|
if (!inputLine) {
|
|
|
continue;
|
|
|
}
|
|
|
const order = line.order;
|
|
|
- if (!order.channels.some((channel) => channel.id === ctx.channelId)) {
|
|
|
+ if (!order.channels.some(channel => channel.id === ctx.channelId)) {
|
|
|
throw new EntityNotFoundError('Order', order.id);
|
|
|
}
|
|
|
if (!orders.has(order.id)) {
|
|
|
@@ -946,7 +946,7 @@ export class OrderService {
|
|
|
if (matchingItems.length < inputLine.quantity) {
|
|
|
throw new IllegalOperationError(noMatchesError);
|
|
|
}
|
|
|
- matchingItems.slice(0, inputLine.quantity).forEach((item) => {
|
|
|
+ matchingItems.slice(0, inputLine.quantity).forEach(item => {
|
|
|
items.set(item.id, item);
|
|
|
});
|
|
|
}
|