UNPKG

qus-canvas

Version:
60 lines (59 loc) 2.57 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SectionsFactory = void 0; const case_converter_1 = require("../../utils/case.converter"); const endpoints_1 = require("../config/endpoints"); class SectionsFactory { constructor(connector, version, accountId) { this.connector = connector; this.version = version; this.accountId = accountId; } /** * Fetch Sections from the API * * @param endpoint * @private */ fetchSections(endpoint) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.connector.get(endpoint); if (response) { const sections = (0, case_converter_1.toCamelCase)(response.data); const sectionPromises = sections.map((section) => __awaiter(this, void 0, void 0, function* () { return (Object.assign(Object.assign({}, section), { id: '', sectionNumber: section.id, remoteCreatedAt: section.createdAt, courseNumber: section.courseId })); })); return yield Promise.all(sectionPromises); } return []; }); } /** * List sections by course * * @param courseId * @param page * @param size */ listSectionsByCourse(courseId, page, size) { return __awaiter(this, void 0, void 0, function* () { const endpoint = new endpoints_1.Endpoints().LIST_SECTIONS_BY_COURSE .replace(':version', this.version) .replace(':account_id', this.accountId) .replace(':course_id', courseId.toString()) .replace(':page', page.toString()) .replace(':size', size.toString()); return this.fetchSections(endpoint); }); } } exports.SectionsFactory = SectionsFactory;