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(
33
33
} ,
34
34
} ) ,
35
35
36
- prisma . sale . aggregate ( {
37
- where,
36
+ prisma . earnings . aggregate ( {
37
+ where : {
38
+ ...where ,
39
+ type : "sale" ,
40
+ } ,
38
41
_sum : {
39
42
amount : true ,
40
43
} ,
41
44
} ) ,
42
45
43
- prisma . sale . count ( {
44
- where,
46
+ prisma . earnings . count ( {
47
+ where : {
48
+ ...where ,
49
+ type : "sale" ,
50
+ } ,
45
51
} ) ,
46
52
47
53
prisma . programEnrollment . count ( {
Original file line number Diff line number Diff line change @@ -21,8 +21,9 @@ export const GET = withWorkspace(
21
21
22
22
const { partnerId } = parsed ;
23
23
24
- const salesAmount = await prisma . sale . aggregate ( {
24
+ const salesAmount = await prisma . earnings . aggregate ( {
25
25
where : {
26
+ type : "sale" ,
26
27
programId,
27
28
partnerId,
28
29
createdAt : {
Original file line number Diff line number Diff line change @@ -21,9 +21,10 @@ export const GET = withWorkspace(
21
21
22
22
const { startDate, endDate } = getStartEndDates ( parsed ) ;
23
23
24
- const salesCount = await prisma . sale . groupBy ( {
24
+ const salesCount = await prisma . earnings . groupBy ( {
25
25
by : [ "status" ] ,
26
26
where : {
27
+ type : "sale" ,
27
28
programId,
28
29
status,
29
30
partnerId,
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ export const GET = withWorkspace(
32
32
programId,
33
33
} ) ;
34
34
35
- const sales = await prisma . sale . findMany ( {
35
+ const sales = await prisma . earnings . findMany ( {
36
36
where : {
37
37
programId,
38
+ type : "sale" ,
38
39
...( status && { status } ) ,
39
40
...( customerId && { customerId } ) ,
40
41
...( payoutId && { payoutId } ) ,
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const updateSaleStatusAction = authActionClient
18
18
const { workspace } = ctx ;
19
19
const { saleId, status } = parsedInput ;
20
20
21
- const sale = await prisma . sale . findUniqueOrThrow ( {
21
+ const sale = await prisma . earnings . findUniqueOrThrow ( {
22
22
where : {
23
23
id : saleId ,
24
24
program : {
@@ -50,7 +50,7 @@ export const updateSaleStatusAction = authActionClient
50
50
} ) ;
51
51
}
52
52
53
- await prisma . sale . update ( {
53
+ await prisma . earnings . update ( {
54
54
where : {
55
55
id : sale . id ,
56
56
} ,
Original file line number Diff line number Diff line change 1
- import "dotenv-flow/config" ;
2
1
import { prisma } from "@dub/prisma" ;
3
2
import { EventType } from "@dub/prisma/client" ;
3
+ import "dotenv-flow/config" ;
4
4
5
5
async function main ( ) {
6
6
const sales = await prisma . sale . findMany ( {
7
7
select : {
8
+ id : true ,
8
9
programId : true ,
9
10
partnerId : true ,
10
11
linkId : true ,
@@ -14,6 +15,7 @@ async function main() {
14
15
eventId : true ,
15
16
amount : true ,
16
17
earnings : true ,
18
+ currency : true ,
17
19
status : true ,
18
20
createdAt : true ,
19
21
updatedAt : true ,
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ model Customer {
16
16
createdAt DateTime @default (now () )
17
17
updatedAt DateTime @updatedAt
18
18
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 ] )
21
21
sales Sale []
22
22
earnings Earnings []
23
23
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ model Earnings {
26
26
type EventType
27
27
amount Int ?
28
28
quantity Int
29
- earnings Int ?
30
- // currency String
29
+ earnings Int @default ( 0 )
30
+ currency String ?
31
31
status EarningsStatus @default (pending )
32
32
33
33
createdAt DateTime @default (now () )
You can’t perform that action at this time.
0 commit comments