content/hifi-content/Experiences/LoadTest/Checkin/DomainEnter_CheckEventbrite/GoogleScripts_CheckEventbrite/attendeeLookupAndCheckin.js
2022-02-13 23:16:46 +01:00

76 lines
No EOL
2 KiB
JavaScript

// Created by Robin Wilson 08-28-2018
var spreadsheetID = "1kLH8MbcOh50OlNIRs6GdEqvsgb3RIZMQda3gOhKprCw";
var worksheetName = "Auto_Checkin";
var spreadsheet = SpreadsheetApp.openById(spreadsheetID);
var sheet = spreadsheet.getSheetByName(worksheetName);
var data = sheet.getDataRange().getValues();
var col_Usernames = sheet.getRange("Usernames").getColumn();
var col_CheckedIn = sheet.getRange("Checkin").getColumn();
var success = ContentService.createTextOutput("Success");
var failureUsername = ContentService.createTextOutput("Not found username");
var failureError = ContentService.createTextOutput(JSON.stringify({ response: "There was a problem please let Hifi know" }));
// onDomainEnter
// Calls this method
function doGet(e) {
Logger.log(JSON.stringify(e));
var username = e.parameter.username,
date = e.parameter.date;
if (username) {
// search for username
var usernameRow = getUsernameRow(username);
if (usernameRow === -1) {
// no username found return false
return failureUsername;
} else {
// username found mark as present and return true
markPresent(usernameRow);
return success;
}
} else {
return failureError;
}
}
// ------ Helper functions ------ //
function markPresent(rowIdx) {
var cell = sheet.getRange(rowIdx + 1, col_CheckedIn); // index to column
cell.setValue([1]);
}
// return the row with the found username
function getUsernameRow(username) {
var searchUsername = username.toString().toLowerCase();
return search(searchUsername, col_Usernames);
}
// Search for searchTerm inside the searchCol
function search(searchTerm, searchCol) {
for (var row = 0; row < data.length; row++) {
var rowData = data[row];
var cur = rowData[searchCol - 1]; // convert column to index
if (cur) cur = cur.toLowerCase();
if (cur === searchTerm) return row;
}
return -1;
}