Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
neb-b committed Mar 22, 2023
1 parent af15548 commit 2cf7463
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/pages/api/debt.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import axios from "axios"
import { NextApiResponse, NextApiRequest } from "next"
import db from "core/db"
import axios from 'axios'
import { NextApiResponse, NextApiRequest } from 'next'
import db from 'core/db'

import type { DebtRecord } from "pages/index"
import type { DebtRecord } from 'pages/index'

const US_DEBT_API_URL =
"https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny?page[number]="
const PAGE = 75
'https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny?page[number]='
const PAGE = 76

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const {
query: { auth },
} = req

if (process.env.NODE_ENV === "production" && auth !== process.env.PING_AUTH) {
res.status(401).json({ error: "unauthorized" })
if (process.env.NODE_ENV === 'production' && auth !== process.env.PING_AUTH) {
res.status(401).json({ error: 'unauthorized' })
return
}

try {
const { data: dbData, error } = await db
.from<DebtRecord>("money")
.select("*")
.filter("us_debt", "is", null)
.order("id", { ascending: false })
.from<DebtRecord>('money')
.select('*')
.filter('us_debt', 'is', null)
.order('id', { ascending: false })

if (error) {
throw error
Expand All @@ -44,19 +44,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
})

if (!itemsToUpdate.length) {
res.status(200).json({ message: "No new data" })
res.status(200).json({ message: 'No new data' })
return
}

const { error: updateError } = await db.from("money").upsert(itemsToUpdate)
const { error: updateError } = await db.from('money').upsert(itemsToUpdate)

if (updateError) {
throw error
}

res.status(200).json({ status: "ok" })
res.status(200).json({ status: 'ok' })
} catch (error) {
console.log("error", error)
console.log('error', error)
res.status(500).json({ statusCode: 500, message: error.message })
}
}

0 comments on commit 2cf7463

Please sign in to comment.