/**
 * -------------------------------------------------------------------------------------------
 * Copyright (c) Microsoft Corporation.  All Rights Reserved.  Licensed under the MIT License.
 * See License in the project root for license information.
 * -------------------------------------------------------------------------------------------
 */ import { IGraph , BetaGraph } from '@microsoft/mgt-element' ; import { PlannerAssignments } from '@microsoft/microsoft-graph-types' ; import { OutlookTask , OutlookTaskFolder , OutlookTaskGroup } from '@microsoft/microsoft-graph-types-beta' ; import { addPlannerTask , assignPeopleToPlannerTask , getAllMyPlannerPlans , getBucketsForPlannerPlan , getPlansForGroup , getSinglePlannerPlan , getTasksForPlannerBucket , removePlannerTask , setPlannerTaskComplete , setPlannerTaskIncomplete } from './mgt-tasks.graph.planner' ; import { addTodoTask , getAllMyTodoGroups , getAllTodoTasksForFolder , getFoldersForTodoGroup , getSingleTodoGroup , removeTodoTask , setTodoTaskComplete , setTodoTaskIncomplete } from './mgt-tasks.graph.todo' ; export interface export interface ITask { type { string } memberof id : string ; type { string } memberof name : string ; type { Date } memberof dueDate : Date ; type { boolean } memberof completed : boolean ; type { string } memberof topParentId : string ; type { string } memberof immediateParentId : string ; type { PlannerAssignments } memberof assignments : PlannerAssignments ; type { string } memberof eTag : string ; type { * } memberof _raw ? : any ; } export interface export interface ITaskFolder { type { string } memberof id : string ; type { string } memberof name : string ; type { string } memberof parentId : string ; type { * } memberof _raw ? : any ; } export interface export interface ITaskGroup { type { string } memberof id : string ; type { string } memberof secondaryId ? : string ; type { string } memberof title : string ; type { * } memberof _raw ? : any ; } export interface export interface ITaskSource { returns { Promise < ITaskGroup [ ] > } memberof getTaskGroups ( ) : Promise < ITaskGroup [ ] > ; returns { Promise < ITaskGroup [ ] > } memberof getTaskGroupsForGroup ( id ) : Promise < ITaskGroup [ ] > ; param { string } id returns { Promise < ITaskGroup > } memberof getTaskGroup ( id ) : Promise < ITaskGroup > ; param { string } id returns { Promise < ITaskFolder [ ] > } memberof getTaskFoldersForTaskGroup ( id ) : Promise < ITaskFolder [ ] > ; param { string } id param { string } parId returns { Promise < ITask [ ] > } memberof getTasksForTaskFolder ( id , parId ) : Promise < ITask [ ] > ; param { string } id param { string } eTag returns { Promise < any > } memberof setTaskComplete ( id , eTag ) : Promise < any > ; param { string } id param { string } eTag returns { Promise < any > } memberof setTaskIncomplete ( id , eTag ) : Promise < any > ; param { ITask } newTask returns { Promise < any > } memberof addTask ( newTask ) : Promise < any > ; param { string } id param { * } people param { string } eTag returns { Promise < any > } memberof assignPeopleToTask ( id , people , eTag ) : Promise < any > ; param { string } id param { string } eTag returns { Promise < any > } memberof removeTask ( id , eTag ) : Promise < any > ; param { ITask } task param { string } myId returns { Boolean } memberof isAssignedToMe ( task , myId ) : boolean ; } class class TaskSourceBase { type { IGraph } memberof public graph : IGraph ; constructor ( graph ) { this . graph = BetaGraph . fromGraph ( graph ) ; } } export class extends TaskSourceBase implements ITaskSource export class PlannerTaskSource extends TaskSourceBase implements ITaskSource { returns { Promise < ITaskGroup [ ] > } memberof public async getTaskGroups ( ) { const plans = await getAllMyPlannerPlans ( this . graph ) ; return plans . map ( plan => ( { id : plan . id , title : plan . title } as ITaskGroup ) ) ; } param { string } id returns { Promise < ITaskGroup [ ] > } memberof public async getTaskGroupsForGroup ( id ) { const plans = await getPlansForGroup ( this . graph , id ) ; return plans . map ( plan => ( { id : plan . id , title : plan . title } as ITaskGroup ) ) ; } param { string } id returns { Promise < ITaskGroup > } memberof public async getTaskGroup ( id ) { const plan = await getSinglePlannerPlan ( this . graph , id ) ; return { id : plan . id , title : plan . title , _raw : plan } ; } param { string } id returns { Promise < ITaskFolder [ ] > } memberof public async getTaskFoldersForTaskGroup ( id ) { const buckets = await getBucketsForPlannerPlan ( this . graph , id ) ; return buckets . map ( bucket => ( { _raw : bucket , id : bucket . id , name : bucket . name , parentId : bucket . planId } as ITaskFolder ) ) ; } param { string } id returns { Promise < ITask [ ] > } memberof public async getTasksForTaskFolder ( id ) { const tasks = await getTasksForPlannerBucket ( this . graph , id ) ; return tasks . map ( task => ( { _raw : task , assignments : task . assignments , completed : task . percentComplete === 100 , dueDate : task . dueDateTime && new Date ( task . dueDateTime ) , eTag : task [ '@odata.etag' ] , id : task . id , immediateParentId : task . bucketId , name : task . title , topParentId : task . planId } as ITask ) ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async setTaskComplete ( id , eTag ) { return await setPlannerTaskComplete ( this . graph , id , eTag ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async setTaskIncomplete ( id , eTag ) { return await setPlannerTaskIncomplete ( this . graph , id , eTag ) ; } param { ITask } newTask returns { Promise < any > } memberof public async addTask ( newTask ) { return await addPlannerTask ( this . graph , { assignments : newTask . assignments , bucketId : newTask . immediateParentId , dueDateTime : newTask . dueDate && newTask . dueDate . toISOString ( ) , planId : newTask . topParentId , title : newTask . name } ) ; } param { string } id param { string } eTag param { * } people returns { Promise < any > } memberof public async assignPeopleToTask ( id , eTag , people ) { return await assignPeopleToPlannerTask ( this . graph , id , eTag , people ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async removeTask ( id , eTag ) { return await removePlannerTask ( this . graph , id , eTag ) ; } param { ITask } task param { string } myId returns { boolean } memberof public isAssignedToMe ( task , myId ) { const keys = Object . keys ( task . assignments ) ; return keys . includes ( myId ) ; } } export class extends TaskSourceBase implements ITaskSource export class TodoTaskSource extends TaskSourceBase implements ITaskSource { returns { Promise < ITaskGroup [ ] > } memberof public async getTaskGroups ( ) { const groups = await getAllMyTodoGroups ( this . graph ) ; return groups . map ( group => ( { _raw : group , id : group . id , secondaryId : group . groupKey , title : group . name } as ITaskGroup ) ) ; } param { string } id returns { Promise < ITaskGroup > } memberof public async getTaskGroup ( id ) { const group = await getSingleTodoGroup ( this . graph , id ) ; return { id : group . id , secondaryId : group . groupKey , title : group . name , _raw : group } ; } param { string } id returns { Promise < ITaskFolder [ ] > } memberof public async getTaskFoldersForTaskGroup ( id ) { const folders = await getFoldersForTodoGroup ( this . graph , id ) ; return folders . map ( folder => ( { _raw : folder , id : folder . id , name : folder . name , parentId : id } as ITaskFolder ) ) ; } param { string } id param { string } parId returns { Promise < ITask [ ] > } memberof public async getTasksForTaskFolder ( id , parId ) { const tasks = await getAllTodoTasksForFolder ( this . graph , id ) ; return tasks . map ( task => ( { _raw : task , assignments : { } , completed : ! ! task . completedDateTime , dueDate : task . dueDateTime && new Date ( task . dueDateTime . dateTime + 'Z' ) , eTag : task [ '@odata.etag' ] , id : task . id , immediateParentId : id , name : task . subject , topParentId : parId } as ITask ) ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async setTaskComplete ( id , eTag ) { return await setTodoTaskComplete ( this . graph , id , eTag ) ; } param { string } id param { string } eTag param { * } people returns { Promise < any > } memberof public async assignPeopleToTask ( id , eTag , people ) { return await assignPeopleToPlannerTask ( this . graph , id , eTag , people ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async setTaskIncomplete ( id , eTag ) { return await setTodoTaskIncomplete ( this . graph , id , eTag ) ; } param { ITask } newTask returns { Promise < any > } memberof public async addTask ( newTask ) { const task = { parentFolderId : newTask . immediateParentId , subject : newTask . name } as OutlookTask ; if ( newTask . dueDate ) { task . dueDateTime = { dateTime : newTask . dueDate . toISOString ( ) , timeZone : 'UTC' } ; } return await addTodoTask ( this . graph , task ) ; } param { string } id param { string } eTag returns { Promise < any > } memberof public async removeTask ( id , eTag ) { return await removeTodoTask ( this . graph , id , eTag ) ; } param { ITask } task param { string } myId returns { boolean } memberof public isAssignedToMe ( task , myId ) { return true ; } param { string } id returns { Promise < ITaskGroup [ ] > } memberof public async getTaskGroupsForGroup ( id ) { return undefined ; } }