@openstax/ts-utils 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { AccountsGateway } from '../accountsGateway';
2
2
  import { AuthProvider } from '../authProvider';
3
3
  import { Logger } from '../logger';
4
+ import { ActivityState } from './attempt-utils';
4
5
  import { LrsGateway } from '.';
5
6
  export interface Grade {
6
7
  scoreGiven: number;
@@ -13,7 +14,7 @@ export interface Grade {
13
14
  export declare const getRegistrationAttemptInfo: (lrs: LrsGateway, registration: string, options?: {
14
15
  anyUser?: boolean | undefined;
15
16
  } | undefined) => Promise<{
16
- [key: string]: import("./attempt-utils").ActivityState;
17
+ [key: string]: ActivityState;
17
18
  }>;
18
19
  export declare const getCurrentGrade: (services: {
19
20
  lrs: LrsGateway;
@@ -27,6 +28,7 @@ export declare const getAllGradesForAssignment: (services: {
27
28
  lrs: LrsGateway;
28
29
  logger: Logger;
29
30
  }, registration: string, options?: {
31
+ incompleteAttemptsCallback?: ((mappedInfo: [string, ActivityState][]) => Promise<Grade[]>) | undefined;
30
32
  platformId?: string | undefined;
31
33
  scoreMaximum?: number | undefined;
32
34
  } | undefined) => Promise<Grade[]>;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getAllGradesForAssignment = exports.getCurrentGrade = exports.getRegistrationAttemptInfo = void 0;
7
+ const partition_1 = __importDefault(require("lodash/fp/partition"));
4
8
  const __1 = require("../..");
5
9
  const attempt_utils_1 = require("./attempt-utils");
6
10
  const getRegistrationAttemptInfo = async (lrs, registration, options) => {
@@ -55,7 +59,12 @@ const getCurrentGrade = async (services, registration, options) => {
55
59
  exports.getCurrentGrade = getCurrentGrade;
56
60
  const getAllGradesForAssignment = async (services, registration, options) => {
57
61
  const infoPerUserUuid = await (0, exports.getRegistrationAttemptInfo)(services.lrs, registration, { anyUser: true });
58
- const mappedResults = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, options === null || options === void 0 ? void 0 : options.platformId);
59
- return mappedResults.map(([userId, userInfo]) => getInfoGrade(userInfo, userId, options === null || options === void 0 ? void 0 : options.scoreMaximum));
62
+ const mappedInfo = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, options === null || options === void 0 ? void 0 : options.platformId);
63
+ const gradeCompletedAttemptsOnly = (results) => results.map(([userId, userInfo]) => getInfoGrade(userInfo, userId, options === null || options === void 0 ? void 0 : options.scoreMaximum));
64
+ if (!(options === null || options === void 0 ? void 0 : options.incompleteAttemptsCallback)) {
65
+ return gradeCompletedAttemptsOnly(mappedInfo);
66
+ }
67
+ const [incompleteInfo, completedInfo] = (0, partition_1.default)((info) => info[1].currentAttemptCompleted === undefined)(mappedInfo);
68
+ return gradeCompletedAttemptsOnly(completedInfo).concat(await options.incompleteAttemptsCallback(incompleteInfo));
60
69
  };
61
70
  exports.getAllGradesForAssignment = getAllGradesForAssignment;