File tree Expand file tree Collapse file tree 8 files changed +25
-14
lines changed
app/api/programs/[programId] Expand file tree Collapse file tree 8 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,21 @@ export const GET = withWorkspace(
3333 } ,
3434 } ) ,
3535
36- prisma . sale . aggregate ( {
37- where,
36+ prisma . earnings . aggregate ( {
37+ where : {
38+ ...where ,
39+ type : "sale" ,
40+ } ,
3841 _sum : {
3942 amount : true ,
4043 } ,
4144 } ) ,
4245
43- prisma . sale . count ( {
44- where,
46+ prisma . earnings . count ( {
47+ where : {
48+ ...where ,
49+ type : "sale" ,
50+ } ,
4551 } ) ,
4652
4753 prisma . programEnrollment . count ( {
Original file line number Diff line number Diff line change @@ -21,8 +21,9 @@ export const GET = withWorkspace(
2121
2222 const { partnerId } = parsed ;
2323
24- const salesAmount = await prisma . sale . aggregate ( {
24+ const salesAmount = await prisma . earnings . aggregate ( {
2525 where : {
26+ type : "sale" ,
2627 programId,
2728 partnerId,
2829 createdAt : {
Original file line number Diff line number Diff line change @@ -21,9 +21,10 @@ export const GET = withWorkspace(
2121
2222 const { startDate, endDate } = getStartEndDates ( parsed ) ;
2323
24- const salesCount = await prisma . sale . groupBy ( {
24+ const salesCount = await prisma . earnings . groupBy ( {
2525 by : [ "status" ] ,
2626 where : {
27+ type : "sale" ,
2728 programId,
2829 status,
2930 partnerId,
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ export const GET = withWorkspace(
3232 programId,
3333 } ) ;
3434
35- const sales = await prisma . sale . findMany ( {
35+ const sales = await prisma . earnings . findMany ( {
3636 where : {
3737 programId,
38+ type : "sale" ,
3839 ...( status && { status } ) ,
3940 ...( customerId && { customerId } ) ,
4041 ...( payoutId && { payoutId } ) ,
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const updateSaleStatusAction = authActionClient
1818 const { workspace } = ctx ;
1919 const { saleId, status } = parsedInput ;
2020
21- const sale = await prisma . sale . findUniqueOrThrow ( {
21+ const sale = await prisma . earnings . findUniqueOrThrow ( {
2222 where : {
2323 id : saleId ,
2424 program : {
@@ -50,7 +50,7 @@ export const updateSaleStatusAction = authActionClient
5050 } ) ;
5151 }
5252
53- await prisma . sale . update ( {
53+ await prisma . earnings . update ( {
5454 where : {
5555 id : sale . id ,
5656 } ,
Original file line number Diff line number Diff line change 1- import "dotenv-flow/config" ;
21import { prisma } from "@dub/prisma" ;
32import { EventType } from "@dub/prisma/client" ;
3+ import "dotenv-flow/config" ;
44
55async function main ( ) {
66 const sales = await prisma . sale . findMany ( {
77 select : {
8+ id : true ,
89 programId : true ,
910 partnerId : true ,
1011 linkId : true ,
@@ -14,6 +15,7 @@ async function main() {
1415 eventId : true ,
1516 amount : true ,
1617 earnings : true ,
18+ currency : true ,
1719 status : true ,
1820 createdAt : true ,
1921 updatedAt : true ,
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ model Customer {
1616 createdAt DateTime @default (now () )
1717 updatedAt DateTime @updatedAt
1818
19- project Project @relation (fields : [projectId ] , references : [id ] , onDelete : Cascade )
20- link Link ? @relation (fields : [linkId ] , references : [id ] )
19+ project Project @relation (fields : [projectId ] , references : [id ] , onDelete : Cascade )
20+ link Link ? @relation (fields : [linkId ] , references : [id ] )
2121 sales Sale []
2222 earnings Earnings []
2323
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ model Earnings {
2626 type EventType
2727 amount Int ?
2828 quantity Int
29- earnings Int ?
30- // currency String
29+ earnings Int @default ( 0 )
30+ currency String ?
3131 status EarningsStatus @default (pending )
3232
3333 createdAt DateTime @default (now () )
You can’t perform that action at this time.
0 commit comments