Skip to content

Commit

Permalink
fix network error
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Feb 6, 2025
1 parent 0980dfc commit 4e5ae4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/admin/import/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Td from '../../components/Td'

const SAVE_TRANSACTION = gql`
mutation SaveTransaction($_id: String, $timestamp: String, $email: String, $count: Int, $amountCents: Int, $coffeeGrams: Int, $description: String) {
transaction(_id: $_id, timestamp: $timestamp, email: $email, count: $count, amountCents: $amountCents, coffeGrams: $coffeGrams, description: $description)
transaction(_id: $_id, timestamp: $timestamp, email: $email, count: $count, amountCents: $amountCents, coffeeGrams: $coffeeGrams, description: $description)
}`

const GET_COST = gql`
Expand Down Expand Up @@ -45,7 +45,7 @@ type Variables = {
timestamp?: string
count?: number
amountCents?: number
coffeGrams?: number
coffeeGrams?: number
email?: string
description?: string
}
Expand Down Expand Up @@ -88,7 +88,7 @@ function parseRow(mapping: Mapping, cols: COLS, COST: number) {
if (mapped.grams) {
const grams = parseInt(mapped.grams)
if (`${grams}` !== mapped.grams) error ||= `invalid grams ${mapped.grams}`
variables.coffeGrams = grams
variables.coffeeGrams = grams
}

if (!mapped.count && !mapped.amount && !mapped.grams) error ||= `either count, grams or amount required`
Expand Down Expand Up @@ -150,7 +150,7 @@ function ImportWidget() {
<Th>timestamp</Th>
<Th>count</Th>
<Th>amountCents</Th>
<Th>coffeGrams</Th>
<Th>coffeeGrams</Th>
<Th>email</Th>
<Th>description</Th>
{Array.from({length: ncols}, (_,i) => i).map(i =>
Expand Down Expand Up @@ -179,7 +179,7 @@ function ImportWidget() {
<Td>{new Date(item.parse.timestamp||'').toLocaleString()}</Td>
<Td>{item.parse.count}</Td>
<Td>{item.parse.amountCents}</Td>
<Td>{item.parse.coffeGrams}</Td>
<Td>{item.parse.coffeeGrams}</Td>
<Td>{item.parse.email}</Td>
<Td>{item.parse.description}</Td>
{item.row.cols.map((cell, j) =>
Expand Down
8 changes: 4 additions & 4 deletions app/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const resolvers = {
_id: null,
creditCents: { $sum: "$amountCents" },
count: { $sum: "$count" },
coffeGrams: { $sum: "$coffeeGrams" },
coffeeGrams: { $sum: "$coffeeGrams" },
} }
]).toArray()
if (result.length === 0) return 0
return {
cents: result[0].creditCents,
count: result[0].count,
grams: result[0].coffeGrams
grams: result[0].coffeeGrams
}
},

Expand Down Expand Up @@ -121,10 +121,10 @@ export const resolvers = {
_id: "$email",
creditCents: { $sum: "$amountCents" },
count: { $sum: "$count" },
coffeGrams: { $sum: "$coffeeGrams" },
coffeeGrams: { $sum: "$coffeeGrams" },
timestamp: { $max: "$timestamp" },
}},
{ $project: { _id: 0, email: "$_id", creditCents: 1, count: 1, coffeGrams: 1, timestamp: 1 } },
{ $project: { _id: 0, email: "$_id", creditCents: 1, count: 1, coffeeGrams: 1, timestamp: 1 } },
{ $sort: { email: 1 } },
]).toArray()
// console.log(JSON.stringify(result))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm-coffee",
"version": "1.3.2",
"version": "1.3.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 4e5ae4a

Please sign in to comment.