From 77baf17557de289a80e8d9f11875f0f670b725c1 Mon Sep 17 00:00:00 2001 From: JihengLi Date: Mon, 23 Sep 2024 20:15:24 -0500 Subject: [PATCH] fix bugs of changing database and model in script --- scripts/cli-util/get-team.ts | 46 ++++---- scripts/cli-util/modify-team.ts | 188 ++++++++++++++++---------------- 2 files changed, 117 insertions(+), 117 deletions(-) diff --git a/scripts/cli-util/get-team.ts b/scripts/cli-util/get-team.ts index e1816ea0..1a9a46b7 100644 --- a/scripts/cli-util/get-team.ts +++ b/scripts/cli-util/get-team.ts @@ -38,10 +38,10 @@ export const handleGetTeam = async () => { name: 'Get schedule', value: 'get-schedule', }, - { - name: 'Get members', - value: 'get-members', - }, + // { + // name: 'Get members', + // value: 'get-members', + // }, { name: 'Get document', value: 'get-document', @@ -53,9 +53,9 @@ export const handleGetTeam = async () => { case 'get-schedule': await getSchedule(team); break; - case 'get-members': - await getMembers(team); - break; + // case 'get-members': + // await getMembers(team); + // break; case 'get-document': await getDocument(team); break; @@ -85,24 +85,24 @@ const getSchedule = async (team: TeamData) => { return promptAction(); }; -const getMembers = async (team: TeamData) => { - const memberIds = team.members; +// const getMembers = async (team: TeamData) => { +// const memberIds = team.members; - let count = 1; - for (const memberId of memberIds) { - const member: UserData | null = await User.findOne({ _id: memberId }); - if (!member) { - console.log(`Member ${count++}:`); - console.log('Member not found'); - } else { - console.log(`Member ${count++}:`); - console.log(`Name: ${member.name}`); - console.log(`Email: ${member.email}`); - } - } +// let count = 1; +// for (const memberId of memberIds) { +// const member: UserData | null = await User.findOne({ _id: memberId }); +// if (!member) { +// console.log(`Member ${count++}:`); +// console.log('Member not found'); +// } else { +// console.log(`Member ${count++}:`); +// console.log(`Name: ${member.name}`); +// console.log(`Email: ${member.email}`); +// } +// } - return promptAction(); -}; +// return promptAction(); +// }; const getDocument = async (team: TeamData) => { console.log('Team Document:'); diff --git a/scripts/cli-util/modify-team.ts b/scripts/cli-util/modify-team.ts index 4f531b10..fe2e3256 100644 --- a/scripts/cli-util/modify-team.ts +++ b/scripts/cli-util/modify-team.ts @@ -37,18 +37,18 @@ export const handleModifyTeam = async () => { name: 'Change Team Name', value: 'change-name', }, - { - name: 'Remove a member', - value: 'remove-member', - }, - { - name: 'Add a member', - value: 'add-member', - }, - { - name: 'Change invite code', - value: 'change-invite-code', - }, + // { + // name: 'Remove a member', + // value: 'remove-member', + // }, + // { + // name: 'Add a member', + // value: 'add-member', + // }, + // { + // name: 'Change invite code', + // value: 'change-invite-code', + // }, { name: 'Change devpost link', value: 'change-devpost-link', @@ -64,15 +64,15 @@ export const handleModifyTeam = async () => { case 'change-name': await changeName(team); break; - case 'remove-member': - await removeMember(team); - break; - case 'add-member': - await addMember(team); - break; - case 'change-invite-code': - await changeInviteCode(team); - break; + // case 'remove-member': + // await removeMember(team); + // break; + // case 'add-member': + // await addMember(team); + // break; + // case 'change-invite-code': + // await changeInviteCode(team); + // break; case 'change-devpost-link': await changeDevpostLink(team); break; @@ -92,79 +92,79 @@ const changeName = async (team: TeamData) => { return promptAction(); }; -const removeMember = async (team: TeamData) => { - const memberIds = team.members; - - if (memberIds.length === 0) { - console.log('Team has no members'); - return promptAction(); - } - - const members: UserData[] = await User.find({ _id: { $in: memberIds } }); - - const member = await select({ - message: `Select member to remove from ${team.name}`, - choices: [ - { - name: '⏪ Back', - value: null, - }, - ...members.map((mem, index) => ({ - name: `${index + 1}) ${mem.name}`, - value: mem._id, - })), - ], - }); - - if (!member) { - return promptAction(); - } - - await Team.updateOne({ _id: team._id }, { $pull: { members: member } }); - - console.log(`Member [${member}] removed from team [${team.name}]`); - return promptAction(); -}; - -const addMember = async (team: TeamData) => { - const memberIds = team.members; - - const members: UserData[] = await User.find({ _id: { $nin: memberIds }, team: null }); - - const member = await select({ - message: `Select member to add to ${team.name}`, - choices: [ - { - name: '⏪ Back', - value: null, - }, - ...members.map((mem, index) => ({ - name: `${index}) ${mem.name}`, - value: mem._id, - })), - ], - }); - - if (!member) { - return promptAction(); - } - - await Team.updateOne({ _id: team._id }, { $push: { members: member } }); - - console.log(`Member [${member}] added to team [${team.name}]`); - return promptAction(); -}; - -const changeInviteCode = async (team: TeamData) => { - const newInviteCode = await input({ - message: `Enter new invite code for ${team.name}`, - }); - - await Team.updateOne({ _id: team._id }, { joinCode: newInviteCode }); - - console.log('Invite code changed successfully'); - return promptAction(); -}; +// const removeMember = async (team: TeamData) => { +// const memberIds = team.members; + +// if (memberIds.length === 0) { +// console.log('Team has no members'); +// return promptAction(); +// } + +// const members: UserData[] = await User.find({ _id: { $in: memberIds } }); + +// const member = await select({ +// message: `Select member to remove from ${team.name}`, +// choices: [ +// { +// name: '⏪ Back', +// value: null, +// }, +// ...members.map((mem, index) => ({ +// name: `${index + 1}) ${mem.name}`, +// value: mem._id, +// })), +// ], +// }); + +// if (!member) { +// return promptAction(); +// } + +// await Team.updateOne({ _id: team._id }, { $pull: { members: member } }); + +// console.log(`Member [${member}] removed from team [${team.name}]`); +// return promptAction(); +// }; + +// const addMember = async (team: TeamData) => { +// const memberIds = team.members; + +// const members: UserData[] = await User.find({ _id: { $nin: memberIds }, team: null }); + +// const member = await select({ +// message: `Select member to add to ${team.name}`, +// choices: [ +// { +// name: '⏪ Back', +// value: null, +// }, +// ...members.map((mem, index) => ({ +// name: `${index}) ${mem.name}`, +// value: mem._id, +// })), +// ], +// }); + +// if (!member) { +// return promptAction(); +// } + +// await Team.updateOne({ _id: team._id }, { $push: { members: member } }); + +// console.log(`Member [${member}] added to team [${team.name}]`); +// return promptAction(); +// }; + +// const changeInviteCode = async (team: TeamData) => { +// const newInviteCode = await input({ +// message: `Enter new invite code for ${team.name}`, +// }); + +// await Team.updateOne({ _id: team._id }, { joinCode: newInviteCode }); + +// console.log('Invite code changed successfully'); +// return promptAction(); +// }; const changeDevpostLink = async (team: TeamData) => { const newDevpostLink = await input({