mirror of
https://github.com/SrIzan10/hctv.git
synced 2026-06-06 00:56:56 +00:00
fix(platform): actually check idv status
i'm sorry
This commit is contained in:
@@ -18,11 +18,13 @@
|
||||
"db:generate": "prisma generate",
|
||||
"db:migrate": "prisma migrate dev",
|
||||
"db:deploy": "prisma migrate deploy",
|
||||
"db:populate-verification": "tsx src/populateHackClubVerification.ts",
|
||||
"build": "prisma generate && tsc --build",
|
||||
"dev": "tsc --watch --preserveWatchOutput"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.0.1",
|
||||
"tsx": "^4.7.1",
|
||||
"typescript": "^5.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "User"
|
||||
ADD COLUMN "hackClubVerificationCheckedAt" TIMESTAMP(3),
|
||||
ADD COLUMN "hackClubVerificationResult" TEXT;
|
||||
@@ -22,6 +22,9 @@ model User {
|
||||
email String?
|
||||
pfpUrl String
|
||||
|
||||
hackClubVerificationResult String?
|
||||
hackClubVerificationCheckedAt DateTime?
|
||||
|
||||
hasOnboarded Boolean @default(false)
|
||||
isAdmin Boolean @default(false)
|
||||
|
||||
|
||||
93
packages/db/src/populateHackClubVerification.ts
Normal file
93
packages/db/src/populateHackClubVerification.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { prisma } from './client.js';
|
||||
|
||||
const HACK_CLUB_CHECK_URL = 'https://auth.hackclub.com/api/external/check';
|
||||
|
||||
type HackClubCheckResult =
|
||||
| 'needs_submission'
|
||||
| 'pending'
|
||||
| 'verified_eligible'
|
||||
| 'verified_but_over_18'
|
||||
| 'rejected'
|
||||
| 'not_found';
|
||||
|
||||
type HackClubCheckResponse = {
|
||||
result: HackClubCheckResult;
|
||||
};
|
||||
|
||||
async function fetchVerificationResult(user: {
|
||||
id: string;
|
||||
email: string | null;
|
||||
slack_id: string;
|
||||
}) {
|
||||
const query = new URLSearchParams();
|
||||
|
||||
if (user.email) {
|
||||
query.set('email', user.email);
|
||||
} else {
|
||||
query.set('slack_id', user.slack_id);
|
||||
}
|
||||
|
||||
const response = await fetch(`${HACK_CLUB_CHECK_URL}?${query.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Hack Club check failed for user ${user.id}: ${response.status}`);
|
||||
}
|
||||
|
||||
return (await response.json()) as HackClubCheckResponse;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const users = await prisma.user.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
slack_id: true,
|
||||
},
|
||||
orderBy: {
|
||||
id: 'asc',
|
||||
},
|
||||
});
|
||||
|
||||
if (users.length === 0) {
|
||||
console.log('No users found.');
|
||||
return;
|
||||
}
|
||||
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const user of users) {
|
||||
if (!user.email && !user.slack_id) {
|
||||
console.warn(`Skipping user ${user.id}: no email or Slack ID available.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetchVerificationResult(user);
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
hackClubVerificationResult: result.result,
|
||||
hackClubVerificationCheckedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
updatedCount += 1;
|
||||
console.log(`Updated ${user.id} (${user.email ?? user.slack_id}) -> ${result.result}`);
|
||||
} catch (error) {
|
||||
console.error(`Failed to update ${user.id}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Finished updating ${updatedCount} of ${users.length} users.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((error) => {
|
||||
console.error('Failed to populate Hack Club verification data:', error);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user