@microsoft/mgt
Version:
The Microsoft Graph Toolkit
380 lines • 12.2 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/**
* async method to get user details
*
* @class TaskSourceBase
*/
class TaskSourceBase {
constructor(graph) {
this.graph = graph;
}
}
/**
* Create Planner
*
* @export
* @class PlannerTaskSource
* @extends {TaskSourceBase}
* @implements {ITaskSource}
*/
// tslint:disable-next-line: max-classes-per-file
export class PlannerTaskSource extends TaskSourceBase {
/**
* returns promise with all of users plans
*
* @returns {Promise<ITaskGroup[]>}
* @memberof PlannerTaskSource
*/
getTaskGroups() {
return __awaiter(this, void 0, void 0, function* () {
const plans = yield this.graph.planner_getAllMyPlans();
return plans.map(plan => ({ id: plan.id, title: plan.title }));
});
}
/**
* returns promise with all of plans for group id
*
* @param {string} id
* @returns {Promise<ITaskGroup[]>}
* @memberof PlannerTaskSource
*/
getTaskGroupsForGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
const plans = yield this.graph.getPlansForGroup(id);
return plans.map(plan => ({ id: plan.id, title: plan.title }));
});
}
/**
* returns promise single TaskGroup or plan from plan.id
*
* @param {string} id
* @returns {Promise<ITaskGroup>}
* @memberof PlannerTaskSource
*/
getTaskGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
const plan = yield this.graph.planner_getSinglePlan(id);
return { id: plan.id, title: plan.title, _raw: plan };
});
}
/**
* returns promise with Bucket for a plan from bucket.id
*
* @param {string} id
* @returns {Promise<ITaskFolder[]>}
* @memberof PlannerTaskSource
*/
getTaskFoldersForTaskGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
const buckets = yield this.graph.planner_getBucketsForPlan(id);
return buckets.map(bucket => ({
_raw: bucket,
id: bucket.id,
name: bucket.name,
parentId: bucket.planId
}));
});
}
/**
* get all task from a Bucket given task id
*
* @param {string} id
* @returns {Promise<ITask[]>}
* @memberof PlannerTaskSource
*/
getTasksForTaskFolder(id) {
return __awaiter(this, void 0, void 0, function* () {
const tasks = yield this.graph.planner_getTasksForBucket(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
}));
});
}
/**
* set task in planner to complete state by id
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
setTaskComplete(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_setTaskComplete(id, eTag);
});
}
/**
* set task in planner to incomplete state by id
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
setTaskIncomplete(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_setTaskIncomplete(id, eTag);
});
}
/**
* add new task to bucket
*
* @param {ITask} newTask
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
addTask(newTask) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_addTask({
assignments: newTask.assignments,
bucketId: newTask.immediateParentId,
dueDateTime: newTask.dueDate && newTask.dueDate.toISOString(),
planId: newTask.topParentId,
title: newTask.name
});
});
}
/**
* Assigns people to task
*
* @param {string} id
* @param {string} eTag
* @param {*} people
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
assignPeopleToTask(id, eTag, people) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_assignPeopleToTask(id, eTag, people);
});
}
/**
* remove task from bucket
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
removeTask(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_removeTask(id, eTag);
});
}
/**
* assigns task to the signed in user
*
* @param {ITask} task
* @param {string} myId
* @returns {boolean}
* @memberof PlannerTaskSource
*/
isAssignedToMe(task, myId) {
const keys = Object.keys(task.assignments);
return keys.includes(myId);
}
}
/**
* determins outlook task group for data source
*
* @export
* @class TodoTaskSource
* @extends {TaskSourceBase}
* @implements {ITaskSource}
*/
// tslint:disable-next-line: max-classes-per-file
export class TodoTaskSource extends TaskSourceBase {
/**
* get all Outlook task groups
*
* @returns {Promise<ITaskGroup[]>}
* @memberof TodoTaskSource
*/
getTaskGroups() {
return __awaiter(this, void 0, void 0, function* () {
const groups = yield this.graph.todo_getAllMyGroups();
return groups.map(group => ({
_raw: group,
id: group.id,
secondaryId: group.groupKey,
title: group.name
}));
});
}
/**
* get a single OutlookTaskGroup from id
*
* @param {string} id
* @returns {Promise<ITaskGroup>}
* @memberof TodoTaskSource
*/
getTaskGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
const group = yield this.graph.todo_getSingleGroup(id);
return { id: group.id, secondaryId: group.groupKey, title: group.name, _raw: group };
});
}
/**
* get all OutlookTaskFolder for group by id
*
* @param {string} id
* @returns {Promise<ITaskFolder[]>}
* @memberof TodoTaskSource
*/
getTaskFoldersForTaskGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
const folders = yield this.graph.todo_getFoldersForGroup(id);
return folders.map(folder => ({
_raw: folder,
id: folder.id,
name: folder.name,
parentId: id
}));
});
}
/**
* gets all tasks for OutLook Task Folder by id
*
* @param {string} id
* @param {string} parId
* @returns {Promise<ITask[]>}
* @memberof TodoTaskSource
*/
getTasksForTaskFolder(id, parId) {
return __awaiter(this, void 0, void 0, function* () {
const tasks = yield this.graph.todo_getAllTasksForFolder(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
}));
});
}
/**
* set task in planner to complete state by id
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof TodoTaskSource
*/
setTaskComplete(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.todo_setTaskComplete(id, eTag);
});
}
/**
* Assigns people to task
*
* @param {string} id
* @param {string} eTag
* @param {*} people
* @returns {Promise<any>}
* @memberof PlannerTaskSource
*/
assignPeopleToTask(id, eTag, people) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.planner_assignPeopleToTask(id, eTag, people);
});
}
/**
* set task in planner to incomplete state by id
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof TodoTaskSource
*/
setTaskIncomplete(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.todo_setTaskIncomplete(id, eTag);
});
}
/**
* add new task to planner
*
* @param {ITask} newTask
* @returns {Promise<any>}
* @memberof TodoTaskSource
*/
addTask(newTask) {
return __awaiter(this, void 0, void 0, function* () {
const task = {
parentFolderId: newTask.immediateParentId,
subject: newTask.name
};
if (newTask.dueDate) {
task.dueDateTime = {
dateTime: newTask.dueDate.toISOString(),
timeZone: 'UTC'
};
}
return yield this.graph.todo_addTask(task);
});
}
/**
* remove task from planner by id
*
* @param {string} id
* @param {string} eTag
* @returns {Promise<any>}
* @memberof TodoTaskSource
*/
removeTask(id, eTag) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.graph.todo_removeTask(id, eTag);
});
}
/**
* if task is assigned in to user logged in
*
* @param {ITask} task
* @param {string} myId
* @returns {boolean}
* @memberof TodoTaskSource
*/
isAssignedToMe(task, myId) {
return true;
}
/**
* returns promise with all of plans for group id
*
* @param {string} id
* @returns {Promise<ITaskGroup[]>}
* @memberof PlannerTaskSource
*/
getTaskGroupsForGroup(id) {
return __awaiter(this, void 0, void 0, function* () {
return undefined;
});
}
}
//# sourceMappingURL=task-sources.js.map