1414 * limitations under the License.
1515 */
1616
17+ /**
18+ * @typedef {Object } TaskInfo
19+ * @property {string } id
20+ * @property {string } title
21+ * @property {string } notes
22+ * @property {boolean } completed
23+ */
24+
25+ /**
26+ * @typedef {object } HtmlOutput
27+ */
28+
29+ /**
30+ * @typedef {Object } TaskListInfo
31+ * @property {string } id
32+ * @property {string } name
33+ */
34+
1735/**
1836 * Special function that handles HTTP GET requests to the published web app.
1937 * @return {HtmlOutput } The HTML page to be served.
@@ -25,66 +43,82 @@ function doGet() {
2543
2644/**
2745 * Returns the ID and name of every task list in the user's account.
28- * @return {Array.<Object> } The task list data.
46+ * @return {TaskListInfo[] } The task list data.
2947 */
3048function getTaskLists ( ) {
31- var taskLists = Tasks . Tasklists . list ( ) . getItems ( ) ;
49+ if ( ! Tasks . Tasklists ) {
50+ return [ ] ;
51+ }
52+ const taskLists = Tasks . Tasklists . list ( ) . items ;
3253 if ( ! taskLists ) {
3354 return [ ] ;
3455 }
35- return taskLists . map ( function ( taskList ) {
36- return {
37- id : taskList . getId ( ) ,
38- name : taskList . getTitle ( )
39- } ;
40- } ) ;
56+ const result = [ ] ;
57+ for ( const taskList of taskLists ) {
58+ if ( taskList . id && taskList . title ) {
59+ result . push ( { id : taskList . id , name : taskList . title } ) ;
60+ }
61+ }
62+ return result ;
4163}
4264
4365/**
4466 * Returns information about the tasks within a given task list.
45- * @param {String } taskListId The ID of the task list.
46- * @return {Array.<Object> } The task data.
67+ * @param {string } taskListId The ID of the task list.
68+ * @return {TaskInfo[] } The task data.
4769 */
4870function getTasks ( taskListId ) {
49- var tasks = Tasks . Tasks . list ( taskListId ) . getItems ( ) ;
71+ if ( ! Tasks . Tasks ) {
72+ return [ ] ;
73+ }
74+ const tasks = Tasks . Tasks . list ( taskListId ) . items ;
5075 if ( ! tasks ) {
5176 return [ ] ;
5277 }
53- return tasks . map ( function ( task ) {
54- return {
55- id : task . getId ( ) ,
56- title : task . getTitle ( ) ,
57- notes : task . getNotes ( ) ,
58- completed : Boolean ( task . getCompleted ( ) )
59- } ;
60- } ) . filter ( function ( task ) {
61- return task . title ;
62- } ) ;
78+ const result = [ ] ;
79+ for ( const task of tasks ) {
80+ if ( task . id && task . title ) {
81+ result . push ( {
82+ id : task . id ,
83+ title : task . title ,
84+ notes : task . notes ?? '' ,
85+ completed : Boolean ( task . completed ) ,
86+ } ) ;
87+ }
88+ }
89+ return result ;
6390}
6491
6592/**
6693 * Sets the completed status of a given task.
67- * @param {String } taskListId The ID of the task list.
68- * @param {String } taskId The ID of the task.
69- * @param {Boolean } completed True if the task should be marked as complete, false otherwise.
94+ * @param {string } taskListId The ID of the task list.
95+ * @param {string } taskId The ID of the task.
96+ * @param {boolean } completed True if the task should be marked as complete, false otherwise.
7097 */
7198function setCompleted ( taskListId , taskId , completed ) {
72- var task = Tasks . newTask ( ) ;
99+ const task = Tasks . newTask ( ) ;
73100 if ( completed ) {
74- task . setStatus ( 'completed' ) ;
101+ task . status = 'completed' ;
75102 } else {
76- task . setStatus ( 'needsAction' ) ;
77- task . setCompleted ( null ) ;
103+ task . status = 'needsAction' ;
104+ ( /** @type {any } */ ( task ) ) . completed = null ;
105+ }
106+ if ( ! Tasks . Tasks ) {
107+ return ;
78108 }
79109 Tasks . Tasks . patch ( task , taskListId , taskId ) ;
80110}
81111
82112/**
83113 * Adds a new task to the task list.
84- * @param {String } taskListId The ID of the task list.
85- * @param {String } title The title of the new task.
114+ * @param {string } taskListId The ID of the task list.
115+ * @param {string } title The title of the new task.
86116 */
87117function addTask ( taskListId , title ) {
88- var task = Tasks . newTask ( ) . setTitle ( title ) ;
118+ const task = Tasks . newTask ( ) ;
119+ task . title = title ;
120+ if ( ! Tasks . Tasks ) {
121+ return ;
122+ }
89123 Tasks . Tasks . insert ( task , taskListId ) ;
90124}
0 commit comments