MCPcopy Create free account
hub / github.com/Orgnise/webapp / main

Function main

scripts/team/update-missing-invite-code.ts:9–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7// npm run script /team/update-missing-invite-code
8// npx tsx ./scripts/team/update-missing-invite-code.ts
9async function main() {
10 const client = await mongodb;
11 const teamCollection = client.db(databaseName).collection<TeamDbSchema>("teams");
12
13 console.log("\n-------------------- Teams --------------------\n");
14
15 // @ts-ignore
16 const teams = await teamCollection.find({ inviteCode: { $in: [null, undefined, ''] }, }).toArray();
17
18 if (teams.length > 0) {
19 console.log(`❌ ${teams.length} teams don't have invite code \n`);
20
21 if (teams.length > 0) {
22 for (let index = 0; index < teams.length; index++) {
23 const team = teams[index];
24 await teamCollection.updateOne({ _id: team._id }, { $set: { inviteCode: randomId() } });
25 }
26 }
27 console.log(`✅ Invite codes added for ${teams.length} teams.`);
28 } else {
29 console.log("✅ All teams have invite code");
30 }
31 console.log("------------------------------------------------\n");
32 client.close();
33 process.exit(0);
34}
35
36
37main();

Callers 1

Calls 1

randomIdFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…