Skip to content

Commit 2ff02e3

Browse files
authored
Feature/seed historical settleup timeline (#598)
* Add playwright cli, skills and basic MCPs * move utility methods to other files * update checksum
1 parent be32503 commit 2ff02e3

File tree

4 files changed

+367
-57
lines changed

4 files changed

+367
-57
lines changed

prisma/seed-checksum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
68c55e94fb8c2eaabe3e1ab07d491283865168df10d430ba0a6deb2d41fa9a64
1+
157cf91ec892d975f64aaf8ef567b06bdc5cfbd238a1ff3c59f92cdc4081d77f

prisma/seed.ts

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { createExpense, deleteExpense, editExpense } from '~/server/api/services
44
import { dummyData } from '~/dummies';
55
import { calculateParticipantSplit } from '~/store/addStore';
66
import assert from 'node:assert';
7-
import { BigMath } from '~/utils/numbers';
8-
import { DEFAULT_CATEGORY } from '~/lib/category';
7+
import { settleBalances } from './seedSettlement';
98

109
const prisma = new PrismaClient();
1110

@@ -57,6 +56,15 @@ async function createExpenses() {
5756
expense.addedBy,
5857
);
5958

59+
await prisma.expense.update({
60+
where: {
61+
id: res!.id,
62+
},
63+
data: {
64+
createdAt: expense.createdAt,
65+
},
66+
});
67+
6068
idLookup.set(idx, res!.id);
6169
}),
6270
);
@@ -103,52 +111,6 @@ async function deleteExpenses() {
103111
return prisma.expense.findMany({ include: { expenseParticipants: true } });
104112
}
105113

106-
async function settleBalances() {
107-
const groupBalances = await prisma.balanceView.findMany();
108-
const groupBalanceMap = Object.fromEntries(
109-
groupBalances.map((gb) => [`${gb.userId}-${gb.friendId}-${gb.groupId}-${gb.currency}`, gb]),
110-
);
111-
112-
await Promise.all(
113-
dummyData.balancesToSettle.map(async ([userId, friendId, groupId, currency]) => {
114-
const groupBalance = groupBalanceMap[`${userId}-${friendId}-${groupId}-${currency}`];
115-
116-
if (!groupBalance || groupBalance.amount === 0n) {
117-
console.warn(`No balance to settle for ${userId}, ${friendId}, ${groupId}, ${currency}`);
118-
return;
119-
}
120-
121-
const sender = 0n > groupBalance.amount ? friendId : userId;
122-
const receiver = 0n > groupBalance.amount ? userId : friendId;
123-
124-
await createExpense(
125-
{
126-
name: 'Settle up',
127-
amount: BigMath.abs(groupBalance.amount),
128-
currency,
129-
splitType: SplitType.SETTLEMENT,
130-
groupId,
131-
participants: [
132-
{
133-
userId: sender,
134-
amount: groupBalance.amount,
135-
},
136-
{
137-
userId: receiver,
138-
amount: -groupBalance.amount,
139-
},
140-
],
141-
paidBy: sender,
142-
category: DEFAULT_CATEGORY,
143-
},
144-
sender,
145-
);
146-
}),
147-
);
148-
149-
console.log('Finished settling balances');
150-
}
151-
152114
async function main() {
153115
// await prisma.user.deleteMany();
154116
// await prisma.expense.deleteMany();
@@ -161,7 +123,7 @@ async function main() {
161123
await createExpenses();
162124
await editExpenses();
163125
await deleteExpenses();
164-
await settleBalances();
126+
await settleBalances(prisma, dummyData.balancesToSettle);
165127
}
166128

167129
main()

0 commit comments

Comments
 (0)