PrismaP
Prisma2mo ago
2 replies
kwiatek_123

Type 'DecimalJsLike' is not assignable to type 'Value'.

My models:
model Order {
  id          Int         @id @default(autoincrement())
  [...]
  orderItems  OrderItem[]
  paymentId   String      @unique
}

model OrderItem {
  id          Int     @id @default(autoincrement())
  orderId     Int
  order       Order   @relation(fields: [orderId], references: [id])
  [...]
  priceNetto  Decimal @db.Decimal(10, 2)
}

I need to calculate price for an entire order (sum of priceNetto of all order items) to generate paymentId. So I have a loop:
let finalPrice = new Prisma.Decimal(0);
for (let item of orderItemCreateManyOrderInput) {
  finalPrice = finalPrice.add(item.priceNetto);
}

The type of orderItemCreateManyOrderInput is of course Prisma.OrderItemCreateManyOrderInput[], because I have to create Order with all OrderItems after generating paymentId.

But I am getting an error inside a loop: Type 'DecimalJsLike' is not assignable to type 'Value'. in finalPrice.add(item.priceNetto);, because item.priceNetto is of type 'string | number | Decimal | DecimalJsLike'.

What should I do?
Was this page helpful?