mirror of
https://github.com/System-End/scraps.git
synced 2026-04-19 23:22:54 +00:00
remove sync
This commit is contained in:
parent
56f04978f3
commit
775c990a74
2 changed files with 1 additions and 65 deletions
|
|
@ -14,7 +14,6 @@ import slack from './routes/slack'
|
|||
import { startHackatimeSync } from './lib/hackatime-sync'
|
||||
import { startAirtableSync } from './lib/airtable-sync'
|
||||
import { startScrapsPayout } from './lib/scraps-payout'
|
||||
import { syncAllPhoneNumbers } from './lib/sync-phones'
|
||||
|
||||
const api = new Elysia()
|
||||
.use(authRoutes)
|
||||
|
|
@ -48,7 +47,4 @@ if (process.env.NODE_ENV !== 'development') {
|
|||
startScrapsPayout()
|
||||
} else {
|
||||
console.log('[STARTUP] Skipping background syncs in development mode')
|
||||
}
|
||||
|
||||
// Sync phone numbers from Hack Club Auth on startup
|
||||
// syncAllPhoneNumbers()
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
import { eq, and, isNull } from 'drizzle-orm'
|
||||
import { db } from '../db'
|
||||
import { usersTable } from '../schemas/users'
|
||||
import { shopOrdersTable } from '../schemas/shop'
|
||||
import { fetchUserIdentity } from './auth'
|
||||
|
||||
export async function syncAllPhoneNumbers() {
|
||||
console.log('[SYNC-PHONES] Starting phone number sync...')
|
||||
|
||||
try {
|
||||
const allUsers = await db
|
||||
.select({
|
||||
id: usersTable.id,
|
||||
username: usersTable.username,
|
||||
accessToken: usersTable.accessToken
|
||||
})
|
||||
.from(usersTable)
|
||||
|
||||
let updated = 0
|
||||
let failed = 0
|
||||
let ordersUpdated = 0
|
||||
|
||||
for (const u of allUsers) {
|
||||
if (!u.accessToken) {
|
||||
continue
|
||||
}
|
||||
|
||||
const identity = await fetchUserIdentity(u.accessToken)
|
||||
if (!identity) {
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
|
||||
const phone = identity.identity.phone_number || null
|
||||
if (phone) {
|
||||
await db
|
||||
.update(usersTable)
|
||||
.set({ phone, updatedAt: new Date() })
|
||||
.where(eq(usersTable.id, u.id))
|
||||
updated++
|
||||
|
||||
// Backfill phone on existing orders that don't have one
|
||||
const result = await db
|
||||
.update(shopOrdersTable)
|
||||
.set({ phone, updatedAt: new Date() })
|
||||
.where(and(
|
||||
eq(shopOrdersTable.userId, u.id),
|
||||
isNull(shopOrdersTable.phone)
|
||||
))
|
||||
.returning({ id: shopOrdersTable.id })
|
||||
ordersUpdated += result.length
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[SYNC-PHONES] Done. Updated ${updated} of ${allUsers.length} users, ${ordersUpdated} orders backfilled (${failed} failed)`)
|
||||
return { total: allUsers.length, updated, ordersUpdated, failed }
|
||||
} catch (err) {
|
||||
console.error('[SYNC-PHONES] Error syncing phone numbers:', err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue