Skip to content

Commit

Permalink
feat: 🎸 add usersCount option in rotation to choose more users
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavarora14 committed Jun 5, 2022
1 parent c8a0386 commit 0333bf7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Command examples
- `/pickup rotation create standup --list={listId}` : Will create a round-robin rotation for standup and assign that list of people with that rotation
- `/pickup ?{message} --rotation={rotationId}` : Will pick next person from rotation and let them know why they are picked up with a message
- `/pickup --rotation-log --rotation={rotationId} @user`: Will add rotation log for the day, on the name of that person, to continue object of round-robin rotation
- `/pickup ?{message} --rotation={rotationId} --usersCount={usersCount}` : Will pick next persons as per count passed to rotation and let them know why they are picked up with a message

#### How to run the project on Slack?

Expand Down
9 changes: 6 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ app.command('/pickup', addRotationLog, createList, createRotation, async ({ comm
usersIds = membersResponse.members
}
const realUsers = await filterRealUsers(app, usersIds)
const onlineUsers = command.text.includes('--online') ? await filterOnlineUsers(app, realUsers) : realUsers
const userChosenId = isCommandWithRotation ? (await getUserFromRotation(onlineUsers)).id : getRandomItemFromList(onlineUsers).id;
const onlineUsers = command.text.includes('--online') ? await filterOnlineUsers(app, realUsers) : realUsers;
const { value: usersCount, text: newText } = getOptionFromText(command.text, 'usersCount');
command.text = newText
const userChosenId: string | Array<string> = isCommandWithRotation ? (await getUserFromRotation(onlineUsers, usersCount ? Number(usersCount) : undefined)).map(user => user.id) : getRandomItemFromList(onlineUsers).id;

const text = command.text.replace('--online', '').trim();

const message = text.length > 0 ? `you are picked up for: ${text}` : `you are picked up randomly by ${command.user_name}. But we don't know why 😔`;
await say(`Hey <@${userChosenId}> , ${message}`);

await say(`Hey ${Array.isArray(userChosenId) ? userChosenId.map(id => `<@${id}>`).join(' , ') : `<@${userChosenId}>`} , ${message}`);
});


Expand Down
4 changes: 2 additions & 2 deletions src/rotation/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getRotationMembers = async (rotationId: number) => {
return members.map(member => member.id);
}

const getUserFromRotation = async (users: any[]): Promise<any> => {
const getUserFromRotation = async (users: any[], usersCount: number = 0): Promise<Array<any>> => {
await database.$connect();

const usersInRotationLogs = await database.rotationLog.findMany({
Expand All @@ -38,7 +38,7 @@ const getUserFromRotation = async (users: any[]): Promise<any> => {

const usersWithCount = users.map(user => ({ user, count: usersInRotationLogs.filter(userInRotiationLog => userInRotiationLog.user.id === user.id).length }))
usersWithCount.sort((a, b) => a.count - b.count);
return usersWithCount[0].user;
return usersWithCount.slice(0, usersCount + 1).map(userWithCount => userWithCount.user);
}


Expand Down

0 comments on commit 0333bf7

Please sign in to comment.