Skip to content

Commit 5d9346c

Browse files
Add user repair scripts and update README with usage instructions
1 parent 753e064 commit 5d9346c

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ See the [Gearbox-Terraform](https://github.com/Decatur-Robotics/Gearbox-Terrafor
6969

7070
1. Run `npm run test`
7171

72+
#### Scripts
73+
74+
There's a few scripts in the /scripts folder that can be run with `npx tsx scripts/<script_name>.ts`.
75+
7276
## Contributing
7377

7478
You've made it past set up and are ready to contibure to the future of scouting - here's how.

scripts/loadUsersIntoResend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ async function loadUsersIntoResend() {
2626
}
2727

2828
console.log("Done!");
29+
30+
process.exit(0); // Needed to avoid having to Ctrl+C the script
2931
}
3032

3133
loadUsersIntoResend();

scripts/repairUsers.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import CollectionId from "@/lib/client/CollectionId";
2+
import { getDatabase } from "@/lib/MongoDB";
3+
import { repairUser } from "@/lib/Utils";
4+
5+
async function repairUsers() {
6+
console.log("Getting database...");
7+
const db = await getDatabase();
8+
9+
console.log("Getting all incomplete users...");
10+
11+
const users = await db.findObjects(CollectionId.Users, {
12+
$or: [
13+
{ name: { $exists: false } },
14+
{ image: { $exists: false } },
15+
{ slackId: { $exists: false } },
16+
{ onboardingComplete: { $exists: false } },
17+
{ admin: { $exists: false } },
18+
{ teams: { $exists: false } },
19+
{ owner: { $exists: false } },
20+
],
21+
});
22+
23+
console.log(`Found ${users.length} incomplete users`);
24+
25+
for (let i = 0; i < users.length; i++) {
26+
const user = users[i];
27+
console.log(`Repairing user ${user._id} (${i + 1}/${users.length})`);
28+
await repairUser(db, user);
29+
}
30+
31+
console.log("Done!");
32+
33+
process.exit(0); // Needed to avoid having to Ctrl+C the script
34+
}
35+
36+
repairUsers();

tests/lib/Utils.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,15 @@ describe(repairUser.name, () => {
223223

224224
const user = {
225225
_id: new ObjectId() as unknown as string,
226-
226+
227227
};
228228

229229
await repairUser(db, user, false);
230230

231-
const foundUser = await db.findObjectById(CollectionId.Users, new ObjectId(user._id));
231+
const foundUser = await db.findObjectById(
232+
CollectionId.Users,
233+
new ObjectId(user._id),
234+
);
232235
expect(foundUser).toBeUndefined();
233236
});
234237

@@ -242,7 +245,7 @@ describe(repairUser.name, () => {
242245

243246
const repairedUser = await repairUser(db, user, false);
244247

245-
expect(repairedUser._id).toBe(user.id);
248+
expect(repairedUser._id?.toString()).toBe(user.id);
246249
});
247250

248251
test("Adds a default name when the name and email is missing", async () => {

0 commit comments

Comments
 (0)