Skip to content

Commit

Permalink
fix: further bulk order updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed Nov 14, 2023
1 parent 6f58808 commit e5d2d65
Show file tree
Hide file tree
Showing 3 changed files with 24,277 additions and 23,318 deletions.
30 changes: 28 additions & 2 deletions pkg/integration-saleor-entities/src/orders/historicOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InstalledSaleorApp,
Language,
OrderLineItem,
OrderStatus as OrderStatusSchemabase,
PrismaClient,
Product,
ProductVariant,
Expand All @@ -19,6 +20,7 @@ import {
BulkOrderCreateMutationVariables,
LanguageCodeEnum,
OrderBulkCreateOrderLineInput,
OrderStatus,
SaleorClient,
} from "@eci/pkg/saleor";

Expand Down Expand Up @@ -69,6 +71,26 @@ export class SaleorHistoricOrdersSync {
};
}

/**
* From schemabase order status to saleor order status
* @param orderStatus
* @returns
*/
private schemabaseOrderStatusToSaleorOrderStatus(
orderStatus: OrderStatusSchemabase,
): OrderStatus {
const orderStatusMapping: {
[key in OrderStatusSchemabase]: OrderStatus;
} = {
[OrderStatusSchemabase.canceled]: OrderStatus.Canceled,
[OrderStatusSchemabase.closed]: OrderStatus.Fulfilled,
[OrderStatusSchemabase.confirmed]: OrderStatus.Unfulfilled,
[OrderStatusSchemabase.draft]: OrderStatus.Draft,
[OrderStatusSchemabase.unconfirmed]: OrderStatus.Unconfirmed,
};
return orderStatusMapping[orderStatus];
}

private schemabaseLanguageToSaleorLanguage(
language: Language,
): LanguageCodeEnum {
Expand Down Expand Up @@ -200,6 +222,9 @@ export class SaleorHistoricOrdersSync {
try {
const orderInput: BulkOrderCreateMutationVariables["orders"] =
orders.map((order) => ({
status: this.schemabaseOrderStatusToSaleorOrderStatus(
order.orderStatus,
),
channel: this.installedSaleorApp.channelSlug || "",
externalReference: order.orderNumber,
currency: order.currency,
Expand Down Expand Up @@ -234,7 +259,7 @@ export class SaleorHistoricOrdersSync {

for (const chunk of chunks) {
this.logger.debug("Sending bulkOrderCreate request", {
chunk,
chunk: JSON.stringify(chunk),
});
const bulkOrderCreateResponse =
await this.saleorClient.bulkOrderCreate({
Expand Down Expand Up @@ -270,7 +295,8 @@ export class SaleorHistoricOrdersSync {
.results) {
if (!result?.order?.id) {
this.logger.error(
`No order id in bulkOrderCreate response. This should never happen`, {
`No order id in bulkOrderCreate response. This should never happen`,
{
order: JSON.stringify(result.order),
},
);
Expand Down
Loading

1 comment on commit e5d2d65

@vercel
Copy link

@vercel vercel bot commented on e5d2d65 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.