Kenny Tran
10/01/2022, 1:24 PMmodel Sale {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
date String
time String
revenue Int
amount Int
invoice String
}
After I fetch using prisma.sale.findMany({})
I want to calculate the commission against some percentage and add an addition commission field. How would I add the type of the additional field to the client so that I can consume it there?
Would it be possible to do something like -
type Sale = Prisma.SaleGetPayload<{
include: {
commission: float
}
}>
The reason why the commission field isn't in the sales model in the first place is because the commission percentage is not persistant and might change depending on other factors. So it needs to be calculated before it gets passed further. I hope that makes sense.
Any help is appreciatedJarupong
10/01/2022, 1:48 PMJarupong
10/01/2022, 1:50 PM_sum
aggregation field
https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizingKenny Tran
10/01/2022, 1:57 PMKenny Tran
10/01/2022, 1:59 PMsum
calculates based on existing data. What I'm trying to do is to first fetch the data on the server. (I'm using Next.js API) then calculate the commission based on the revenue like so for example. commission = revenue * 0.05
then I would add this commission as a field of the data but I'm afraid Prisma might not know the type as it's originally generated like so -
model Sale {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
date String
time String
revenue Int
amount Int
invoice String
}
Kenny Tran
10/01/2022, 2:00 PMmodel Sale {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
date String
time String
revenue Int
amount Int
invoice String
commission Float
}
Jarupong
10/01/2022, 2:01 PMJarupong
10/01/2022, 2:02 PMKenny Tran
10/01/2022, 2:04 PMKenny Tran
10/01/2022, 2:05 PMJarupong
10/01/2022, 2:06 PM_sum
directly.Jarupong
10/01/2022, 2:06 PMJarupong
10/01/2022, 2:07 PMKenny Tran
10/01/2022, 2:08 PM