@quesmed/types 1.5.2 → 1.5.3

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.
@@ -64,6 +64,7 @@ export interface IOsceMarksheet {
64
64
  pausedAt: number | Date;
65
65
  timeRemaining: string;
66
66
  totalStationTime: string;
67
+ stage: EOsceStage;
67
68
  marks: IOsceMarksheetMark[];
68
69
  users: IOsceMarksheetUser[];
69
70
  members: IUser[];
@@ -87,9 +88,16 @@ export declare enum EOsceTimerState {
87
88
  PAUSE = 1,
88
89
  COMPLETED = 2
89
90
  }
91
+ export declare enum EOsceStage {
92
+ READING = 0,
93
+ STATION = 1,
94
+ FEEDBACK = 2
95
+ }
90
96
  export interface IOsceMarksheetTimer {
91
97
  osceMarksheetId: number;
92
98
  timeRemaining: string;
93
99
  totalStationTime: string;
100
+ stage: EOsceStage;
94
101
  state: EOsceTimerState;
95
102
  }
103
+ export declare function createTimerPayload(osceMarksheet: Partial<Omit<IOsceMarksheet, 'marks'>>): IOsceMarksheetTimer;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EOsceTimerState = exports.EOsceMarksheetState = exports.EOsceMarksheetAction = exports.EOsceRoles = void 0;
3
+ exports.createTimerPayload = exports.EOsceStage = exports.EOsceTimerState = exports.EOsceMarksheetState = exports.EOsceMarksheetAction = exports.EOsceRoles = void 0;
4
+ const utils_1 = require("../utils");
4
5
  var EOsceRoles;
5
6
  (function (EOsceRoles) {
6
7
  EOsceRoles[EOsceRoles["ALL"] = 0] = "ALL";
@@ -34,3 +35,65 @@ var EOsceTimerState;
34
35
  EOsceTimerState[EOsceTimerState["PAUSE"] = 1] = "PAUSE";
35
36
  EOsceTimerState[EOsceTimerState["COMPLETED"] = 2] = "COMPLETED";
36
37
  })(EOsceTimerState = exports.EOsceTimerState || (exports.EOsceTimerState = {}));
38
+ var EOsceStage;
39
+ (function (EOsceStage) {
40
+ EOsceStage[EOsceStage["READING"] = 0] = "READING";
41
+ EOsceStage[EOsceStage["STATION"] = 1] = "STATION";
42
+ EOsceStage[EOsceStage["FEEDBACK"] = 2] = "FEEDBACK";
43
+ })(EOsceStage = exports.EOsceStage || (exports.EOsceStage = {}));
44
+ function createTimerPayload(osceMarksheet) {
45
+ const payload = {
46
+ osceMarksheetId: osceMarksheet.id,
47
+ timeRemaining: '00:00',
48
+ totalStationTime: '00:00',
49
+ stage: EOsceStage.READING,
50
+ state: EOsceTimerState.PAUSE,
51
+ };
52
+ if (!osceMarksheet.startedAt ||
53
+ !osceMarksheet.endedAt ||
54
+ !osceMarksheet.readingTime ||
55
+ !osceMarksheet.stationTime ||
56
+ !osceMarksheet.feedbackTime) {
57
+ return payload;
58
+ }
59
+ payload.state = EOsceTimerState.START;
60
+ const stationDuration = osceMarksheet.readingTime +
61
+ (osceMarksheet.stationTime + osceMarksheet.feedbackTime) * 60;
62
+ payload.totalStationTime = (0, utils_1.printDuration)(stationDuration);
63
+ let endedAt;
64
+ if (typeof osceMarksheet.endedAt === 'number') {
65
+ endedAt = osceMarksheet.endedAt;
66
+ }
67
+ else {
68
+ endedAt = Math.floor(osceMarksheet.endedAt.getTime() / 1000);
69
+ }
70
+ // calculate duration from pause timestamp or from current time
71
+ let timeRemainingDuration = endedAt - Math.floor(Date.now() / 1000);
72
+ if (osceMarksheet.completed || timeRemainingDuration < 0) {
73
+ payload.state = EOsceTimerState.COMPLETED;
74
+ }
75
+ if (osceMarksheet.pausedAt) {
76
+ let pausedAt;
77
+ if (typeof osceMarksheet.pausedAt === 'number') {
78
+ pausedAt = osceMarksheet.pausedAt;
79
+ }
80
+ else {
81
+ pausedAt = Math.floor(osceMarksheet.pausedAt.getTime() / 1000);
82
+ }
83
+ timeRemainingDuration = endedAt - pausedAt;
84
+ payload.state = EOsceTimerState.PAUSE;
85
+ }
86
+ if (timeRemainingDuration > stationDuration - osceMarksheet.readingTime) {
87
+ payload.stage = EOsceStage.READING;
88
+ }
89
+ else if (timeRemainingDuration >
90
+ stationDuration - osceMarksheet.readingTime - osceMarksheet.stationTime * 60) {
91
+ payload.stage = EOsceStage.STATION;
92
+ }
93
+ else {
94
+ payload.stage = EOsceStage.FEEDBACK;
95
+ }
96
+ payload.timeRemaining = (0, utils_1.printDuration)(timeRemainingDuration);
97
+ return payload;
98
+ }
99
+ exports.createTimerPayload = createTimerPayload;
@@ -1,3 +1,4 @@
1
+ import { printDuration } from '../utils';
1
2
  export var EOsceRoles;
2
3
  (function (EOsceRoles) {
3
4
  EOsceRoles[EOsceRoles["ALL"] = 0] = "ALL";
@@ -31,3 +32,64 @@ export var EOsceTimerState;
31
32
  EOsceTimerState[EOsceTimerState["PAUSE"] = 1] = "PAUSE";
32
33
  EOsceTimerState[EOsceTimerState["COMPLETED"] = 2] = "COMPLETED";
33
34
  })(EOsceTimerState || (EOsceTimerState = {}));
35
+ export var EOsceStage;
36
+ (function (EOsceStage) {
37
+ EOsceStage[EOsceStage["READING"] = 0] = "READING";
38
+ EOsceStage[EOsceStage["STATION"] = 1] = "STATION";
39
+ EOsceStage[EOsceStage["FEEDBACK"] = 2] = "FEEDBACK";
40
+ })(EOsceStage || (EOsceStage = {}));
41
+ export function createTimerPayload(osceMarksheet) {
42
+ const payload = {
43
+ osceMarksheetId: osceMarksheet.id,
44
+ timeRemaining: '00:00',
45
+ totalStationTime: '00:00',
46
+ stage: EOsceStage.READING,
47
+ state: EOsceTimerState.PAUSE,
48
+ };
49
+ if (!osceMarksheet.startedAt ||
50
+ !osceMarksheet.endedAt ||
51
+ !osceMarksheet.readingTime ||
52
+ !osceMarksheet.stationTime ||
53
+ !osceMarksheet.feedbackTime) {
54
+ return payload;
55
+ }
56
+ payload.state = EOsceTimerState.START;
57
+ const stationDuration = osceMarksheet.readingTime +
58
+ (osceMarksheet.stationTime + osceMarksheet.feedbackTime) * 60;
59
+ payload.totalStationTime = printDuration(stationDuration);
60
+ let endedAt;
61
+ if (typeof osceMarksheet.endedAt === 'number') {
62
+ endedAt = osceMarksheet.endedAt;
63
+ }
64
+ else {
65
+ endedAt = Math.floor(osceMarksheet.endedAt.getTime() / 1000);
66
+ }
67
+ // calculate duration from pause timestamp or from current time
68
+ let timeRemainingDuration = endedAt - Math.floor(Date.now() / 1000);
69
+ if (osceMarksheet.completed || timeRemainingDuration < 0) {
70
+ payload.state = EOsceTimerState.COMPLETED;
71
+ }
72
+ if (osceMarksheet.pausedAt) {
73
+ let pausedAt;
74
+ if (typeof osceMarksheet.pausedAt === 'number') {
75
+ pausedAt = osceMarksheet.pausedAt;
76
+ }
77
+ else {
78
+ pausedAt = Math.floor(osceMarksheet.pausedAt.getTime() / 1000);
79
+ }
80
+ timeRemainingDuration = endedAt - pausedAt;
81
+ payload.state = EOsceTimerState.PAUSE;
82
+ }
83
+ if (timeRemainingDuration > stationDuration - osceMarksheet.readingTime) {
84
+ payload.stage = EOsceStage.READING;
85
+ }
86
+ else if (timeRemainingDuration >
87
+ stationDuration - osceMarksheet.readingTime - osceMarksheet.stationTime * 60) {
88
+ payload.stage = EOsceStage.STATION;
89
+ }
90
+ else {
91
+ payload.stage = EOsceStage.FEEDBACK;
92
+ }
93
+ payload.timeRemaining = printDuration(timeRemainingDuration);
94
+ return payload;
95
+ }
package/models/User.d.ts CHANGED
@@ -5,6 +5,7 @@ import { IQuestion } from './Question';
5
5
  import { ISubscription } from './Subscription';
6
6
  import { ITopic } from './Topic';
7
7
  import { Id } from './Type';
8
+ export declare type IAccessLevel = 'subscriber' | 'administrator' | 'tutor';
8
9
  export declare type IClassYear = 'Year 1' | 'Year 2' | 'Year 3' | 'Year 4' | 'Year 5' | 'Graduated' | 'PhD' | 'BSc' | 'MSc' | 'Beta Tester';
9
10
  export declare const classYears: IClassYear[];
10
11
  export declare enum EClassYearGroup {
@@ -20,7 +21,7 @@ export interface IPayload {
20
21
  firstName: string;
21
22
  lastName: string;
22
23
  username: string;
23
- accessLevel: string;
24
+ accessLevel: IAccessLevel;
24
25
  tocAccepted: boolean;
25
26
  exp: number;
26
27
  stripeSubscriptionEndDate: number | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -90,6 +90,7 @@ exports.OSCE_MARKSHEET_FIELDS = (0, client_1.gql) `
90
90
  pausedAt
91
91
  timeRemaining
92
92
  totalStationTime
93
+ stage
93
94
  marks {
94
95
  ...OsceMarksheetMarkFields
95
96
  }
@@ -87,6 +87,7 @@ export const OSCE_MARKSHEET_FIELDS = gql `
87
87
  pausedAt
88
88
  timeRemaining
89
89
  totalStationTime
90
+ stage
90
91
  marks {
91
92
  ...OsceMarksheetMarkFields
92
93
  }
@@ -1,6 +1,5 @@
1
- import { EOsceMarksheetAction, EOsceRoles, IClassYear, Id, IOsceMarksheetTimer, IOsceMarksheetUser, IUser } from '../../models';
1
+ import { EClassYearGroup, EOsceMarksheetAction, EOsceRoles, IAccessLevel, IClassYear, Id, IOsceMarksheetTimer, IOsceMarksheetUser, IUser } from '../../models';
2
2
  import { RootData } from '../types';
3
- import { EClassYearGroup } from './../../models/User';
4
3
  export declare const OSCE_ROLE_CHANGE_KEY = "OSCE_ROLE_CHANGE";
5
4
  export declare const OSCE_MARKSHEET_ACTION_KEY = "OSCE_MARKSHEET_ACTION";
6
5
  export declare const OSCE_MARKSHEET_TIMER_KEY = "OSCE_MARKSHEET_TIMER";
@@ -44,6 +43,7 @@ export interface IOsceMatchmakingAction {
44
43
  userId: Id;
45
44
  classYear: IClassYear;
46
45
  classYearGroup: EClassYearGroup;
46
+ accessLevel: IAccessLevel;
47
47
  lastSyncAt: number;
48
48
  startedAt: number;
49
49
  grouped: boolean;
@@ -101,6 +101,7 @@ exports.OSCE_MARKSHEET_TIMER = (0, client_1.gql) `
101
101
  osceMarksheetId
102
102
  timeRemaining
103
103
  totalStationTime
104
+ stage
104
105
  state
105
106
  }
106
107
  }
@@ -97,6 +97,7 @@ export const OSCE_MARKSHEET_TIMER = gql `
97
97
  osceMarksheetId
98
98
  timeRemaining
99
99
  totalStationTime
100
+ stage
100
101
  state
101
102
  }
102
103
  }
package/utils/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './webSocketLink';
6
6
  export * from './wordsToNumber';
7
7
  import uuid from './uuid4';
8
8
  export declare const Uuid4: typeof uuid;
9
+ export declare function printDuration(duration: number): string;
package/utils/index.js CHANGED
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Uuid4 = void 0;
16
+ exports.printDuration = exports.Uuid4 = void 0;
17
17
  __exportStar(require("./commonFunctions"), exports);
18
18
  __exportStar(require("./lightgallery"), exports);
19
19
  __exportStar(require("./offlineLink"), exports);
@@ -22,3 +22,21 @@ __exportStar(require("./webSocketLink"), exports);
22
22
  __exportStar(require("./wordsToNumber"), exports);
23
23
  const uuid4_1 = __importDefault(require("./uuid4"));
24
24
  exports.Uuid4 = uuid4_1.default;
25
+ function printDuration(duration) {
26
+ let timeRemainingMins = Math.floor(duration / 60);
27
+ if (timeRemainingMins < 0) {
28
+ timeRemainingMins = 0;
29
+ }
30
+ const timeRemainingMinsStr = timeRemainingMins >= 10
31
+ ? timeRemainingMins.toString()
32
+ : `0${timeRemainingMins}`;
33
+ let timeRemainingSecs = duration % 60;
34
+ if (timeRemainingSecs < 0) {
35
+ timeRemainingSecs = 0;
36
+ }
37
+ const timeRemainingSecsStr = timeRemainingSecs >= 10
38
+ ? timeRemainingSecs.toString()
39
+ : `0${timeRemainingSecs}`;
40
+ return `${timeRemainingMinsStr}:${timeRemainingSecsStr}`;
41
+ }
42
+ exports.printDuration = printDuration;
package/utils/index.mjs CHANGED
@@ -6,3 +6,20 @@ export * from './webSocketLink';
6
6
  export * from './wordsToNumber';
7
7
  import uuid from './uuid4';
8
8
  export const Uuid4 = uuid;
9
+ export function printDuration(duration) {
10
+ let timeRemainingMins = Math.floor(duration / 60);
11
+ if (timeRemainingMins < 0) {
12
+ timeRemainingMins = 0;
13
+ }
14
+ const timeRemainingMinsStr = timeRemainingMins >= 10
15
+ ? timeRemainingMins.toString()
16
+ : `0${timeRemainingMins}`;
17
+ let timeRemainingSecs = duration % 60;
18
+ if (timeRemainingSecs < 0) {
19
+ timeRemainingSecs = 0;
20
+ }
21
+ const timeRemainingSecsStr = timeRemainingSecs >= 10
22
+ ? timeRemainingSecs.toString()
23
+ : `0${timeRemainingSecs}`;
24
+ return `${timeRemainingMinsStr}:${timeRemainingSecsStr}`;
25
+ }