Skip to content

Commit

Permalink
fix bugs of changing database and model in script
Browse files Browse the repository at this point in the history
  • Loading branch information
JihengLi committed Sep 24, 2024
1 parent dc42758 commit 77baf17
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 117 deletions.
46 changes: 23 additions & 23 deletions scripts/cli-util/get-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -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:');
Expand Down
188 changes: 94 additions & 94 deletions scripts/cli-util/modify-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand All @@ -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({
Expand Down

0 comments on commit 77baf17

Please sign in to comment.