Skip to content

Commit

Permalink
#1 fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeenciu committed Jul 8, 2023
1 parent 91a9b3d commit e8b8cb9
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 114 deletions.
50 changes: 29 additions & 21 deletions libs/training-events/src/actions/emit-training-event.ts
Original file line number Diff line number Diff line change
@@ -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<Training | null> => {

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<Training | null> => {
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);
};
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,12 +16,16 @@ const reducer: Reducer<TrainingIntentConfirmationExpiredEvent> = (
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;
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -12,12 +16,16 @@ const reducer: Reducer<TrainingIntentConfirmationRejectedEvent> = (
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;
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -12,12 +15,16 @@ const reducer: Reducer<TrainingIntentConfirmationRequestedEvent> = (
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;
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,13 +16,16 @@ const reducer: Reducer<TrainingIntentConfirmationRespondedEvent> = (
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;
18 changes: 11 additions & 7 deletions libs/training-events/src/events/training-mentor-assigned.ts
Original file line number Diff line number Diff line change
@@ -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<TrainingMentorAssignedEvent> = (
training: Training | null,
Expand All @@ -13,10 +18,9 @@ const reducer: Reducer<TrainingMentorAssignedEvent> = (
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;
22 changes: 14 additions & 8 deletions libs/training-events/src/events/training-mentor-reassigned.ts
Original file line number Diff line number Diff line change
@@ -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<TrainingMentorReassignedEvent> = (
training: Training | null,
Expand All @@ -13,11 +18,12 @@ const reducer: Reducer<TrainingMentorReassignedEvent> = (
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;
27 changes: 17 additions & 10 deletions libs/training-events/src/events/training-session-performed.ts
Original file line number Diff line number Diff line change
@@ -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<TrainingSessionPerformedEvent> = (
training: Training | null,
Expand All @@ -15,13 +19,16 @@ const reducer: Reducer<TrainingSessionPerformedEvent> = (
...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;
27 changes: 17 additions & 10 deletions libs/training-events/src/events/training-session-scheduled.ts
Original file line number Diff line number Diff line change
@@ -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<TrainingSessionScheduledEvent> = (
training: Training | null,
Expand All @@ -14,13 +18,16 @@ const reducer: Reducer<TrainingSessionScheduledEvent> = (
[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;
Loading

0 comments on commit e8b8cb9

Please sign in to comment.