From aca7690171dcdea1983c08d8c7e4e6d80a6dafd8 Mon Sep 17 00:00:00 2001 From: Linus Bolls Date: Wed, 6 Nov 2024 15:53:52 +0100 Subject: [PATCH] docs: update readme usage examples to use new, optimal apis --- README.md | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 1faf860..b040ec7 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,15 @@ async function main() { const groupRes = await splid.group.getByInviteCode(inviteCode); - const groupInfoRes = await splid.groupInfo.getByGroup( - groupRes.result.objectId - ); + const groupId = groupRes.result.objectId; - const entriesRes = await splid.entry.getByGroup(groupRes.result.objectId); + const members = await splid.person.getAllByGroup(groupId); + const expensesAndPayments = await splid.entry.getAllByGroup(groupId); - const membersRes = await splid.person.getByGroup(groupRes.result.objectId); + const balance = SplidClient.getBalance(people, expensesAndPayments); + const suggestedPayments = SplidClient.getSuggestedPayments(balance); - const expensesAndPayments = await splid.entry.getByGroup( - groupRes.result.objectId - ); + console.log(balance, suggestedPayments); } main(); ``` @@ -100,30 +98,18 @@ async function main() { const groupRes = await splid.group.getByInviteCode(inviteCode); - const groupInfoRes = await splid.groupInfo.getByGroup( - groupRes.result.objectId - ); + const groupId = groupRes.result.objectId; - const entriesRes = await splid.entry.getByGroup(groupRes.result.objectId); + const members = await splid.person.getAllByGroup(groupId); + const expensesAndPayments = await splid.entry.getAllByGroup(groupId); - const membersRes = await splid.person.getByGroup(groupRes.result.objectId); - - for (const entry of entriesRes.result.results) { - console.log(getEntryDescription(entry, membersRes.result.results)); + for (const entry of expensesAndPayments) { + console.log(getEntryDescription(entry, members)); } } main(); ``` -```typescript -// calculating members balances and suggested payments -const people = await splid.person.getAllByGroup(groupId); -const entries = await splid.entry.getAllByGroup(groupId); - -const balance = SplidClient.getBalance(people, entries); -const suggestedPayments = SplidClient.getSuggestedPayments(balance); -``` - ```typescript // updating group properties const groupInfoRes = await splid.groupInfo.getByGroup(groupId); @@ -154,9 +140,9 @@ groupInfo.wallpaperID = uploadRes.dataID; ```typescript // updating person properties -const membersRes = await splid.person.getByGroup(groupId); +const members = await splid.person.getAllByGroup(groupId); -const linus = membersRes.result.results.find((i) => i.name === 'Linus'); +const linus = members.find((i) => i.name === 'Linus'); linus.name = 'Alex'; linus.initials = 'A'; @@ -166,9 +152,9 @@ await splid.person.set(linus); ```typescript // updating entry properties -const entriesRes = await splid.entry.getByGroup(groupId); +const entries = await splid.entry.getAllByGroup(groupId); -const pizzaEntries = entriesRes.result.results.filter((i) => +const pizzaEntries = entries.filter((i) => i.title.toLowerCase().includes('pizza') );