-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlService.ts
52 lines (42 loc) · 1.74 KB
/
HtmlService.ts
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
46
47
48
49
50
51
52
// Setup code for the web app associated with this project.
// https://developers.google.com/apps-script/guides/html#code.gs_1
function doGet() {
return HtmlService.createTemplateFromFile('Index').evaluate();
}
function include(filename: string) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
const DEV_WEB_TEST = false;
const WEB_SHEET_ID = DEV_WEB_TEST ? TEST_SHEET_ID : SHEET_ID;
// NOTE for below functions: GAS HtmlService does not accept Date objects
// in inputs and outputs of these functions.
// Note that "Audit Dates"
/**
* Gets the chore statuses for the given week.
* @param auditDate The week to get data for, expressed as the due date (such that chores are due the next day at 5AM) in milliseconds since epoch.
*/
function webappGetWeek(auditDate: number) {
const report = getReport(WEB_SHEET_ID, new Date(auditDate));
return {
chores: report.chores
.map((chore) => ({
title: chore.description,
assignee: chore.person.name,
status: chore.auditWeekStatus,
})
)};
}
/**
* Sets the status for the given chore.
* @param auditDate The week that chores are due, expressed as the due date (such that chores are due the next day at 5AM) in milliseconds since epoch.
* @param person The name of the person whose chore should be updated.
* @param status The status to set for this chore on this week.
*/
function webappUpdateStatus(auditDate: number, person: string, status: string) {
const tracker = new TrackerModel(getChoresSheet(WEB_SHEET_ID));
const choresWeek = tracker.getWeek(new Date(auditDate));
const chore = choresWeek.find(c => c.name === person);
if (chore == null) throw new Error("Could not find " + person);
chore.statusCell.setValue(status);
}