Skip to content

Commit

Permalink
#1 fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeenciu committed Jun 21, 2023
1 parent aa636c4 commit 18895fb
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 39 deletions.
37 changes: 37 additions & 0 deletions libs/training-events/src/actions/emit-training-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { v4 as uuidv4 } from "uuid";
import { TrainingEvent, TrainingEventData } from "../types";
import { SYSTEM_ID, TRAINING_COLLECTION, TRAINING_EVENTS_SUBCOLLECTION } from '../config'
import { getFirestore } from "firebase-admin/firestore";
import { FirestoreNotInitialzedException } from "../exception/firestore-not-initialized";

export const emitTrainingEvent = async (eventData: TrainingEventData, correlationId: string): Promise<void> => {

const trainingId = eventData.trainingId
const event: TrainingEvent = {
eventId: uuidv4(),
emittedAt: new Date(),
system: SYSTEM_ID,
correlationId,
...eventData,
}

const db = getFirestore();
if (!db) {
throw new FirestoreNotInitialzedException()
}
const trainingCollection = db.collection(TRAINING_COLLECTION)

const training = await trainingCollection.doc(trainingId).get()
if (!training.exists) {
await trainingCollection
.doc(trainingId)
.set({ trainingId })
}

await trainingCollection
.doc(trainingId)
.collection(TRAINING_EVENTS_SUBCOLLECTION)
.doc(event.eventId)
.set(event)

}
3 changes: 3 additions & 0 deletions libs/training-events/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SYSTEM_ID = process.env['SYSTEM_ID'] as string
export const TRAINING_COLLECTION = 'training'
export const TRAINING_EVENTS_SUBCOLLECTION = 'events'
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-intent-confirmation-expired';

export type TrainingIntentConfirmationExpiredData = {
export type TrainingIntentConfirmationExpiredEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationExpiredEvent = TrainingEventMetadata & TrainingIntentConfirmationExpiredData
export type TrainingIntentConfirmationExpiredEvent = TrainingEventMetadata & TrainingIntentConfirmationExpiredEventData

const reducer: Reducer<TrainingIntentConfirmationExpiredEvent> = (
training: Training | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-intent-confirmation-rejected';

export type TrainingIntentConfirmationRejectedData = {
export type TrainingIntentConfirmationRejectedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRejectedEvent = TrainingEventMetadata & TrainingIntentConfirmationRejectedData
export type TrainingIntentConfirmationRejectedEvent = TrainingEventMetadata & TrainingIntentConfirmationRejectedEventData

const reducer: Reducer<TrainingIntentConfirmationRejectedEvent> = (
training: Training | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-intent-confirmation-requested';

export type TrainingIntentConfirmationRequestedData = {
export type TrainingIntentConfirmationRequestedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRequestedEvent = TrainingEventMetadata & TrainingIntentConfirmationRequestedData
export type TrainingIntentConfirmationRequestedEvent = TrainingEventMetadata & TrainingIntentConfirmationRequestedEventData

const reducer: Reducer<TrainingIntentConfirmationRequestedEvent> = (
training: Training | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-intent-confirmation-responded';

export type TrainingIntentConfirmationRespondedData = {
export type TrainingIntentConfirmationRespondedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRespondedEvent = TrainingEventMetadata & TrainingIntentConfirmationRespondedData
export type TrainingIntentConfirmationRespondedEvent = TrainingEventMetadata & TrainingIntentConfirmationRespondedEventData

const reducer: Reducer<TrainingIntentConfirmationRespondedEvent> = (
training: Training | null,
Expand Down
4 changes: 2 additions & 2 deletions libs/training-events/src/events/training-mentor-assigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Member, Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-mentor-assigned'

export type TrainingMentorAssignedData = {
export type TrainingMentorAssignedEventData = {
name: typeof name
trainingId: string
payload: {
Expand All @@ -11,7 +11,7 @@ export type TrainingMentorAssignedData = {
}
}

export type TrainingMentorAssignedEvent = TrainingEventMetadata & TrainingMentorAssignedData
export type TrainingMentorAssignedEvent = TrainingEventMetadata & TrainingMentorAssignedEventData

const reducer: Reducer<TrainingMentorAssignedEvent> = (
training: Training | null,
Expand Down
4 changes: 2 additions & 2 deletions libs/training-events/src/events/training-mentor-reassigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Member, Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-mentor-reassigned'

export type TrainingMentorReassignedData = {
export type TrainingMentorReassignedEventData = {
name: typeof name
trainingId: string
payload: {
Expand All @@ -11,7 +11,7 @@ export type TrainingMentorReassignedData = {
}
}

export type TrainingMentorReassignedEvent = TrainingEventMetadata & TrainingMentorReassignedData
export type TrainingMentorReassignedEvent = TrainingEventMetadata & TrainingMentorReassignedEventData

const reducer: Reducer<TrainingMentorReassignedEvent> = (
training: Training | null,
Expand Down
4 changes: 2 additions & 2 deletions libs/training-events/src/events/training-session-performed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from

const name = 'training-session-performed'

export type TrainingSessionPerformedData = {
export type TrainingSessionPerformedEventData = {
name: typeof name
trainingId: string
payload: {
Expand All @@ -12,7 +12,7 @@ export type TrainingSessionPerformedData = {
}
}

export type TrainingSessionPerformedEvent = TrainingEventMetadata & TrainingSessionPerformedData
export type TrainingSessionPerformedEvent = TrainingEventMetadata & TrainingSessionPerformedEventData

const reducer: Reducer<TrainingSessionPerformedEvent> = (
training: Training | null,
Expand Down
4 changes: 2 additions & 2 deletions libs/training-events/src/events/training-session-scheduled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Reducer, Training, TrainingEventMetadata } from "../types";

const name = 'training-session-scheduled'

export type TrainingSessionScheduledData = {
export type TrainingSessionScheduledEventData = {
name: typeof name
trainingId: string
payload: {
Expand All @@ -11,7 +11,7 @@ export type TrainingSessionScheduledData = {
}
}

export type TrainingSessionScheduledEvent = TrainingEventMetadata & TrainingSessionScheduledData
export type TrainingSessionScheduledEvent = TrainingEventMetadata & TrainingSessionScheduledEventData

const reducer: Reducer<TrainingSessionScheduledEvent> = (
training: Training | null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class FirestoreNotInitialzedException extends Error {
constructor() {
super('Firestore is not initialized');
}
}
61 changes: 39 additions & 22 deletions libs/training-events/src/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -133,7 +150,7 @@ export type Reducer<T = unknown> = (training: Training | null, event: T) => Trai
export type IsEmitted<T = unknown> = (training: Training | null, event: T) => boolean

export type TrainingEventMetadata = {
id: string
eventId: string
emittedAt: Date
system: string
correlationId: string
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"scripts": {},
"private": true,
"dependencies": {
"firebase-admin": "^11.9.0"
"@nx/js": "^16.3.2",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@nx/node": "^16.3.2",
Expand All @@ -15,6 +18,7 @@
"@nx/vite": "16.3.2",
"@nx/workspace": "16.3.2",
"@types/node": "18.7.1",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@vitest/coverage-c8": "^0.31.0",
Expand Down

0 comments on commit 18895fb

Please sign in to comment.