updateEE
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { SplitType } from "@/lib/store/expense-store";
|
||||
import type { z } from "zod";
|
||||
import { expenseSplitSchema } from "../validations/expense";
|
||||
import type { ExpenseSplit } from "@/server/db/schema";
|
||||
|
||||
const debtSchema = expenseSplitSchema.pick({
|
||||
owedFromId: true,
|
||||
@@ -118,3 +119,24 @@ export function calculateDepts(
|
||||
|
||||
return debts;
|
||||
}
|
||||
|
||||
export const calculateTotalValue: (
|
||||
userId: string,
|
||||
splits: Array<ExpenseSplit>
|
||||
) => {
|
||||
owed: number;
|
||||
owes: number;
|
||||
} = (userId, splits) => {
|
||||
let owed = 0;
|
||||
let owes = 0;
|
||||
|
||||
splits.forEach((split) => {
|
||||
if (split.owedToId === userId) {
|
||||
owes += Number(split.amount); // You are the debitor
|
||||
} else if (split.owedFromId === userId) {
|
||||
owed += Number(split.amount); // You are the creditor
|
||||
}
|
||||
});
|
||||
|
||||
return { owed, owes };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user