Skip to content

Instantly share code, notes, and snippets.

@lipis
Created December 26, 2022 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lipis/7564e99b6315a3940dbcb1a5c1a413a9 to your computer and use it in GitHub Desktop.
Save lipis/7564e99b6315a3940dbcb1a5c1a413a9 to your computer and use it in GitHub Desktop.
Prisma $extends
export const xprisma = prisma.$extends({
result: {
statistic: {
salaryPercent: {
needs: { revenue: true, salary: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.salary / statistic.revenue) * 100);
},
},
expensePercent: {
needs: { revenue: true, expense: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.expense / statistic.revenue) * 100);
},
},
recurrentPercent: {
needs: { revenue: true, recurrent: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.recurrent / statistic.revenue) * 100);
},
},
vendorPercent: {
needs: { revenue: true, vendor: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.vendor / statistic.revenue) * 100);
},
},
reportPercent: {
needs: { revenue: true, report: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.report / statistic.revenue) * 100);
},
},
incomePercent: {
needs: { revenue: true, income: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.income / statistic.revenue) * 100);
},
},
sharePercent: {
needs: { revenue: true, share: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.share / statistic.revenue) * 100);
},
},
reservePercent: {
needs: { revenue: true, reserve: true },
compute(statistic) {
return statistic.revenue === 0
? 0
: Math.abs((statistic.reserve / statistic.revenue) * 100);
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment