Skip to content

Commit

Permalink
fix: handling connect or create logic for existing pricelist entries
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed Oct 7, 2024
1 parent 299807b commit 3fc57e7
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions pkg/integration-kencove-api/src/pricelists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ export class KencoveApiAppPricelistSyncService {
endDate: endDate ?? (undefined as any),
},
});
this.logger.info(
`Creating new price entry for SKU ${productVariant.sku} and ` +
`${pricelistEntry.pricelist_name}.`,
{
productVariantId: productVariant.id,
salesChannelId: salesChannel.id,
pricelistEntryId:
pricelistEntry.pricelist_item_id,
},
);
await this.db.kencoveApiPricelistItem.create({
data: {
id: pricelistEntry.pricelist_item_id.toString(),
Expand All @@ -350,35 +360,39 @@ export class KencoveApiAppPricelistSyncService {
},
},
salesChannelPriceEntry: {
connectOrCreate: {
where: {
id: existingSalesChannelPriceEntry?.id,
},
create: {
id: id.id("salesChannelPriceEntry"),
tenant: {
connect: {
id: this.kencoveApiApp
.tenantId,
},
},
salesChannel: {
connect: {
id: salesChannel.id,
},
},
productVariant: {
connect: {
id: productVariant.id,
},
},
startDate,
endDate,
price: pricelistEntry.price,
minQuantity:
pricelistEntry.min_quantity,
},
},
connect: existingSalesChannelPriceEntry?.id
? {
id: existingSalesChannelPriceEntry.id,
}
: undefined,
create: !existingSalesChannelPriceEntry?.id
? {
id: id.id(
"salesChannelPriceEntry",
),
tenant: {
connect: {
id: this.kencoveApiApp
.tenantId,
},
},
salesChannel: {
connect: {
id: salesChannel.id,
},
},
productVariant: {
connect: {
id: productVariant.id,
},
},
startDate,
endDate,
price: pricelistEntry.price,
minQuantity:
pricelistEntry.min_quantity,
}
: undefined,
},
},
});
Expand Down

0 comments on commit 3fc57e7

Please sign in to comment.