mirror of
https://github.com/ershisan99/www.git
synced 2025-12-17 05:19:23 +00:00
add refresh history by date endpoint
This commit is contained in:
50
scripts/refresh-history-by-date.ts
Normal file
50
scripts/refresh-history-by-date.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { syncHistoryByDateRange } from '@/server/api/routers/history'
|
||||
|
||||
async function refreshHistoryByDate(startDate?: string, endDate?: string) {
|
||||
try {
|
||||
console.log('Refreshing history by date range...')
|
||||
if (startDate) {
|
||||
console.log(`Start date: ${startDate}`)
|
||||
}
|
||||
if (endDate) {
|
||||
console.log(`End date: ${endDate}`)
|
||||
}
|
||||
|
||||
await syncHistoryByDateRange(startDate, endDate)
|
||||
console.log('History refresh completed successfully')
|
||||
} catch (err) {
|
||||
console.error('History refresh failed:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Parse command line arguments
|
||||
function parseArgs() {
|
||||
const args = process.argv.slice(2)
|
||||
let startDate: string | undefined
|
||||
let endDate: string | undefined
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--start-date' && i + 1 < args.length) {
|
||||
startDate = args[i + 1]
|
||||
i++
|
||||
} else if (args[i] === '--end-date' && i + 1 < args.length) {
|
||||
endDate = args[i + 1]
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
return { startDate, endDate }
|
||||
}
|
||||
|
||||
// Run if called directly
|
||||
if (require.main === module) {
|
||||
const { startDate, endDate } = parseArgs()
|
||||
|
||||
refreshHistoryByDate(startDate, endDate)
|
||||
.then(() => process.exit(0))
|
||||
.catch((err) => {
|
||||
console.error('Refresh failed:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user