1. "use strict";
  2. /**
  3. * Functions for interacting with enrollment terms
  4. * @namespace api.user.self
  5. */
  6. var __extends = (this && this.__extends) || (function () {
  7. var extendStatics = function (d, b) {
  8. extendStatics = Object.setPrototypeOf ||
  9. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  11. return extendStatics(d, b);
  12. };
  13. return function (d, b) {
  14. if (typeof b !== "function" && b !== null)
  15. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  16. extendStatics(d, b);
  17. function __() { this.constructor = d; }
  18. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  19. };
  20. })();
  21. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  22. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  23. return new (P || (P = Promise))(function (resolve, reject) {
  24. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  26. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  27. step((generator = generator.apply(thisArg, _arguments || [])).next());
  28. });
  29. };
  30. var __generator = (this && this.__generator) || function (thisArg, body) {
  31. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  32. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  33. function verb(n) { return function (v) { return step([n, v]); }; }
  34. function step(op) {
  35. if (f) throw new TypeError("Generator is already executing.");
  36. while (g && (g = 0, op[0] && (_ = 0)), _) try {
  37. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  38. if (y = 0, t) op = [op[0] & 2, t.value];
  39. switch (op[0]) {
  40. case 0: case 1: t = op; break;
  41. case 4: _.label++; return { value: op[1], done: false };
  42. case 5: _.label++; y = op[1]; op = [0]; continue;
  43. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  44. default:
  45. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  46. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  47. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  48. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  49. if (t[2]) _.ops.pop();
  50. _.trys.pop(); continue;
  51. }
  52. op = body.call(thisArg, _);
  53. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  54. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  55. }
  56. };
  57. var __importDefault = (this && this.__importDefault) || function (mod) {
  58. return (mod && mod.__esModule) ? mod : { "default": mod };
  59. };
  60. Object.defineProperty(exports, "__esModule", { value: true });
  61. // Import shared classes
  62. var EndpointCategory_1 = __importDefault(require("../../shared/EndpointCategory"));
  63. // Import shared helpers
  64. var utils_1 = __importDefault(require("../../shared/helpers/utils"));
  65. // Import shared constants
  66. var API_PREFIX_1 = __importDefault(require("../../shared/constants/API_PREFIX"));
  67. var ECatSelf = /** @class */ (function (_super) {
  68. __extends(ECatSelf, _super);
  69. function ECatSelf() {
  70. return _super !== null && _super.apply(this, arguments) || this;
  71. }
  72. /*------------------------------------------------------------------------*/
  73. /* Endpoints: */
  74. /*------------------------------------------------------------------------*/
  75. /**
  76. * Gets info on the current user
  77. * @author Gabe Abrams
  78. * @method getProfile
  79. * @memberof api.user.self
  80. * @instance
  81. * @param {APIConfig} [config] custom configuration for this specific endpoint
  82. * call (overwrites defaults that were included when api was initialized)
  83. * @returns {Promise<CanvasUserProfile>} Canvas user profile object {@link https://canvas.instructure.com/doc/api/users.html#Profile}
  84. */
  85. ECatSelf.prototype.getProfile = function (config) {
  86. return __awaiter(this, void 0, void 0, function () {
  87. return __generator(this, function (_a) {
  88. return [2 /*return*/, this.visitEndpoint({
  89. config: config,
  90. action: 'get info on the current user',
  91. path: "".concat(API_PREFIX_1.default, "/users/self/profile"),
  92. method: 'GET',
  93. })];
  94. });
  95. });
  96. };
  97. /**
  98. * Gets the list of courses associated with the current user
  99. * @author Gabe Abrams
  100. * @method listCourses
  101. * @memberof api.user.self
  102. * @instance
  103. * @param {object} opts object containing all arguments
  104. * @param {boolean} [opts.includeTerm] if truthy, term is included
  105. * @param {APIConfig} [config] custom configuration for this specific endpoint
  106. * call (overwrites defaults that were included when api was initialized)
  107. * @returns {Promise<CanvasCourse[]>} list of Canvas courses {@link https://canvas.instructure.com/doc/api/courses.html#Course}
  108. */
  109. ECatSelf.prototype.listCourses = function (opts, config) {
  110. return __awaiter(this, void 0, void 0, function () {
  111. return __generator(this, function (_a) {
  112. return [2 /*return*/, this.visitEndpoint({
  113. config: config,
  114. action: 'get the list of courses associated with the current user',
  115. path: "".concat(API_PREFIX_1.default, "/courses"),
  116. method: 'GET',
  117. params: {
  118. include: utils_1.default.genIncludesList({
  119. term: opts.includeTerm,
  120. }),
  121. },
  122. })];
  123. });
  124. });
  125. };
  126. return ECatSelf;
  127. }(EndpointCategory_1.default));
  128. /*------------------------------------------------------------------------*/
  129. /* Export */
  130. /*------------------------------------------------------------------------*/
  131. exports.default = ECatSelf;
  132. //# sourceMappingURL=ECatSelf.js.map