/**
 * -------------------------------------------------------------------------------------------
 * Copyright (c) Microsoft Corporation.  All Rights Reserved.  Licensed under the MIT License.
 * See License in the project root for license information.
 * -------------------------------------------------------------------------------------------
 */ import { DateTimeTimeZone , ItemBody , PatternedRecurrence } from '@microsoft/microsoft-graph-types' ; import { IGraph , prepScopes } from '@microsoft/mgt-element' ; export interface LinkedResource { id : string ; webUrl : string ; applicationName : string ; displayName : string ; externalId : string ; } export enum TaskStatus { notStarted , inProgress , completed , deferred , waitingOnOthers } export enum TaskImportance { low , normal , high } export enum WellknownListName { none , default , flaggedEmails , unknownFutureValue } export interface TodoTask { id : string ; title : string ; body : ItemBody ; importance : TaskImportance ; status : TaskStatus ; createdDateTime : Date ; completedDateTime : DateTimeTimeZone ; lastModifiedDate : Date ; bodyLastModifiedDateTime : Date ; dueDateTime : DateTimeTimeZone ; isReminderOn : boolean ; reminderDateTime : DateTimeTimeZone ; recurrence : PatternedRecurrence ; linkedResources : LinkedResource [ ] ; } export interface TodoTaskList { id : string ; displayName : string ; tasks : TodoTask [ ] ; isOwner : boolean ; isShared : boolean ; wellknownName : WellknownListName ; } export param { IGraph } graph param { string } listId returns { Promise < TodoTask [ ] > } export async function getTodoTasks ( graph , listId ) { const tasks = await graph . api ( `/me/todo/lists/${ listId }/tasks` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.Read' ) ) . get ( ) ; return tasks && tasks . value ; } export param { IGraph } graph param { string } listId param { string } taskId returns { Promise < TodoTask > } export async function getTodoTask ( graph , listId , taskId ) { const task = await graph . api ( `/me/todo/lists/${ listId }/tasks/${ taskId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.Read' ) ) . get ( ) ; return task ; } export param { IGraph } graph returns { Promise < TodoTaskList [ ] > } export async function getTodoTaskLists ( graph ) { const taskLists = await graph . api ( '/me/todo/lists' ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.Read' ) ) . get ( ) ; return taskLists && taskLists . value ; } export param { IGraph } graph param { string } listId returns { Promise < TodoTaskList > } export async function getTodoTaskList ( graph , listId ) { const taskList = await graph . api ( `/me/todo/lists/${ listId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.Read' ) ) . get ( ) ; return taskList ; } export param { IGraph } graph param { string } listId param { { title : string ; dueDateTime : { dateTime : string ; timeZone : string } } } taskData returns { Promise < TodoTask > } export async function createTodoTask ( graph , listId , taskData ) { const task = await graph . api ( `/me/todo/lists/${ listId }/tasks` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . post ( taskData ) ; return task ; } export param { IGraph } graph param { { displayName : string } } list returns { Promise < TodoTaskList > } export async function createTodoTaskList ( graph , listData ) { const list = await graph . api ( '/me/todo/lists' ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . post ( listData ) ; return list ; } export param { IGraph } graph param { string } listId param { string } taskId returns { Promise < void > } export async function deleteTodoTask ( graph , listId , taskId ) { await graph . api ( `/me/todo/lists/${ listId }/tasks/${ taskId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . delete ( ) ; } export param { IGraph } graph param { string } listId returns { Promise < void > } export async function deleteTodoTaskList ( graph , listId ) { await graph . api ( `/me/todo/lists/${ listId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . delete ( ) ; } export param { IGraph } graph param { string } listId param { string } taskId param { TodoTask } taskData returns { Promise < TodoTask > } export async function updateTodoTask ( graph , listId , taskId , taskData ) { const task = await graph . api ( `/me/todo/lists/${ listId }/tasks/${ taskId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . patch ( taskData ) ; return task ; } export param { IGraph } graph param { string } listId param { TodoTaskList } taskListData returns { Promise < TodoTaskList > } export async function updateTodoTaskList ( graph , listId , taskListData ) { const task = await graph . api ( `/me/todo/lists/${ listId }` ) . header ( 'Cache-Control' , 'no-store' ) . middlewareOptions ( prepScopes ( 'Tasks.ReadWrite' ) ) . patch ( taskListData ) ; return task ; }