()
| 7 | // npm run script /team/update-missing-invite-code |
| 8 | // npx tsx ./scripts/team/update-missing-invite-code.ts |
| 9 | async 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 | |
| 37 | main(); |
no test coverage detected
searching dependent graphs…