@quesmed/types 1.5.0 → 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.
@@ -62,6 +62,9 @@ export interface IOsceMarksheet {
62
62
  startedAt: number | Date;
63
63
  endedAt: number | Date;
64
64
  pausedAt: number | Date;
65
+ timeRemaining: string;
66
+ totalStationTime: string;
67
+ stage: EOsceStage;
65
68
  marks: IOsceMarksheetMark[];
66
69
  users: IOsceMarksheetUser[];
67
70
  members: IUser[];
@@ -85,9 +88,16 @@ export declare enum EOsceTimerState {
85
88
  PAUSE = 1,
86
89
  COMPLETED = 2
87
90
  }
91
+ export declare enum EOsceStage {
92
+ READING = 0,
93
+ STATION = 1,
94
+ FEEDBACK = 2
95
+ }
88
96
  export interface IOsceMarksheetTimer {
89
97
  osceMarksheetId: number;
90
98
  timeRemaining: string;
91
- stationTime: string;
99
+ totalStationTime: string;
100
+ stage: EOsceStage;
92
101
  state: EOsceTimerState;
93
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.0",
3
+ "version": "1.5.3",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -88,6 +88,9 @@ exports.OSCE_MARKSHEET_FIELDS = (0, client_1.gql) `
88
88
  startedAt
89
89
  endedAt
90
90
  pausedAt
91
+ timeRemaining
92
+ totalStationTime
93
+ stage
91
94
  marks {
92
95
  ...OsceMarksheetMarkFields
93
96
  }
@@ -85,6 +85,9 @@ export const OSCE_MARKSHEET_FIELDS = gql `
85
85
  startedAt
86
86
  endedAt
87
87
  pausedAt
88
+ timeRemaining
89
+ totalStationTime
90
+ stage
88
91
  marks {
89
92
  ...OsceMarksheetMarkFields
90
93
  }
@@ -74,7 +74,6 @@ export declare type ISaveOsceMarksheetData = RestrictedData<graphqlNormalize & I
74
74
  export declare const OSCE_MARKSHEET_ACTIONS: import("@apollo/client").DocumentNode;
75
75
  export interface IOsceMarksheetActionsVar {
76
76
  osceMarksheetId: Id;
77
- agoraId: string;
78
77
  action: EOsceMarksheetAction;
79
78
  }
80
79
  export declare type IOsceMarksheetActionsData = RestrictedData<number, 'osceMarksheetActions'>;
@@ -132,7 +132,7 @@ exports.START_OSCE_TIMER = (0, client_1.gql) `
132
132
  startOsceTimer(osceMarksheetId: $osceMarksheetId) {
133
133
  osceMarksheetId
134
134
  timeRemaining
135
- stationTime
135
+ totalStationTime
136
136
  state
137
137
  }
138
138
  }
@@ -183,17 +183,9 @@ exports.SAVE_OSCE_MARKSHEET = (0, client_1.gql) `
183
183
  }
184
184
  `;
185
185
  exports.OSCE_MARKSHEET_ACTIONS = (0, client_1.gql) `
186
- mutation OsceMarksheetActions(
187
- $osceMarksheetId: Int!
188
- $agoraId: String!
189
- $action: Int!
190
- ) {
186
+ mutation OsceMarksheetActions($osceMarksheetId: Int!, $action: Int!) {
191
187
  restricted {
192
- osceMarksheetActions(
193
- osceMarksheetId: $osceMarksheetId
194
- agoraId: $agoraId
195
- action: $action
196
- )
188
+ osceMarksheetActions(osceMarksheetId: $osceMarksheetId, action: $action)
197
189
  }
198
190
  }
199
191
  `;
@@ -128,7 +128,7 @@ export const START_OSCE_TIMER = gql `
128
128
  startOsceTimer(osceMarksheetId: $osceMarksheetId) {
129
129
  osceMarksheetId
130
130
  timeRemaining
131
- stationTime
131
+ totalStationTime
132
132
  state
133
133
  }
134
134
  }
@@ -179,17 +179,9 @@ export const SAVE_OSCE_MARKSHEET = gql `
179
179
  }
180
180
  `;
181
181
  export const OSCE_MARKSHEET_ACTIONS = gql `
182
- mutation OsceMarksheetActions(
183
- $osceMarksheetId: Int!
184
- $agoraId: String!
185
- $action: Int!
186
- ) {
182
+ mutation OsceMarksheetActions($osceMarksheetId: Int!, $action: Int!) {
187
183
  restricted {
188
- osceMarksheetActions(
189
- osceMarksheetId: $osceMarksheetId
190
- agoraId: $agoraId
191
- action: $action
192
- )
184
+ osceMarksheetActions(osceMarksheetId: $osceMarksheetId, action: $action)
193
185
  }
194
186
  }
195
187
  `;
@@ -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;
@@ -100,7 +100,8 @@ exports.OSCE_MARKSHEET_TIMER = (0, client_1.gql) `
100
100
  osceMarksheetTimer(osceMarksheetId: $osceMarksheetId) {
101
101
  osceMarksheetId
102
102
  timeRemaining
103
- stationTime
103
+ totalStationTime
104
+ stage
104
105
  state
105
106
  }
106
107
  }
@@ -96,7 +96,8 @@ export const OSCE_MARKSHEET_TIMER = gql `
96
96
  osceMarksheetTimer(osceMarksheetId: $osceMarksheetId) {
97
97
  osceMarksheetId
98
98
  timeRemaining
99
- stationTime
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
+ }