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)
}
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);
}
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?
2 Replies
Prisma AI Help
Prisma AI Help18h ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
kwiatek_123
kwiatek_123OP17h ago
Or maybe another question: Why type of priceNetto in CreateInput is 'string | number | Decimal | DecimalJsLike' instead of just Decimal?

Did you find this page helpful?