Fix formatting
This commit is contained in:
@ -1,29 +1,29 @@
|
||||
import Replay from '#models/replay'
|
||||
import {parseSentryLinkHeader, SentryPagination} from './Sentry.js'
|
||||
import { parseSentryLinkHeader, SentryPagination } from './Sentry.js'
|
||||
|
||||
import env from '#start/env'
|
||||
let recordsUpdated = 0
|
||||
const SENTRY_TOKEN = env.get('SENTRY_TOKEN')
|
||||
interface ApiResponse<T> {
|
||||
data: T;
|
||||
data: T
|
||||
// optionally, you can define `meta`, `errors`, etc. if your API returns them
|
||||
}
|
||||
export async function fetchBatch(url: string) {
|
||||
const options: RequestInit = {
|
||||
headers: {
|
||||
Authorization: `Bearer ${SENTRY_TOKEN}`
|
||||
}
|
||||
Authorization: `Bearer ${SENTRY_TOKEN}`,
|
||||
},
|
||||
}
|
||||
const req = await fetch(url, options)
|
||||
if (!req.ok) {
|
||||
throw new Error(`Request failed with status ${req.status}`);
|
||||
throw new Error(`Request failed with status ${req.status}`)
|
||||
}
|
||||
|
||||
const resp = await req.json() as ApiResponse<Replay[]>;
|
||||
const replays = resp.data;
|
||||
const resp = (await req.json()) as ApiResponse<Replay[]>
|
||||
const replays = resp.data
|
||||
const headers = req.headers
|
||||
|
||||
const cleanedData = replays.map(record => sanitizeInput(record, Replay.allowedFields))
|
||||
const cleanedData = replays.map((record) => sanitizeInput(record, Replay.allowedFields))
|
||||
|
||||
let updated = await Replay.updateOrCreateMany('id', cleanedData)
|
||||
recordsUpdated = recordsUpdated + updated.length
|
||||
@ -39,12 +39,14 @@ export async function fetchBatch(url: string) {
|
||||
}
|
||||
console.log('no more results')
|
||||
return { recordsUpdated }
|
||||
|
||||
}
|
||||
|
||||
function sanitizeInput(data: Record<string, any>, allowedFields: string[]) {
|
||||
return allowedFields.reduce((acc, key) => {
|
||||
if (key in data) acc[key] = data[key]
|
||||
return acc
|
||||
}, {} as Record<string, any>)
|
||||
return allowedFields.reduce(
|
||||
(acc, key) => {
|
||||
if (key in data) acc[key] = data[key]
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, any>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user