Skip to content

Commit

Permalink
docs: update readme usage examples to use new, optimal apis
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusBolls committed Nov 6, 2024
1 parent 0208003 commit aca7690
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand All @@ -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')
);

Expand Down

0 comments on commit aca7690

Please sign in to comment.