mirror of
https://github.com/spliit-app/spliit.git
synced 2025-12-06 01:19:29 +01:00
Compare commits
3 Commits
0f4c96fc46
...
fc0feee736
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc0feee736 | ||
|
|
548a8dc5ee | ||
|
|
157ed4fd96 |
@@ -0,0 +1,5 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Activity" DROP CONSTRAINT "Activity_groupId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -116,7 +116,7 @@ model ExpensePaidFor {
|
||||
|
||||
model Activity {
|
||||
id String @id
|
||||
group Group @relation(fields: [groupId], references: [id])
|
||||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
||||
groupId String
|
||||
time DateTime @default(now())
|
||||
activityType ActivityType
|
||||
|
||||
@@ -81,7 +81,7 @@ const getDefaultSplittingOptions = (
|
||||
splitMode: 'EVENLY' as const,
|
||||
paidFor: group.participants.map(({ id }) => ({
|
||||
participant: id,
|
||||
shares: 1,
|
||||
shares: '1' as any, // Use string to ensure consistent schema handling
|
||||
})),
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ const getDefaultSplittingOptions = (
|
||||
splitMode: parsedDefaultSplitMode.splitMode,
|
||||
paidFor: parsedDefaultSplitMode.paidFor.map((paidFor) => ({
|
||||
participant: paidFor.participant,
|
||||
shares: paidFor.shares / 100,
|
||||
shares: (paidFor.shares / 100).toString() as any, // Convert to string for consistent schema handling
|
||||
})),
|
||||
}
|
||||
}
|
||||
@@ -197,10 +197,9 @@ export function ExpenseForm({
|
||||
paidBy: expense.paidById,
|
||||
paidFor: expense.paidFor.map(({ participantId, shares }) => ({
|
||||
participant: participantId,
|
||||
shares:
|
||||
expense.splitMode === 'BY_AMOUNT'
|
||||
? amountAsDecimal(shares, groupCurrency)
|
||||
: shares / 100,
|
||||
shares: (expense.splitMode === 'BY_AMOUNT'
|
||||
? amountAsDecimal(shares, groupCurrency)
|
||||
: (shares / 100).toString()) as any, // Convert to string to ensure consistent handling
|
||||
})),
|
||||
splitMode: expense.splitMode,
|
||||
saveDefaultSplittingOptions: false,
|
||||
@@ -226,7 +225,7 @@ export function ExpenseForm({
|
||||
searchParams.get('to')
|
||||
? {
|
||||
participant: searchParams.get('to')!,
|
||||
shares: 1,
|
||||
shares: '1' as any, // String for consistent form handling
|
||||
}
|
||||
: undefined,
|
||||
],
|
||||
@@ -359,9 +358,9 @@ export function ExpenseForm({
|
||||
if (!editedParticipants.includes(participant.participant)) {
|
||||
return {
|
||||
...participant,
|
||||
shares: Number(
|
||||
amountPerRemaining.toFixed(groupCurrency.decimal_digits),
|
||||
),
|
||||
shares: amountPerRemaining.toFixed(
|
||||
groupCurrency.decimal_digits,
|
||||
) as any, // Keep as string for consistent schema handling
|
||||
}
|
||||
}
|
||||
return participant
|
||||
@@ -825,11 +824,11 @@ export function ExpenseForm({
|
||||
? []
|
||||
: group.participants.map((p) => ({
|
||||
participant: p.id,
|
||||
shares:
|
||||
paidFor.find((pfor) => pfor.participant === p.id)
|
||||
?.shares ?? 1,
|
||||
shares: (paidFor.find(
|
||||
(pfor) => pfor.participant === p.id,
|
||||
)?.shares ?? '1') as any, // Use string to ensure consistent schema handling
|
||||
}))
|
||||
form.setValue('paidFor', newPaidFor, {
|
||||
form.setValue('paidFor', newPaidFor as any, {
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
shouldValidate: true,
|
||||
@@ -886,9 +885,9 @@ export function ExpenseForm({
|
||||
...field.value,
|
||||
{
|
||||
participant: id,
|
||||
shares: 1,
|
||||
shares: '1', // Use string to ensure consistent schema handling
|
||||
},
|
||||
],
|
||||
] as any,
|
||||
options,
|
||||
)
|
||||
: form.setValue(
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { RecurrenceRule, SplitMode } from '@prisma/client'
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
import * as z from 'zod'
|
||||
|
||||
export const groupFormSchema = z
|
||||
@@ -148,14 +150,14 @@ export const expenseFormSchema = z
|
||||
break // noop
|
||||
case 'BY_AMOUNT': {
|
||||
const sum = expense.paidFor.reduce(
|
||||
(sum, { shares }) => sum + Number(shares),
|
||||
0,
|
||||
(sum, { shares }) => new Decimal(shares).add(sum),
|
||||
new Decimal(0),
|
||||
)
|
||||
if (sum !== expense.amount) {
|
||||
const detail =
|
||||
sum < expense.amount
|
||||
? `${((expense.amount - sum) / 100).toFixed(2)} missing`
|
||||
: `${((sum - expense.amount) / 100).toFixed(2)} surplus`
|
||||
if (!sum.equals(new Decimal(expense.amount))) {
|
||||
// const detail =
|
||||
// sum < expense.amount
|
||||
// ? `${((expense.amount - sum) / 100).toFixed(2)} missing`
|
||||
// : `${((sum - expense.amount) / 100).toFixed(2)} surplus`
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'amountSum',
|
||||
|
||||
Reference in New Issue
Block a user