1. "use strict";
  2. /**
  3. * Functions for interacting with discussion topics within courses
  4. * @namespace api.course.discussionTopic
  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. // Endpoint category
  68. var ECatDiscussionTopic = /** @class */ (function (_super) {
  69. __extends(ECatDiscussionTopic, _super);
  70. function ECatDiscussionTopic() {
  71. return _super !== null && _super.apply(this, arguments) || this;
  72. }
  73. /*------------------------------------------------------------------------*/
  74. /* Endpoints */
  75. /*------------------------------------------------------------------------*/
  76. /**
  77. * Gets the list of discussion topics
  78. * @author Gabe Abrams
  79. * @method list
  80. * @memberof api.course.discussionTopic
  81. * @instance
  82. * @async
  83. * @param {object} [opts] object containing all arguments
  84. * @param {number} [opts.courseId] Canvas course Id to query
  85. * @param {boolean} [opts.includeAllDates] If truthy, includes
  86. * all dates
  87. * @param {boolean} [opts.includeSections] If truthy, includes
  88. * sections
  89. * @param {boolean} [opts.includeSectionsUserCount] If truthy,
  90. * includes section user count
  91. * @param {boolean} [opts.includeOverrides] If truthy,
  92. * includes overrides
  93. * @param {string} [opts.searchTerm] If included, the partial title of the
  94. * discussion topics to match and return
  95. * @param {string} [opts.orderBy="position"] If included, the results are
  96. * ordered as instructed. Can be "position" or "recent_activity" or "title"
  97. * @param {APIConfig} [config] custom configuration for this specific endpoint
  98. * call (overwrites defaults that were included when api was initialized)
  99. * @returns {Promise<CanvasDiscussionTopic[]>} List of Canvas Discussion Topics {@link https://canvas.instructure.com/doc/api/discussion_topics.html#DiscussionTopic}
  100. */
  101. ECatDiscussionTopic.prototype.list = function (opts, config) {
  102. var _a;
  103. if (opts === void 0) { opts = {}; }
  104. return __awaiter(this, void 0, void 0, function () {
  105. return __generator(this, function (_b) {
  106. return [2 /*return*/, this.visitEndpoint({
  107. config: config,
  108. action: 'get the list of discussion topics in a course',
  109. path: "".concat(API_PREFIX_1.default, "/courses/").concat((_a = opts.courseId) !== null && _a !== void 0 ? _a : this.defaultCourseId, "/discussion_topics"),
  110. method: 'GET',
  111. params: {
  112. include: utils_1.default.genIncludesList({
  113. all_dates: opts.includeAllDates,
  114. sections: opts.includeSections,
  115. sections_user_count: opts.includeSectionsUserCount,
  116. overrides: opts.includeOverrides,
  117. }),
  118. search_term: utils_1.default.includeIfTruthy(opts.searchTerm),
  119. order_by: utils_1.default.includeIfTruthy(opts.orderBy),
  120. },
  121. })];
  122. });
  123. });
  124. };
  125. /**
  126. * Creates a new discussion topic
  127. * @author Gabe Abrams
  128. * @method create
  129. * @memberof api.course.discussionTopic
  130. * @instance
  131. * @async
  132. * @param {object} opts object containing all arguments
  133. * @param {string} opts.title title of the discussion
  134. * @param {string} opts.message message of the discussion
  135. * @param {number} [opts.courseId=default course id] Canvas course Id to query
  136. * @param {string} [opts.discussionType="side_comment"] the type of
  137. * discussion. Accepted values are 'side_comment', for discussions that
  138. * only allow one level of nested comments, and 'threaded' for fully
  139. * threaded discussions.
  140. * @param {boolean} [opts.published] if true, topic is published. If false,
  141. * discussion topic is left in draft state
  142. * @param {date} [opts.delayedPostAt] if a date is given, the topic will
  143. * not be published until that time
  144. * @param {boolean} [opts.allowRating] if true, users can rate entries in
  145. * this topic
  146. * @param {date} [opts.lockAt] if a date is given, the topic will be
  147. * scheduled to lock at the provided timestamp. If the date is in the past,
  148. * the topic will be locked
  149. * @param {boolean} [opts.pinned] if true, this topic will be listed in
  150. * the “Pinned Discussion” section
  151. * @param {number} [opts.groupSetId] if included, the topic will become a
  152. * group discussion assigned to the group
  153. * @param {boolean} [opts.onlyGradersCanRate] if true, only graders will
  154. * be allowed to rate entries.
  155. * @param {boolean} [opts.requireInitialPost] if true, then a user may not
  156. * respond to other replies until that user has made an initial reply
  157. * @param {APIConfig} [config] custom configuration for this specific endpoint
  158. * call (overwrites defaults that were included when api was initialized)
  159. * @returns {Promise<CanvasDiscussionTopic>} A Canvas Discussion Topics {@link https://canvas.instructure.com/doc/api/discussion_topics.html#DiscussionTopic}
  160. */
  161. ECatDiscussionTopic.prototype.create = function (opts, config) {
  162. var _a;
  163. return __awaiter(this, void 0, void 0, function () {
  164. return __generator(this, function (_b) {
  165. return [2 /*return*/, this.visitEndpoint({
  166. config: config,
  167. action: 'create a discussion topic in a course',
  168. path: "".concat(API_PREFIX_1.default, "/courses/").concat((_a = opts.courseId) !== null && _a !== void 0 ? _a : this.defaultCourseId, "/discussion_topics"),
  169. method: 'POST',
  170. params: {
  171. title: opts.title,
  172. message: opts.message,
  173. discussion_type: utils_1.default.includeIfTruthy(opts.discussionType),
  174. published: utils_1.default.includeIfBoolean(opts.published),
  175. delayed_post_at: utils_1.default.includeIfDate(opts.delayedPostAt),
  176. lock_at: utils_1.default.includeIfDate(opts.lockAt),
  177. require_initial_post: (utils_1.default.includeIfBoolean(opts.requireInitialPost)),
  178. pinned: utils_1.default.includeIfBoolean(opts.pinned),
  179. group_category_id: utils_1.default.includeIfNumber(opts.groupSetId),
  180. allow_rating: utils_1.default.includeIfBoolean(opts.allowRating),
  181. only_graders_can_rate: (utils_1.default.includeIfBoolean(opts.onlyGradersCanRate)),
  182. },
  183. })];
  184. });
  185. });
  186. };
  187. /**
  188. * Deletes a discussion topic
  189. * @author Gabe Abrams
  190. * @method delete
  191. * @memberof api.course.discussionTopic
  192. * @instance
  193. * @async
  194. * @param {object} opts object containing all arguments
  195. * @param {string} opts.topicId the id of the Canvas discussion topic to
  196. * delete
  197. * @param {number} [opts.courseId=default course id] Canvas course Id to query
  198. * @param {APIConfig} [config] custom configuration for this specific endpoint
  199. * call (overwrites defaults that were included when api was initialized)
  200. * @returns {Promise<CanvasDiscussionTopic>} A Canvas Discussion Topic {@link https://canvas.instructure.com/doc/api/discussion_topics.html#DiscussionTopic}
  201. */
  202. ECatDiscussionTopic.prototype.delete = function (opts, config) {
  203. var _a;
  204. return __awaiter(this, void 0, void 0, function () {
  205. return __generator(this, function (_b) {
  206. return [2 /*return*/, this.visitEndpoint({
  207. config: config,
  208. action: 'delete a discussion topic from a course',
  209. path: "".concat(API_PREFIX_1.default, "/courses/").concat((_a = opts.courseId) !== null && _a !== void 0 ? _a : this.defaultCourseId, "/discussion_topics/").concat(opts.topicId),
  210. method: 'DELETE',
  211. })];
  212. });
  213. });
  214. };
  215. /**
  216. * Update whether a discussion topic is published or not
  217. * @author Gabe Abrams
  218. * @method updatePublishState
  219. * @memberof api.course.discussionTopic
  220. * @instance
  221. * @async
  222. * @param {object} opts object containing all arguments
  223. * @param {number} opts.topicId the id of the Canvas discussion topic to
  224. * update
  225. * @param {number} [opts.courseId=default course id] Canvas course Id to
  226. * modify
  227. * @param {boolean} [opts.isPublished] if true, publish the discussion topic.
  228. * Otherwise, unpublish it
  229. */
  230. ECatDiscussionTopic.prototype.updatePublishState = function (opts, config) {
  231. var _a;
  232. return __awaiter(this, void 0, void 0, function () {
  233. return __generator(this, function (_b) {
  234. return [2 /*return*/, this.visitEndpoint({
  235. config: config,
  236. action: 'update the published state of a specific discussion topic',
  237. path: "".concat(API_PREFIX_1.default, "/courses/").concat((_a = opts.courseId) !== null && _a !== void 0 ? _a : this.defaultCourseId, "/discussion_topics/").concat(opts.topicId),
  238. method: 'PUT',
  239. params: {
  240. published: !!opts.isPublished,
  241. },
  242. })];
  243. });
  244. });
  245. };
  246. /**
  247. * Lists the entries in a discussion topic
  248. * @author Gabe Abrams
  249. * @method listEntries
  250. * @memberof api.course.discussionTopic
  251. * @instance
  252. * @async
  253. * @param {object} opts object containing all arguments
  254. * @param {number} opts.topicId the id of the Canvas discussion topic to
  255. * list entries in
  256. * @param {number} [opts.courseId=default course id] Canvas course Id to query
  257. * @param {APIConfig} [config] custom configuration for this specific endpoint
  258. * call (overwrites defaults that were included when api was initialized)
  259. * @returns {Promise<CanvasDiscussionTopic>} A Canvas Discussion Topic {@link https://canvas.instructure.com/doc/api/discussion_topics.html#DiscussionTopic}
  260. */
  261. ECatDiscussionTopic.prototype.listEntries = function (opts, config) {
  262. var _a;
  263. return __awaiter(this, void 0, void 0, function () {
  264. return __generator(this, function (_b) {
  265. return [2 /*return*/, this.visitEndpoint({
  266. config: config,
  267. action: 'list entries in a discussion topic in a course',
  268. path: "".concat(API_PREFIX_1.default, "/courses/").concat((_a = opts.courseId) !== null && _a !== void 0 ? _a : this.defaultCourseId, "/discussion_topics/").concat(opts.topicId, "/entries"),
  269. method: 'GET',
  270. })];
  271. });
  272. });
  273. };
  274. return ECatDiscussionTopic;
  275. }(EndpointCategory_1.default));
  276. /*------------------------------------------------------------------------*/
  277. /* Export */
  278. /*------------------------------------------------------------------------*/
  279. exports.default = ECatDiscussionTopic;
  280. //# sourceMappingURL=ECatDiscussionTopic.js.map