-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gs
45 lines (35 loc) · 1.15 KB
/
main.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Tent API Backend
// Trigger: onFormSubmit -> onSubmit(e)
function removeNullsFromArray(arr) {
if (!Array.isArray(arr)) {
throw new Error('Input is not an array.');
}
return arr.filter(element => element !== null && element !== undefined);
}
function getJsonMusicQueue() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const data = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
const objectArray = [];
for (let i = 1; i < data.length; i++) {
const item = {};
const headerlist = ["time_stamp", "mail", "song_name", "artist_name", "uuid"]
for (let j = 0; j < data[0].length; j++) {
item[headerlist[j]] = data[i][j];
}
objectArray.push(item);
}
const modifiedJson = {
contents: removeNullsFromArray(objectArray)
};
const json = JSON.stringify(modifiedJson);
return json;
}
const doGet = (e) => {
return ContentService.createTextOutput(getJsonMusicQueue());
}
function onSubmit(e) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange(e.range.getRow(), 5).setValue(Utilities.getUuid());
}