(function () { 'use strict'; var serviceId = 'userService'; angular.module('user').factory(serviceId, ['userDataContext', dataContext]); function dataContext(userDataContext) { var sasToken; var service = {}; /** * Get the profile for the current user then * run the callback */ service.profile = function (callback) { return userDataContext.getProfile().then(callback); } /** * Get all deployed framework assignments for the user * then run the callback */ service.getFrameworks = function (callback) { return userDataContext.getAllMyFrameworkAssignmentDeployments().then(callback); } /** * Get the users upload bucket token, refreshing the token if the * stored token has expired */ service.getUploadBucketSas = function () { if (sasToken) { var expiry = moment(sasToken.expiryTime).subtract('seconds', '30'); if (expiry.isAfter(moment())) { return Promise.resolve(sasToken); } } return userDataContext.getUploadBucketSas().then(function (token) { sasToken = token; return token; }) } return service; } })();