mui-spfx-controls
Version:
SPFx component library built with MUI
54 lines • 2.13 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import { getGraph } from '../config/pnp.config';
/**
* Service class for User profiles
*/
var UserService = /** @class */ (function () {
/**
* Initializes the ProfileService instance.
* @param {WebPartContext} context - The SharePoint WebPart context.
*/
function UserService(context) {
this.graph = getGraph(context);
}
/**
* Fetches current user details from Microsoft Graph.
* @returns {Promise<User>} A promise resolving to current user profile details.
* @throws {Error} - Throws an error if the request fails due to insufficient permissions.
* @example
* const user = await profileService.getUser('john.doe@example.com');
* console.log(user.displayName, user.mail);
*/
UserService.prototype.getCurrentUser = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.graph.me()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* Fetches user details from Microsoft Graph using either a user ID or email.
* @param upn - The user's upn
* @returns {Promise<User>} A promise resolving to the user profile details.
* @throws {Error} - Throws an error if the request fails due to insufficient permissions.
* @example
* const user = await profileService.getUser('john.doe@example.com');
* console.log(user.displayName, user.mail);
*/
UserService.prototype.getUser = function (upn) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.graph.users.getById(upn)()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return UserService;
}());
export { UserService };
//# sourceMappingURL=UserService.js.map