diff --git a/libs/training-events-types/src/events/training-mentor-assigned.ts b/libs/training-events-types/src/events/training-mentor-assigned.ts index 4cc68cb..6f756a8 100644 --- a/libs/training-events-types/src/events/training-mentor-assigned.ts +++ b/libs/training-events-types/src/events/training-mentor-assigned.ts @@ -7,7 +7,7 @@ export type TrainingMentorAssignedEventData = { trainingId: string payload: { mentor: Member - assigned_by: Member + assignedBy: Member } } diff --git a/libs/training-events-types/src/events/training-mentor-reassigned.ts b/libs/training-events-types/src/events/training-mentor-reassigned.ts index 437e4de..2a81aa2 100644 --- a/libs/training-events-types/src/events/training-mentor-reassigned.ts +++ b/libs/training-events-types/src/events/training-mentor-reassigned.ts @@ -7,7 +7,7 @@ export type TrainingMentorReassignedEventData = { trainingId: string payload: { mentor: Member - assigned_by: Member + assignedBy: Member } } diff --git a/libs/training-events/src/actions/emit-training-event.test.ts b/libs/training-events/src/actions/emit-training-event.test.ts index 21255bf..8267043 100644 --- a/libs/training-events/src/actions/emit-training-event.test.ts +++ b/libs/training-events/src/actions/emit-training-event.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, it, expect } from "vitest"; -import { TrainingEventData } from "../types"; +import { TrainingEventData } from "@rovacc/training-events-types"; import { emitTrainingEvent } from "./emit-training-event"; import { deleteCollection } from "@rovacc/test-helpers"; @@ -27,7 +27,7 @@ describe('emitTrainingEvent', () => { vi.restoreAllMocks() }) - it('should emit the event correctly', async () => { + it('should emit the event correctly and create the empty training object', async () => { const eventData: TrainingEventData = { trainingId: TRAINING_ID, name: 'training-intent', @@ -62,37 +62,45 @@ describe('emitTrainingEvent', () => { }) }) - it('should emit the event', async () => { - const eventData: TrainingEventData = { - trainingId: TRAINING_ID, - name: 'training-intent', - payload: { - student: 1364858, - rating: 5, - purpose: 'acquire_rating' - } - } - - const reducedTraining = await emitTrainingEvent(eventData, null, 'correlationId') + it('should emit the event and not alter the training object', async () => { - expect(reducedTraining).toEqual({ - trainingId: TRAINING_ID, - status: 'QUEUED', + const trainingCollection = getDatabaseCollection('training') + await trainingCollection.doc(TRAINING_ID).set({ purpose: 'acquire_rating', rating: 5, student: 1364858, requestedAt: DATE }) - const trainingCollection = getDatabaseCollection('training') + await trainingCollection.doc(TRAINING_ID).collection('events').doc('event-id').set({ + const eventData: TrainingEventData = { + trainingId: TRAINING_ID, + name: 'training-test-completed', + payload: { + passed: true, + result: 'passed', + willExpireAt: new Date() + } + } + + const reducedTraining = await emitTrainingEvent(eventData, null, 'correlationId') + + expect(reducedTraining).toEqual({ + trainingId: TRAINING_ID, + status: 'QUEUED', + purpose: 'acquire_rating', + rating: 5, + student: 1364858, + requestedAt: DATE + }) const event = await trainingCollection.doc(TRAINING_ID).collection('events').doc(EVENT_ID).get() expect(event.data()).toEqual({ - eventId: EVENT_ID, - emittedAt: Timestamp.fromDate(DATE), - system: 'rovacc-system-id', - trainingId: TRAINING_ID, - payload: { student: 1364858, purpose: 'acquire_rating', rating: 5 }, - name: 'training-intent', - correlationId: 'correlationId' - }) + eventId: EVENT_ID, + emittedAt: Timestamp.fromDate(DATE), + system: 'rovacc-system-id', + trainingId: TRAINING_ID, + payload: { student: 1364858, purpose: 'acquire_rating', rating: 5 }, + name: 'training-intent', + correlationId: 'correlationId' + }) }) }) diff --git a/libs/training-events/src/actions/emit-training-event.ts b/libs/training-events/src/actions/emit-training-event.ts index 7b7bfb0..95a0180 100644 --- a/libs/training-events/src/actions/emit-training-event.ts +++ b/libs/training-events/src/actions/emit-training-event.ts @@ -1,5 +1,5 @@ import { v4 as uuidv4 } from "uuid"; -import { Training, TrainingEvent, TrainingEventData } from "../types"; +import { Training, TrainingEvent, TrainingEventData } from "@rovacc/training-events-types"; import { SYSTEM_ID, TRAINING_COLLECTION, TRAINING_EVENTS_SUBCOLLECTION } from '../config' import { getDatabaseCollection } from '@rovacc/clients' import { isEmitted, reduceEvent } from "../events"; diff --git a/libs/training-events/src/actions/get-training-events.ts b/libs/training-events/src/actions/get-training-events.ts index 8e7ff56..04db386 100644 --- a/libs/training-events/src/actions/get-training-events.ts +++ b/libs/training-events/src/actions/get-training-events.ts @@ -1,5 +1,5 @@ import { getDatabaseCollection } from "@rovacc/clients"; -import { Training, TrainingEvent } from "../types"; +import { Training, TrainingEvent } from "@rovacc/training-events-types"; import { TRAINING_COLLECTION, TRAINING_EVENTS_SUBCOLLECTION } from "../config"; import { TrainingNotFound } from "../exception/training-not-found"; diff --git a/libs/training-events/src/events/reducer.ts b/libs/training-events/src/events/reducer.ts index 5f2e83e..0636192 100644 --- a/libs/training-events/src/events/reducer.ts +++ b/libs/training-events/src/events/reducer.ts @@ -1,4 +1,4 @@ -import { IsEmitted, Reducer, Training, TrainingEvent } from "../types"; +import { IsEmitted, Reducer, Training, TrainingEvent } from "@rovacc/training-events-types"; import { trainingCompleted } from "./training-completed"; import { trainingCptPerformed } from "./training-cpt-performed"; import { trainingCptRequested } from "./training-cpt-requested"; diff --git a/libs/training-events/src/events/training-completed.ts b/libs/training-events/src/events/training-completed.ts index cce3bd8..c89fe50 100644 --- a/libs/training-events/src/events/training-completed.ts +++ b/libs/training-events/src/events/training-completed.ts @@ -1,19 +1,8 @@ -import { OutcomeReason, OutcomeReasonDetailed, Reducer, Training, TrainingEventMetadata } from "../types"; +import { TrainingCompletedEvent, Reducer, Training } from "@rovacc/training-events-types"; const name = 'training-completed' -export type TrainingCompletedEventData = { - trainingId: string, - name: typeof name - payload: { - reason: OutcomeReason - reasonDetailed: OutcomeReasonDetailed - } -} - -export type TrainingCompletedEvent = TrainingEventMetadata & TrainingCompletedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingCompletedEvent diff --git a/libs/training-events/src/events/training-cpt-performed.ts b/libs/training-events/src/events/training-cpt-performed.ts index 45d2290..169eea0 100644 --- a/libs/training-events/src/events/training-cpt-performed.ts +++ b/libs/training-events/src/events/training-cpt-performed.ts @@ -1,20 +1,8 @@ -import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from "../types"; +import { Reducer, Training, TrainingCptPerformedEvent } from "@rovacc/training-events-types"; const name = 'training-cpt-performed' -export type TrainingCptPerformedEventData = { - trainingId: string, - name: typeof name - payload: { - assessedBy: Member - report: TrainingReport - passed: boolean - } -} - -export type TrainingCptPerformedEvent = TrainingEventMetadata & TrainingCptPerformedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingCptPerformedEvent diff --git a/libs/training-events/src/events/training-cpt-requested.ts b/libs/training-events/src/events/training-cpt-requested.ts index b8aa9a5..2a4bac0 100644 --- a/libs/training-events/src/events/training-cpt-requested.ts +++ b/libs/training-events/src/events/training-cpt-requested.ts @@ -1,18 +1,8 @@ -import { Member, Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingCptRequestedEvent } from "@rovacc/training-events-types"; const name = 'training-cpt-requested' -export type TrainingCptRequestedEventData = { - trainingId: string, - name: typeof name - payload: { - requestedBy: Member - } -} - -export type TrainingCptRequestedEvent = TrainingEventMetadata & TrainingCptRequestedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingCptRequestedEvent diff --git a/libs/training-events/src/events/training-cpt-scheduled.ts b/libs/training-events/src/events/training-cpt-scheduled.ts index 703a591..88a778d 100644 --- a/libs/training-events/src/events/training-cpt-scheduled.ts +++ b/libs/training-events/src/events/training-cpt-scheduled.ts @@ -1,18 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingCptScheduledEvent } from "@rovacc/training-events-types"; const name = 'training-cpt-scheduled' -export type TrainingCptScheduledEventData = { - trainingId: string, - name: typeof name - payload: { - scheduledAt: Date - } -} - -export type TrainingCptScheduledEvent = TrainingEventMetadata & TrainingCptScheduledEventData - const reducer: Reducer = ( training: Training | null, event: TrainingCptScheduledEvent diff --git a/libs/training-events/src/events/training-intent-confirmation-expired.ts b/libs/training-events/src/events/training-intent-confirmation-expired.ts index 3aeda38..ab19436 100644 --- a/libs/training-events/src/events/training-intent-confirmation-expired.ts +++ b/libs/training-events/src/events/training-intent-confirmation-expired.ts @@ -1,16 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingIntentConfirmationExpiredEvent } from "@rovacc/training-events-types"; const name = 'training-intent-confirmation-expired'; -export type TrainingIntentConfirmationExpiredEventData = { - name: typeof name - trainingId: string - payload: Record -} - -export type TrainingIntentConfirmationExpiredEvent = TrainingEventMetadata & TrainingIntentConfirmationExpiredEventData - const reducer: Reducer = ( training: Training | null, event: TrainingIntentConfirmationExpiredEvent diff --git a/libs/training-events/src/events/training-intent-confirmation-rejected.ts b/libs/training-events/src/events/training-intent-confirmation-rejected.ts index 0cdce34..a925ff0 100644 --- a/libs/training-events/src/events/training-intent-confirmation-rejected.ts +++ b/libs/training-events/src/events/training-intent-confirmation-rejected.ts @@ -1,15 +1,7 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingIntentConfirmationRejectedEvent } from "@rovacc/training-events-types"; const name = 'training-intent-confirmation-rejected'; -export type TrainingIntentConfirmationRejectedEventData = { - name: typeof name - trainingId: string - payload: Record -} - -export type TrainingIntentConfirmationRejectedEvent = TrainingEventMetadata & TrainingIntentConfirmationRejectedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingIntentConfirmationRejectedEvent diff --git a/libs/training-events/src/events/training-intent-confirmation-requested.ts b/libs/training-events/src/events/training-intent-confirmation-requested.ts index ec8c89a..ed92d88 100644 --- a/libs/training-events/src/events/training-intent-confirmation-requested.ts +++ b/libs/training-events/src/events/training-intent-confirmation-requested.ts @@ -1,16 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingIntentConfirmationRequestedEvent } from "@rovacc/training-events-types"; const name = 'training-intent-confirmation-requested'; -export type TrainingIntentConfirmationRequestedEventData = { - name: typeof name - trainingId: string - payload: Record -} - -export type TrainingIntentConfirmationRequestedEvent = TrainingEventMetadata & TrainingIntentConfirmationRequestedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingIntentConfirmationRequestedEvent diff --git a/libs/training-events/src/events/training-intent-confirmation-responded.ts b/libs/training-events/src/events/training-intent-confirmation-responded.ts index f5a0572..fc3b936 100644 --- a/libs/training-events/src/events/training-intent-confirmation-responded.ts +++ b/libs/training-events/src/events/training-intent-confirmation-responded.ts @@ -1,16 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingIntentConfirmationRespondedEvent } from "@rovacc/training-events-types"; const name = 'training-intent-confirmation-responded'; -export type TrainingIntentConfirmationRespondedEventData = { - name: typeof name - trainingId: string - payload: Record -} - -export type TrainingIntentConfirmationRespondedEvent = TrainingEventMetadata & TrainingIntentConfirmationRespondedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingIntentConfirmationRespondedEvent diff --git a/libs/training-events/src/events/training-intent.ts b/libs/training-events/src/events/training-intent.ts index b0faa02..920486d 100644 --- a/libs/training-events/src/events/training-intent.ts +++ b/libs/training-events/src/events/training-intent.ts @@ -1,20 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata, TrainingPurpose } from "../types"; +import { Reducer, Training, TrainingIntentEvent } from "@rovacc/training-events-types"; const name = 'training-intent'; -export type TrainingIntentEventData = { - trainingId: string, - name: typeof name - payload: { - student: number - rating: number - purpose: TrainingPurpose - } -} - -export type TrainingIntentEvent = TrainingEventMetadata & TrainingIntentEventData - const reducer: Reducer = ( training: Training | null, event: TrainingIntentEvent diff --git a/libs/training-events/src/events/training-mentor-assigned.ts b/libs/training-events/src/events/training-mentor-assigned.ts index f91b9ac..5283295 100644 --- a/libs/training-events/src/events/training-mentor-assigned.ts +++ b/libs/training-events/src/events/training-mentor-assigned.ts @@ -1,18 +1,7 @@ -import { Member, Reducer, Training, TrainingEventMetadata } from "../types"; +import { Member, Reducer, Training, TrainingMentorAssignedEvent } from "@rovacc/training-events-types"; const name = 'training-mentor-assigned' -export type TrainingMentorAssignedEventData = { - name: typeof name - trainingId: string - payload: { - mentor: Member - assigned_by: Member - } -} - -export type TrainingMentorAssignedEvent = TrainingEventMetadata & TrainingMentorAssignedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingMentorAssignedEvent @@ -23,7 +12,7 @@ const reducer: Reducer = ( mentor: { member: event.payload.mentor, assignedAt: event.emittedAt, - assignedBy: event.payload.assigned_by, + assignedBy: event.payload.assignedBy, } }) diff --git a/libs/training-events/src/events/training-mentor-reassigned.ts b/libs/training-events/src/events/training-mentor-reassigned.ts index 9b1a2db..ae129f0 100644 --- a/libs/training-events/src/events/training-mentor-reassigned.ts +++ b/libs/training-events/src/events/training-mentor-reassigned.ts @@ -1,18 +1,7 @@ -import { Member, Reducer, Training, TrainingEventMetadata } from "../types"; +import { Member, Reducer, Training, TrainingMentorReassignedEvent } from "@rovacc/training-events-types"; const name = 'training-mentor-reassigned' -export type TrainingMentorReassignedEventData = { - name: typeof name - trainingId: string - payload: { - mentor: Member - assigned_by: Member - } -} - -export type TrainingMentorReassignedEvent = TrainingEventMetadata & TrainingMentorReassignedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingMentorReassignedEvent @@ -23,7 +12,7 @@ const reducer: Reducer = ( mentor: { member: event.payload.mentor, assignedAt: event.emittedAt, - assignedBy: event.payload.assigned_by, + assignedBy: event.payload.assignedBy, } }) diff --git a/libs/training-events/src/events/training-session-performed.ts b/libs/training-events/src/events/training-session-performed.ts index c7fb8da..e596895 100644 --- a/libs/training-events/src/events/training-session-performed.ts +++ b/libs/training-events/src/events/training-session-performed.ts @@ -1,19 +1,7 @@ -import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from "../types"; +import { Reducer, Training, TrainingSessionPerformedEvent } from "@rovacc/training-events-types"; const name = 'training-session-performed' -export type TrainingSessionPerformedEventData = { - name: typeof name - trainingId: string - payload: { - sessionId: string - mentor: Member, - report: TrainingReport - } -} - -export type TrainingSessionPerformedEvent = TrainingEventMetadata & TrainingSessionPerformedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingSessionPerformedEvent diff --git a/libs/training-events/src/events/training-session-scheduled.ts b/libs/training-events/src/events/training-session-scheduled.ts index 4627ebd..3e7b950 100644 --- a/libs/training-events/src/events/training-session-scheduled.ts +++ b/libs/training-events/src/events/training-session-scheduled.ts @@ -1,18 +1,7 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingSessionScheduledEvent } from "@rovacc/training-events-types"; const name = 'training-session-scheduled' -export type TrainingSessionScheduledEventData = { - name: typeof name - trainingId: string - payload: { - sessionId: string - scheduledAt: Date - } -} - -export type TrainingSessionScheduledEvent = TrainingEventMetadata & TrainingSessionScheduledEventData - const reducer: Reducer = ( training: Training | null, event: TrainingSessionScheduledEvent diff --git a/libs/training-events/src/events/training-solo-performed.ts b/libs/training-events/src/events/training-solo-performed.ts index ac0dd3d..58458d6 100644 --- a/libs/training-events/src/events/training-solo-performed.ts +++ b/libs/training-events/src/events/training-solo-performed.ts @@ -1,20 +1,8 @@ -import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from "../types"; +import { Reducer, Training, TrainingSoloPerformedEvent } from "@rovacc/training-events-types"; const name = 'training-solo-performed' -export type TrainingSoloPerformedEventData = { - trainingId: string, - name: typeof name - payload: { - requestedBy: Member - passed: boolean - report: TrainingReport - } -} - -export type TrainingSoloPerformedEvent = TrainingEventMetadata & TrainingSoloPerformedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingSoloPerformedEvent diff --git a/libs/training-events/src/events/training-solo-requested.ts b/libs/training-events/src/events/training-solo-requested.ts index 1aa24ef..be101b1 100644 --- a/libs/training-events/src/events/training-solo-requested.ts +++ b/libs/training-events/src/events/training-solo-requested.ts @@ -1,18 +1,8 @@ -import { Member, Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingSoloRequestedEvent } from "@rovacc/training-events-types"; const name = 'training-solo-requested' -export type TrainingSoloRequestedEventData = { - trainingId: string, - name: typeof name - payload: { - requestedBy: Member - } -} - -export type TrainingSoloRequestedEvent = TrainingEventMetadata & TrainingSoloRequestedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingSoloRequestedEvent diff --git a/libs/training-events/src/events/training-solo-scheduled.ts b/libs/training-events/src/events/training-solo-scheduled.ts index afb8f4d..72b5f27 100644 --- a/libs/training-events/src/events/training-solo-scheduled.ts +++ b/libs/training-events/src/events/training-solo-scheduled.ts @@ -1,18 +1,8 @@ -import { Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingSoloScheduledEvent } from "@rovacc/training-events-types"; const name = 'training-solo-scheduled' -export type TrainingSoloScheduledEventData = { - trainingId: string, - name: typeof name - payload: { - scheduledAt: Date - } -} - -export type TrainingSoloScheduledEvent = TrainingEventMetadata & TrainingSoloScheduledEventData - const reducer: Reducer = ( training: Training | null, event: TrainingSoloScheduledEvent diff --git a/libs/training-events/src/events/training-test-assigned.ts b/libs/training-events/src/events/training-test-assigned.ts index 810e8c5..a5c2a50 100644 --- a/libs/training-events/src/events/training-test-assigned.ts +++ b/libs/training-events/src/events/training-test-assigned.ts @@ -1,18 +1,8 @@ -import { Member, Reducer, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingTestAssignedEvent } from "@rovacc/training-events-types"; const name = 'training-test-assigned' -export type TrainingTestAssignedEventData = { - trainingId: string, - name: typeof name - payload: { - assignedBy: Member - } -} - -export type TrainingTestAssignedEvent = TrainingEventMetadata & TrainingTestAssignedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingTestAssignedEvent diff --git a/libs/training-events/src/events/training-test-completed.ts b/libs/training-events/src/events/training-test-completed.ts index a0f0068..cea01e0 100644 --- a/libs/training-events/src/events/training-test-completed.ts +++ b/libs/training-events/src/events/training-test-completed.ts @@ -1,19 +1,7 @@ -import { Reducer, TestResult, Training, TrainingEventMetadata } from "../types"; +import { Reducer, Training, TrainingTestCompletedEvent } from "@rovacc/training-events-types"; const name = 'training-test-completed' -export type TrainingTestCompletedEventData = { - trainingId: string, - name: typeof name - payload: { - passed: boolean - result: TestResult - willExpireAt?: Date - } -} - -export type TrainingTestCompletedEvent = TrainingEventMetadata & TrainingTestCompletedEventData - const reducer: Reducer = ( training: Training | null, event: TrainingTestCompletedEvent diff --git a/libs/training-events/src/index.ts b/libs/training-events/src/index.ts index 259500d..8b342eb 100644 --- a/libs/training-events/src/index.ts +++ b/libs/training-events/src/index.ts @@ -1,5 +1,5 @@ export * from './events' -export { applyReducer } from './events/reducer' +export { reduceEvent } from './events/reducer' export type { Member, @@ -12,3 +12,23 @@ export type { TrainingPurpose, TrainingStatus, } from './types' + +export type { TrainingCompletedEvent, TrainingCompletedEventData } from "./events/training-completed" +export type { TrainingCptPerformedEvent, TrainingCptPerformedEventData } from "./events/training-cpt-performed" +export type { TrainingCptRequestedEvent, TrainingCptRequestedEventData } from "./events/training-cpt-requested" +export type { TrainingCptScheduledEvent, TrainingCptScheduledEventData } from "./events/training-cpt-scheduled" +export type { TrainingIntentConfirmationExpiredEvent, TrainingIntentConfirmationExpiredEventData } from "./events/training-intent-confirmation-expired" +export type { TrainingIntentConfirmationRejectedEvent, TrainingIntentConfirmationRejectedEventData } from "./events/training-intent-confirmation-rejected" +export type { TrainingIntentConfirmationRequestedEvent, TrainingIntentConfirmationRequestedEventData } from "./events/training-intent-confirmation-requested" +export type { TrainingIntentConfirmationRespondedEvent, TrainingIntentConfirmationRespondedEventData } from "./events/training-intent-confirmation-responded" +export type { TrainingIntentEvent, TrainingIntentEventData } from "./events/training-intent" +export type { TrainingMentorAssignedEvent, TrainingMentorAssignedEventData } from "./events/training-mentor-assigned" +export type { TrainingMentorReassignedEvent, TrainingMentorReassignedEventData } from "./events/training-mentor-reassigned" +export type { TrainingSessionPerformedEvent, TrainingSessionPerformedEventData } from "./events/training-session-performed" +export type { TrainingSessionScheduledEvent, TrainingSessionScheduledEventData } from "./events/training-session-scheduled" +export type { TrainingSoloPerformedEvent, TrainingSoloPerformedEventData } from "./events/training-solo-performed" +export type { TrainingSoloRequestedEvent, TrainingSoloRequestedEventData } from "./events/training-solo-requested" +export type { TrainingSoloScheduledEvent, TrainingSoloScheduledEventData } from "./events/training-solo-scheduled" +export type { TrainingTestAssignedEvent, TrainingTestAssignedEventData } from "./events/training-test-assigned" +export type { TrainingTestCompletedEvent, TrainingTestCompletedEventData } from "./events/training-test-completed" + diff --git a/libs/training-events/src/types.ts b/libs/training-events/src/types.ts deleted file mode 100644 index dbeb6c0..0000000 --- a/libs/training-events/src/types.ts +++ /dev/null @@ -1,158 +0,0 @@ -import { TrainingCompletedEvent, TrainingCompletedEventData } from "./events/training-completed" -import { TrainingCptPerformedEvent, TrainingCptPerformedEventData } from "./events/training-cpt-performed" -import { TrainingCptRequestedEvent, TrainingCptRequestedEventData } from "./events/training-cpt-requested" -import { TrainingCptScheduledEvent, TrainingCptScheduledEventData } from "./events/training-cpt-scheduled" -import { TrainingIntentEvent, TrainingIntentEventData } from "./events/training-intent" -import { TrainingIntentConfirmationExpiredEvent, TrainingIntentConfirmationExpiredEventData } from "./events/training-intent-confirmation-expired" -import { TrainingIntentConfirmationRejectedEvent, TrainingIntentConfirmationRejectedEventData } from "./events/training-intent-confirmation-rejected" -import { TrainingIntentConfirmationRequestedEvent, TrainingIntentConfirmationRequestedEventData } from "./events/training-intent-confirmation-requested" -import { TrainingIntentConfirmationRespondedEvent, TrainingIntentConfirmationRespondedEventData } from "./events/training-intent-confirmation-responded" -import { TrainingMentorAssignedEvent, TrainingMentorAssignedEventData } from "./events/training-mentor-assigned" -import { TrainingMentorReassignedEvent, TrainingMentorReassignedEventData } from "./events/training-mentor-reassigned" -import { TrainingSessionPerformedEvent, TrainingSessionPerformedEventData } from "./events/training-session-performed" -import { TrainingSessionScheduledEvent, TrainingSessionScheduledEventData } from "./events/training-session-scheduled" -import { TrainingSoloPerformedEvent, TrainingSoloPerformedEventData } from "./events/training-solo-performed" -import { TrainingSoloRequestedEvent, TrainingSoloRequestedEventData } from "./events/training-solo-requested" -import { TrainingSoloScheduledEvent, TrainingSoloScheduledEventData } from "./events/training-solo-scheduled" -import { TrainingTestAssignedEvent, TrainingTestAssignedEventData } from "./events/training-test-assigned" -import { TrainingTestCompletedEvent, TrainingTestCompletedEventData } from "./events/training-test-completed" - -export type TrainingEvent = - | TrainingCompletedEvent - | TrainingCptPerformedEvent - | TrainingCptScheduledEvent - | TrainingIntentConfirmationExpiredEvent - | TrainingIntentConfirmationRejectedEvent - | TrainingIntentConfirmationRequestedEvent - | TrainingIntentConfirmationRespondedEvent - | TrainingIntentEvent - | TrainingMentorAssignedEvent - | TrainingMentorReassignedEvent - | TrainingSessionPerformedEvent - | TrainingSessionScheduledEvent - | TrainingSoloPerformedEvent - | TrainingSoloRequestedEvent - | TrainingSoloScheduledEvent - | TrainingTestAssignedEvent - | TrainingTestCompletedEvent - | TrainingCptRequestedEvent - -export type TrainingEventData = - | TrainingCompletedEventData - | TrainingCptPerformedEventData - | TrainingCptScheduledEventData - | TrainingIntentConfirmationExpiredEventData - | TrainingIntentConfirmationRejectedEventData - | TrainingIntentConfirmationRequestedEventData - | TrainingIntentConfirmationRespondedEventData - | TrainingIntentEventData - | TrainingMentorAssignedEventData - | TrainingMentorReassignedEventData - | TrainingSessionPerformedEventData - | TrainingSessionScheduledEventData - | TrainingSoloPerformedEventData - | TrainingSoloRequestedEventData - | TrainingSoloScheduledEventData - | TrainingTestAssignedEventData - | TrainingTestCompletedEventData - | TrainingCptRequestedEventData - -export type Member = { - id: number - name: string -} - -export type TrainingStatus = - | "QUEUED" - | "STARTED" - | "AWAITING_TEST" - | "IN_PROGRESS" - | "AWAITING_SOLO" - | "SOLO" - | "AWAITING_CPT" - | "COMPLETED" - | "TERMINATED" - -export type TrainingPurpose = "acquire_rating" | "revalidate_rating" | "visiting" -export type TestResult = "passed" | "failed" -export type TrainingReport = { - purpose: "cpt_ots" | "revalidation" | "training" | "sim_session" - workload: "light" | 'moderate' | 'heavy' - complexity: "routine" | "occasionally_difficult" | "mostly_difficult" | "very_difficult" - traffic: "light" | "medium" | "heavy" - comments: string -} - -export type TrainingSessions = { - scheduledAt?: Date - mentor?: Member, - report?: TrainingReport -} - -export type OutcomeReason = - | "completed" - | "terminated" - -export type OutcomeReasonDetailed = - | "rating_upgraded" - | "student_did_not_confirm_intent" - | "student_cancelled_training" - | "atsimtest_expired" - -export type Training = { - trainingId: string - status: TrainingStatus, - requestedAt?: Date - student?: number - rating?: number - purpose?: TrainingPurpose - mentor?: { - member: Member - assignedBy: Member - assignedAt: Date - } - intentConfirmation?: { - requestedAt?: Date - respondedAt?: Date - rejectedAt?: Date - expiredAt?: Date - } - test?: { - assignedAt?: Date - assignedBy?: Member - completedAt?: Date - result?: TestResult - willExpireAt?: Date - passed?: boolean - } - sessions?: Record - solo?: { - requestedAt?: Date - requestedBy?: Member - scheduledAt?: Date - performedBy?: Member - report?: TrainingReport - passed?: boolean - } - cpt?: { - requestedAt?: Date - scheduledAt?: Date - assessedBy?: Member - report?: TrainingReport - passed?: boolean - } - completedAt?: Date - outcome?: OutcomeReason - outcomeDetailed?: OutcomeReasonDetailed -} - -export type Reducer = (training: Training | null, event: T) => Training -export type IsEmitted = (training: Training | null, event: T) => boolean - -export type TrainingEventMetadata = { - eventId: string - emittedAt: Date - system: string - correlationId: string -} - diff --git a/tsconfig.base.json b/tsconfig.base.json index 9c5c0cb..1deb724 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -17,7 +17,10 @@ "paths": { "@rovacc/clients": ["libs/clients/src/index.ts"], "@rovacc/test-helpers": ["libs/test-helpers/src/index.ts"], - "@rovacc/training-events": ["libs/training-events/src/index.ts"] + "@rovacc/training-events": ["libs/training-events/src/index.ts"], + "@rovacc/training-events-types": [ + "libs/training-events-types/src/index.ts" + ] } }, "exclude": ["node_modules", "tmp"]