-
-
Notifications
You must be signed in to change notification settings - Fork 1
Adds Completed-By Column To Google Spreadsheets #15
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
Open
zapdos26
wants to merge
12
commits into
dev
Choose a base branch
from
add-completed-by
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3f307c3
Fixed error regarding how map() is not a function of getChores()
zapdos26 e9c6aa9
Updated so that when a chore is completed, the username and userid of…
zapdos26 5c03367
Fixed misspelling of packages
zapdos26 28ae71c
Added that the service account will need both read and write permissi…
zapdos26 ac6b681
Moved privatekey to local packages.
zapdos26 8bbd04b
End for loop when cells are located.
zapdos26 415e91b
Renamed markChoreUser() to setCompletedBy()
zapdos26 d977641
Added () around await getChores() to fix map() error
zapdos26 82c7c36
Added scope needed
zapdos26 a8d2964
Merge branches 'add-completed-by' and 'dev' of github.com:rpiambulanc…
zapdos26 e5b754f
Removed filter since its no longer necessary here.
zapdos26 0542dfc
Merge branch 'dev' into add-completed-by
justetz 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
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
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
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
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 |
|---|---|---|
| @@ -1,26 +1,86 @@ | ||
| //node packages | ||
| const {google} = require("googleapis"); | ||
| require("dotenv").config(); | ||
|
|
||
| //local packages | ||
| const { | ||
| app: { | ||
| client: { | ||
| chat: { update } | ||
| app: { | ||
| client: { | ||
| chat: { update } | ||
| } | ||
| } | ||
| } | ||
| } = require("./bolt.js"); | ||
| const privatekey = require("../keys/sheets-api.json"); | ||
|
|
||
| //globals | ||
| const TOKEN = process.env.SLACK_BOT_TOKEN; | ||
| const SPREADSHEET_ID = process.env.SPREADSHEET_ID; | ||
zapdos26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const GDRIVE_EMAIL = process.env.GDRIVE_EMAIL; | ||
|
|
||
| const jwtClient = new google.auth.JWT( | ||
| privatekey.client_email, | ||
| null, | ||
| privatekey.private_key, | ||
| ["https://www.googleapis.com/auth/spreadsheets"], | ||
| GDRIVE_EMAIL | ||
| ); | ||
|
|
||
| const setCompletedBy = async (user, date, choretext) => { | ||
| const sheets = google.sheets({ | ||
| version: "v4", | ||
| auth: jwtClient | ||
| }); | ||
|
|
||
| jwtClient.authorize(err => console.log(err ? err : "Successfully connected!")); | ||
|
|
||
| try { | ||
| const {data} = await sheets.spreadsheets.values.get({ | ||
| spreadsheetId: SPREADSHEET_ID, | ||
| range: "A2:B" | ||
| }); | ||
| for (let n = 0; n < data.values.length; n++) { | ||
ddbruce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (data.values[n][1] === choretext && data.values[n][0] === date) { | ||
| await sheets.spreadsheets.values.update({ | ||
| spreadsheetId: SPREADSHEET_ID, | ||
| range: `Sheet1!C${n + 2}:D${n + 2}`, | ||
| valueInputOption: 'USER_ENTERED', | ||
| resource: {values: [[user.name, user.id]]} | ||
| }); | ||
| break; | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
|
|
||
| //helper functions | ||
| const crossOffAndTag = (user, index, blocks) => { | ||
| const choreText = blocks[index + 2].text.text.replace(">", ""); | ||
| blocks[index + 2].text.text = `>~${choreText}~ Completed by <@${user}>`; | ||
| delete blocks[index + 2].accessory; | ||
| return blocks; | ||
| const choreText = blocks[index + 2].text.text.replace(">", ""); | ||
| blocks[index + 2].text.text = `>~${choreText}~ Completed by <@${user}>`; | ||
| delete blocks[index + 2].accessory; | ||
| return blocks; | ||
| }; | ||
|
|
||
| const markChoreDone = async (index, user, channel, ts, initialBlocks) => { | ||
| await setCompletedBy(user, formatDate(new Date(ts * 1000)), initialBlocks[parseInt(index) + 2] | ||
| .text.text.replace(">", "")); | ||
| const blocks = crossOffAndTag(user.id, parseInt(index), initialBlocks); | ||
| update({ token: TOKEN, channel, ts, blocks }); | ||
| }; | ||
|
|
||
| const markChoreDone = (index, user, channel, ts, initialBlocks) => { | ||
| const blocks = crossOffAndTag(user, parseInt(index), initialBlocks); | ||
| update({ token: TOKEN, channel, ts, blocks }); | ||
| const formatDate = (date) => { | ||
| var d = new Date(date), | ||
| month = '' + (d.getMonth() + 1), | ||
| day = '' + d.getDate(), | ||
| year = d.getFullYear(); | ||
|
|
||
| if (month.length < 2) | ||
| month = '0' + month; | ||
| if (day.length < 2) | ||
| day = '0' + day; | ||
|
|
||
| return [year, month, day].join('-'); | ||
| }; | ||
|
|
||
| module.exports = { markChoreDone }; | ||
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
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.