From e8b8cb996736fb0c27def2cf056dffd7a14d5e90 Mon Sep 17 00:00:00 2001 From: George Enciu Date: Tue, 20 Jun 2023 21:19:40 +0200 Subject: [PATCH] #1 fix typos --- .../src/actions/emit-training-event.ts | 50 ++++++++------- .../training-intent-confirmation-expired.ts | 25 +++++--- .../training-intent-confirmation-rejected.ts | 24 +++++--- .../training-intent-confirmation-requested.ts | 25 +++++--- .../training-intent-confirmation-responded.ts | 26 +++++--- .../src/events/training-mentor-assigned.ts | 18 +++--- .../src/events/training-mentor-reassigned.ts | 22 ++++--- .../src/events/training-session-performed.ts | 27 +++++--- .../src/events/training-session-scheduled.ts | 27 +++++--- libs/training-events/src/types.ts | 61 ++++++++++++------- package.json | 2 + 11 files changed, 193 insertions(+), 114 deletions(-) diff --git a/libs/training-events/src/actions/emit-training-event.ts b/libs/training-events/src/actions/emit-training-event.ts index 95a0180..a96387c 100644 --- a/libs/training-events/src/actions/emit-training-event.ts +++ b/libs/training-events/src/actions/emit-training-event.ts @@ -1,40 +1,48 @@ -import { v4 as uuidv4 } from "uuid"; -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"; -import { getDate } from "../helpers/get-date"; - - -export const emitTrainingEvent = async (eventData: TrainingEventData, training: Training | null, correlationId: string): Promise => { - - const trainingId = eventData.trainingId +import { v4 as uuidv4 } from 'uuid'; +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'; +import { getDate } from '../helpers/get-date'; + +export const emitTrainingEvent = async ( + eventData: TrainingEventData, + training: Training | null, + correlationId: string +): Promise => { + const trainingId = eventData.trainingId; const event: TrainingEvent = { eventId: uuidv4(), emittedAt: getDate(), system: SYSTEM_ID, correlationId, ...eventData, - } + }; if (isEmitted[event.name] && isEmitted[event.name](training, event)) { - return training + return training; } - const trainingCollection = getDatabaseCollection(TRAINING_COLLECTION) + const trainingCollection = getDatabaseCollection(TRAINING_COLLECTION); - const trainingObj = await trainingCollection.doc(trainingId).get() + const trainingObj = await trainingCollection.doc(trainingId).get(); if (!trainingObj.exists) { - await trainingCollection - .doc(trainingId) - .set({ trainingId }) + await trainingCollection.doc(trainingId).set({ trainingId }); } await trainingCollection .doc(trainingId) .collection(TRAINING_EVENTS_SUBCOLLECTION) .doc(event.eventId) - .set(event) + .set(event); - return reduceEvent(training, event) -} + return reduceEvent(training, event); +}; 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 ab19436..277ecf7 100644 --- a/libs/training-events/src/events/training-intent-confirmation-expired.ts +++ b/libs/training-events/src/events/training-intent-confirmation-expired.ts @@ -1,5 +1,8 @@ - -import { Reducer, Training, TrainingIntentConfirmationExpiredEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingIntentConfirmationExpiredEvent, +} from '@rovacc/training-events-types'; const name = 'training-intent-confirmation-expired'; @@ -13,12 +16,16 @@ const reducer: Reducer = ( intentConfirmation: { ...training?.intentConfirmation, expiredAt: event.emittedAt, - } -}) - -const isEmitted = - (training: Training | null) => - training && training?.intentConfirmation && !!training.intentConfirmation.expiredAt + }, +}); -export const trainingIntentConfirmationExpired = { name, reducer, isEmitted } as const +const isEmitted = (training: Training | null) => + training && + training?.intentConfirmation && + !!training.intentConfirmation.expiredAt; +export const trainingIntentConfirmationExpired = { + name, + reducer, + isEmitted, +} as const; 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 a925ff0..d80c665 100644 --- a/libs/training-events/src/events/training-intent-confirmation-rejected.ts +++ b/libs/training-events/src/events/training-intent-confirmation-rejected.ts @@ -1,4 +1,8 @@ -import { Reducer, Training, TrainingIntentConfirmationRejectedEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingIntentConfirmationRejectedEvent, +} from '@rovacc/training-events-types'; const name = 'training-intent-confirmation-rejected'; @@ -12,12 +16,16 @@ const reducer: Reducer = ( intentConfirmation: { ...training?.intentConfirmation, rejectedAt: event.emittedAt, - } -}) + }, +}); -const isEmitted = - (training: Training | null) => - training && training?.intentConfirmation && training.intentConfirmation.rejectedAt - -export const trainingIntentConfirmationRejected = { name, reducer, isEmitted } as const +const isEmitted = (training: Training | null) => + training && + training?.intentConfirmation && + training.intentConfirmation.rejectedAt; +export const trainingIntentConfirmationRejected = { + name, + reducer, + isEmitted, +} as const; 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 ed92d88..284fc6e 100644 --- a/libs/training-events/src/events/training-intent-confirmation-requested.ts +++ b/libs/training-events/src/events/training-intent-confirmation-requested.ts @@ -1,5 +1,8 @@ - -import { Reducer, Training, TrainingIntentConfirmationRequestedEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingIntentConfirmationRequestedEvent, +} from '@rovacc/training-events-types'; const name = 'training-intent-confirmation-requested'; @@ -12,12 +15,16 @@ const reducer: Reducer = ( trainingId: event.trainingId, intentConfirmation: { requestedAt: event.emittedAt, - } -}) - -const isEmitted = - (training: Training | null) => - training && training?.intentConfirmation && !!training.intentConfirmation.requestedAt + }, +}); -export const trainingIntentConfirmationRequested = { name, reducer, isEmitted } as const +const isEmitted = (training: Training | null) => + training && + training?.intentConfirmation && + !!training.intentConfirmation.requestedAt; +export const trainingIntentConfirmationRequested = { + name, + reducer, + isEmitted, +} as const; 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 fc3b936..d884c9b 100644 --- a/libs/training-events/src/events/training-intent-confirmation-responded.ts +++ b/libs/training-events/src/events/training-intent-confirmation-responded.ts @@ -1,5 +1,8 @@ - -import { Reducer, Training, TrainingIntentConfirmationRespondedEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingIntentConfirmationRespondedEvent, +} from '@rovacc/training-events-types'; const name = 'training-intent-confirmation-responded'; @@ -13,13 +16,16 @@ const reducer: Reducer = ( intentConfirmation: { ...training?.intentConfirmation, respondedAt: event.emittedAt, + }, +}); - } -}) - -const isEmitted = - (training: Training | null) => - training && training?.intentConfirmation && training.intentConfirmation.respondedAt - -export const trainingIntentConfirmationResponded = { name, reducer, isEmitted } as const +const isEmitted = (training: Training | null) => + training && + training?.intentConfirmation && + training.intentConfirmation.respondedAt; +export const trainingIntentConfirmationResponded = { + name, + reducer, + isEmitted, +} as const; diff --git a/libs/training-events/src/events/training-mentor-assigned.ts b/libs/training-events/src/events/training-mentor-assigned.ts index 5283295..19c4dd2 100644 --- a/libs/training-events/src/events/training-mentor-assigned.ts +++ b/libs/training-events/src/events/training-mentor-assigned.ts @@ -1,6 +1,11 @@ -import { Member, Reducer, Training, TrainingMentorAssignedEvent } from "@rovacc/training-events-types"; +import { + Member, + Reducer, + Training, + TrainingMentorAssignedEvent, +} from '@rovacc/training-events-types'; -const name = 'training-mentor-assigned' +const name = 'training-mentor-assigned'; const reducer: Reducer = ( training: Training | null, @@ -13,10 +18,9 @@ const reducer: Reducer = ( member: event.payload.mentor, assignedAt: event.emittedAt, assignedBy: event.payload.assignedBy, - } -}) + }, +}); -const isEmitted = (training: Training | null) => !!training?.mentor - -export const trainingMentorAssigned = { name, reducer, isEmitted } as const +const isEmitted = (training: Training | null) => !!training?.mentor; +export const trainingMentorAssigned = { name, reducer, isEmitted } as const; diff --git a/libs/training-events/src/events/training-mentor-reassigned.ts b/libs/training-events/src/events/training-mentor-reassigned.ts index ae129f0..a45abde 100644 --- a/libs/training-events/src/events/training-mentor-reassigned.ts +++ b/libs/training-events/src/events/training-mentor-reassigned.ts @@ -1,6 +1,11 @@ -import { Member, Reducer, Training, TrainingMentorReassignedEvent } from "@rovacc/training-events-types"; +import { + Member, + Reducer, + Training, + TrainingMentorReassignedEvent, +} from '@rovacc/training-events-types'; -const name = 'training-mentor-reassigned' +const name = 'training-mentor-reassigned'; const reducer: Reducer = ( training: Training | null, @@ -13,11 +18,12 @@ const reducer: Reducer = ( member: event.payload.mentor, assignedAt: event.emittedAt, assignedBy: event.payload.assignedBy, - } -}) + }, +}); -const isEmitted = - (training: Training | null, event: TrainingMentorReassignedEvent) => training && training?.mentor?.member.id !== event.payload.mentor.id - -export const trainingMentorReassigned = { name, reducer, isEmitted } as const +const isEmitted = ( + training: Training | null, + event: TrainingMentorReassignedEvent +) => training && training?.mentor?.member.id !== event.payload.mentor.id; +export const trainingMentorReassigned = { name, reducer, isEmitted } as const; diff --git a/libs/training-events/src/events/training-session-performed.ts b/libs/training-events/src/events/training-session-performed.ts index e596895..bd70160 100644 --- a/libs/training-events/src/events/training-session-performed.ts +++ b/libs/training-events/src/events/training-session-performed.ts @@ -1,6 +1,10 @@ -import { Reducer, Training, TrainingSessionPerformedEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingSessionPerformedEvent, +} from '@rovacc/training-events-types'; -const name = 'training-session-performed' +const name = 'training-session-performed'; const reducer: Reducer = ( training: Training | null, @@ -15,13 +19,16 @@ const reducer: Reducer = ( ...training?.sessions?.[event.payload.sessionId], mentor: event.payload.mentor, report: event.payload.report, - } - } -}) + }, + }, +}); -const isEmitted = - (training: Training | null, event: TrainingSessionPerformedEvent) => - !!training?.sessions && !!training.sessions[event.payload.sessionId] && !!training.sessions[event.payload.sessionId].report - -export const trainingSessionPerformed = { name, reducer, isEmitted } as const +const isEmitted = ( + training: Training | null, + event: TrainingSessionPerformedEvent +) => + !!training?.sessions && + !!training.sessions[event.payload.sessionId] && + !!training.sessions[event.payload.sessionId].report; +export const trainingSessionPerformed = { name, reducer, isEmitted } as const; diff --git a/libs/training-events/src/events/training-session-scheduled.ts b/libs/training-events/src/events/training-session-scheduled.ts index 3e7b950..1a0e970 100644 --- a/libs/training-events/src/events/training-session-scheduled.ts +++ b/libs/training-events/src/events/training-session-scheduled.ts @@ -1,6 +1,10 @@ -import { Reducer, Training, TrainingSessionScheduledEvent } from "@rovacc/training-events-types"; +import { + Reducer, + Training, + TrainingSessionScheduledEvent, +} from '@rovacc/training-events-types'; -const name = 'training-session-scheduled' +const name = 'training-session-scheduled'; const reducer: Reducer = ( training: Training | null, @@ -14,13 +18,16 @@ const reducer: Reducer = ( [event.payload.sessionId]: { ...training?.sessions?.[event.payload.sessionId], scheduledAt: event.payload.scheduledAt, - } - } -}) + }, + }, +}); -const isEmitted = - (training: Training | null, event: TrainingSessionScheduledEvent) => - !!training?.sessions && !!training.sessions[event.payload.sessionId] && !!training.sessions[event.payload.sessionId].scheduledAt - -export const trainingSessionScheduled = { name, reducer, isEmitted } as const +const isEmitted = ( + training: Training | null, + event: TrainingSessionScheduledEvent +) => + !!training?.sessions && + !!training.sessions[event.payload.sessionId] && + !!training.sessions[event.payload.sessionId].scheduledAt; +export const trainingSessionScheduled = { name, reducer, isEmitted } as const; diff --git a/libs/training-events/src/types.ts b/libs/training-events/src/types.ts index fb52708..dbeb6c0 100644 --- a/libs/training-events/src/types.ts +++ b/libs/training-events/src/types.ts @@ -1,22 +1,21 @@ - -import { TrainingCompletedEvent } from "./events/training-completed" -import { TrainingCptPerformedEvent } from "./events/training-cpt-performed" -import { TrainingCptRequestedEvent } from "./events/training-cpt-requested" -import { TrainingCptScheduledEvent } from "./events/training-cpt-scheduled" -import { TrainingIntentEvent } from "./events/training-intent" -import { TrainingIntentConfirmationExpiredEvent } from "./events/training-intent-confirmation-expired" -import { TrainingIntentConfirmationRejectedEvent } from "./events/training-intent-confirmation-rejected" -import { TrainingIntentConfirmationRequestedEvent } from "./events/training-intent-confirmation-requested" -import { TrainingIntentConfirmationRespondedEvent } from "./events/training-intent-confirmation-responded" -import { TrainingMentorAssignedEvent } from "./events/training-mentor-assigned" -import { TrainingMentorReassignedEvent } from "./events/training-mentor-reassigned" -import { TrainingSessionPerformedEvent } from "./events/training-session-performed" -import { TrainingSessionScheduledEvent } from "./events/training-session-scheduled" -import { TrainingSoloPerformedEvent } from "./events/training-solo-performed" -import { TrainingSoloRequestedEvent } from "./events/training-solo-requested" -import { TrainingSoloScheduledEvent } from "./events/training-solo-scheduled" -import { TrainingTestAssignedEvent } from "./events/training-test-assigned" -import { TrainingTestCompletedEvent } from "./events/training-test-completed" +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 @@ -38,6 +37,26 @@ export type TrainingEvent = | 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 @@ -54,8 +73,6 @@ export type TrainingStatus = | "COMPLETED" | "TERMINATED" - - export type TrainingPurpose = "acquire_rating" | "revalidate_rating" | "visiting" export type TestResult = "passed" | "failed" export type TrainingReport = { @@ -133,7 +150,7 @@ export type Reducer = (training: Training | null, event: T) => Trai export type IsEmitted = (training: Training | null, event: T) => boolean export type TrainingEventMetadata = { - id: string + eventId: string emittedAt: Date system: string correlationId: string diff --git a/package.json b/package.json index 70b5b66..f3a3fba 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@typescript-eslint/parser": "5.61.0", "@vitest/coverage-c8": "0.32.4", "@vitest/ui": "0.32.4", + "@types/uuid": "^9.0.2", "eslint": "~8.15.0", "eslint-config-prettier": "8.1.0", "firestore-vitest-mock": "^0.6.0", @@ -42,3 +43,4 @@ } } +