(function () { 'use strict'; var serviceId = 'calendarDataContext'; angular.module('calendar').factory(serviceId, ['$q', '$http', 'config', '$modal', datacontext]); function datacontext($q, $http, config, $modal) { var service = { getCalendars: getCalendars, getCalendarByOrgId: getCalendarByOrgId, createCalendar: createCalendar, createCalendarEvent: createCalendarEvent, updateCalendarEvent: updateCalendarEvent, deleteCalendarEvent: deleteCalendarEvent, createo365Event: createo365Event }; return service; function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function getCalendars() { var request = $http({ method: "get", url: config.calendarUrl + "api/calendarsmanager/" }); return (request.then(handleSuccess, handleError)); } function getCalendarByOrgId(orgId) { var request = $http({ method: "get", url: config.calendarUrl + "api/calendarsmanager/org/" + orgId }); return (request.then(handleSuccess, handleError)); } function createCalendar(calendar) { var request = $http({ method: "post", url: config.calendarUrl + "api/calendarsmanager", data: calendar }); return (request.then(handleSuccess, handleError)); } function createCalendarEvent(event) { var request = $http({ method: "post", url: config.calendarUrl + "api/calendarevents", data: event }); return (request.then(handleSuccess, handleError)); } function updateCalendarEvent(event) { var request = $http({ method: "put", url: config.calendarUrl + "api/calendarevents/" + event.id, data: event }); return (request.then(handleSuccess, handleError)); } function deleteCalendarEvent(event) { var request = $http({ method: "delete", url: config.calendarUrl + "api/calendarevents/" + event.id, data: event }); return (request.then(handleSuccess, handleError)); } function createo365Event(event) { var request = $http({ method: "post", url: "https://mkm-playground.azurewebsites.net/api/CreateEvent?code=hvXkb13AtVj/1q65MNQ8adXVwa0SV9qasi55nO/PNT5IQVfIRZdrWQ==", data: event }); return (request.then(handleSuccess, handleError)); } } })();