Skip to content

Commit

Permalink
feat: receive sum as number
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Nov 28, 2024
1 parent 24a8dda commit 29c456d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pages/credits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@
$directus.request<{amount: number}[]>(readItems('gp_credits', {
filter: { user_id: { _eq: user.id } },
})),
$directus.request<[{sum: { amount: string }, date_created: 'datetime'}]>(aggregate('gp_credits_additions', {
$directus.request<[{sum: { amount: number }, date_created: 'datetime'}]>(aggregate('gp_credits_additions', {
query: { filter: { github_id: { _eq: user.external_identifier || 'admin' }, date_created: { _gte: '$NOW(-30 day)' } } },
groupBy: [ 'date_created' ],
aggregate: { sum: 'amount' },
})).then((additions) => {
return additions.map((addition) => {
const { sum, ...rest } = addition;
return { ...rest, amount: Number(sum.amount) };
return { ...rest, amount: sum.amount };
});
}),
$directus.request<[{sum: { amount: string }, date: 'datetime'}]>(aggregate('gp_credits_deductions', {
$directus.request<[{sum: { amount: number }, date: 'datetime'}]>(aggregate('gp_credits_deductions', {
query: { filter: { user_id: { _eq: user.id }, date: { _gte: '$NOW(-30 day)' } } },
groupBy: [ 'date' ],
aggregate: { sum: 'amount' },
})).then((deduction) => {
return deduction.map((addition) => {
const { sum, ...rest } = addition;
return { ...rest, amount: Number(sum.amount) };
return { ...rest, amount: sum.amount };
});
}),
$directus.request<[{count: number}]>(aggregate('gp_adopted_probes', {
Expand Down
6 changes: 3 additions & 3 deletions pages/probes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
query: { filter: { userId: { _eq: user.id } } },
aggregate: { count: '*' },
})),
$directus.request<[{ sum: { amount: string }, adopted_probe: string}]>(aggregate('gp_credits_additions', {
$directus.request<[{ sum: { amount: number }, adopted_probe: string}]>(aggregate('gp_credits_additions', {
query: { filter: { github_id: { _eq: user.external_identifier || 'admin' }, adopted_probe: { _null: false }, date_created: { _gte: '$NOW(-30 day)' } } },
groupBy: [ 'adopted_probe' ],
aggregate: { sum: 'amount' },
Expand All @@ -265,8 +265,8 @@
for (const addition of creditsAdditions) {
const { adopted_probe: adoptedProbe, sum: { amount } } = addition;
totalCredits.value += Number(amount);
creditsByProbeId[adoptedProbe] = creditsByProbeId[adoptedProbe] ? creditsByProbeId[adoptedProbe] + Number(amount) : Number(amount);
totalCredits.value += amount;
creditsByProbeId[adoptedProbe] = creditsByProbeId[adoptedProbe] ? creditsByProbeId[adoptedProbe] + amount : amount;
}
credits.value = creditsByProbeId;
Expand Down

0 comments on commit 29c456d

Please sign in to comment.