all repos — stealth-developers @ main

apps/migration/src/3.get-users.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
import type { UserResponse } from "@purrkit/types";

import fs from "node:fs";

import { rest } from "./lib/rest";

const missingUserIds = JSON.parse(
	fs.readFileSync("./members/missing-users.json", "utf8"),
) as string[];

const out: { users: UserResponse[]; errors: any[] } = {
	users: [],
	errors: [],
};

for (const userId of missingUserIds) {
	const user = await rest.users(userId).get();
	if (user.ok) {
		out.users.push(user.data);
		process.stdout.cursorTo(0);
		process.stdout.write(`Fetched ${out.users.length}/${missingUserIds.length} users`);
	} else {
		console.error(`Failed to fetch user ${userId}:`, user.status, user.data);
		out.errors.push({ userId, status: user.status, data: user.data });
	}
}

fs.writeFileSync("./members/fetched-users.json", JSON.stringify(out, null, 2));