-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Azure endpoint return all users from ioet #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cxcarvaj
merged 6 commits into
master
from
TT-537-azure-endpoint-doesnt-return-the-complete-users
Feb 16, 2022
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
67c6f70
Fix: Azure endpoint return all users from ioet
cxcarvaj 504a0f3
Fix: Azure endpoint return all users from ioet
cxcarvaj 55a06c2
refactor: Refactor of code smells
cxcarvaj bbf68f2
style: Changes requested by review
cxcarvaj 2a1dc12
style: Changes requested by reviews
cxcarvaj 462117f
style: Changes requested by Sandros review
cxcarvaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix: Azure endpoint return all users from ioet
- Loading branch information
commit 504a0f376cb25bdbd360340123b9ef798cb6ad3d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ const SlackClient = require('./slack_client'); | |
const { CLOCK_OUT_MESSAGE, CLOCK_OUT_MESSAGE_MIDNIGHT } = require('./constants'); | ||
|
||
const doClockOut = async (context) => { | ||
console.log( | ||
context.log( | ||
`I am going to check how many entries were not clocked out ${new Date()}` | ||
); | ||
|
||
|
@@ -23,52 +23,50 @@ const doClockOut = async (context) => { | |
const slackUsers = await SlackClient.findUsersInSlack(); | ||
|
||
const { resources: entries } = await timeEntryDao.getEntriesWithNoEndDate(); | ||
console.log(`Checking for time-entries that need to be clocked out`); | ||
context.log(`Checking for time-entries that need to be clocked out`); | ||
|
||
let totalClockOutsExecuted = 0; | ||
|
||
await Promise.all( | ||
entries.map(async (timeEntryAsJson) => { | ||
const timeEntry = new TimeEntry(timeEntryAsJson); | ||
const { userName, userEmail } = findUserData(users, timeEntry.timeEntry.owner_id); | ||
const { userName, userEmail } = findUserData( users, timeEntry.timeEntry.owner_id); | ||
cxcarvaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const userId = findSlackUserId(slackUsers, userEmail); | ||
if( userEmail === '[email protected]'){ | ||
if (timeEntry.needsToBeClockedOut()) { | ||
if (userId) { | ||
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE.replace('%user_name%', userName)); | ||
} | ||
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut(); | ||
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); | ||
totalClockOutsExecuted++; | ||
|
||
if (timeEntry.needsToBeClockedOut()) { | ||
if (userId) { | ||
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE.replace('%user_name%', userName)); | ||
} | ||
|
||
else if (timeEntry.needsToBeClockedOutMidnight()) { | ||
if (userId) { | ||
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName)); | ||
} | ||
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight(); | ||
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); | ||
totalClockOutsExecuted++; | ||
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut(); | ||
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); | ||
totalClockOutsExecuted++; | ||
|
||
} else if (timeEntry.needsToBeClockedOutMidnight()) { | ||
cxcarvaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (userId) { | ||
SlackClient.sendMessageToUser(userId,CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName)); | ||
cxcarvaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight(); | ||
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); | ||
totalClockOutsExecuted++; | ||
} | ||
|
||
}) | ||
); | ||
|
||
console.log( | ||
context.log( | ||
`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...` | ||
); | ||
}; | ||
|
||
|
||
const findUserData = (users, id) => { | ||
const user = users.find((user) => user.id === id); | ||
return user ? { userName: user.name.split(' ')[0], userEmail: (user.email) } : {}; | ||
return user | ||
? { userName: user.name.split(' ')[0], userEmail: user.email } | ||
: {}; | ||
}; | ||
|
||
const findSlackUserId = (slackUsers, email) => { | ||
const user = slackUsers.find((slackUser) => slackUser.email === email); | ||
return user ? user.id : null; | ||
}; | ||
doClockOut() | ||
|
||
module.exports = { doClockOut }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.