Skip to content

Commit

Permalink
issue coderbunker/timesheet-backend#22: use apikey, use calendarid as…
Browse files Browse the repository at this point in the history
… column name
  • Loading branch information
rngadam committed May 4, 2018
1 parent 5f094a8 commit 0dcaac1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions timesheet/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ function snapshot(spreadsheet, sheetNames, category) {
const exported = export(spreadsheet, sheetNames, category);
const snapshotEndpoint = PropertiesService.getScriptProperties().getProperty('SNAPSHOT_ENDPOINT');
const response = postData(spreadsheet.getId(), exported, snapshotEndpoint);
Logger.log('server response as follows: ');
Logger.log(response);
snapshotAllCalendarOfSpreadsheet(spreadsheet);
return response;
Expand Down
4 changes: 2 additions & 2 deletions timesheet/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ function snapshotAllCalendarOfSpreadsheet(spreadsheet) {
const responses = entries.map(function(entry) {
Logger.log(entry.resource);
Logger.log(entry.fullname);
if(!entry.calendar) {
if(!entry.calendarid) {
Logger.log('No calendar associated to %s', entry.resource);
return null;
}
const calendar = CalendarApp.getCalendarById(entry.calendarid);
if(!calendar) {
Logger.log('not a valid id: %s', entry.calendarid);
Logger.log('not a valid calendar id: %s', entry.calendarid);
return null;
}
return snapshotCalendar(calendar);
Expand Down
13 changes: 11 additions & 2 deletions timesheet/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ function doGet() {
function onOpen() {
const orgName = PropertiesService.getScriptProperties().getProperty('ORG_NAME');
const menu = SpreadsheetApp.getUi().createMenu(orgName)
if(getActiveSpreadsheet().getSheetByName('Accounts')) {
const spreadsheet = getActiveSpreadsheet();
if(spreadsheet.getSheetByName('Accounts')) {
menu.addItem('Snapshot Accounts & All Timesheets', 'snapshotAllTrigger');
}
if(getActiveSpreadsheet().getSheetByName('Timesheet')) {
if(spreadsheet.getSheetByName('Timesheet')) {
menu.addItem('Snapshot Timesheet and associated calendars', 'snapshotTrigger');
}
if(spreadsheet.getSheetByName('Accounts Receivable Transactions')) {
menu.addItem('Snapshot WaveApp', 'snapshotWaveApp');
}
menu.addToUi();
}

function snapshotWaveApp() {
const spreadsheet = getActiveSpreadsheet();
snapshot(spreadsheet, ['Accounts Receivable Transactions'], 'WaveApp');
}

function snapshotTrigger() {
const spreadsheet = getActiveSpreadsheet();
snapshot(spreadsheet, ['Timesheet', 'Balance'], 'Timesheet');
Expand Down
7 changes: 5 additions & 2 deletions timesheet/network.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
function postData(id, doc, endpoint) {
const apikey = PropertiesService.getScriptProperties().getProperty('APIKEY');
const options = {
method : 'post',
contentType: 'application/json',
payload: JSON.stringify({
id: id,
doc: doc
})
doc: doc,
apikey: apikey
}),
muteHttpExceptions: true
};
return UrlFetchApp.fetch(endpoint, options);
}

0 comments on commit 0dcaac1

Please sign in to comment.