-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Instrument assignment implemented via Event Bus.
- Loading branch information
1 parent
c0d283a
commit ca5d5be
Showing
12 changed files
with
138 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
apps/user-office-backend/src/eventHandlers/questionary/instrumentPicker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { container } from 'tsyringe'; | ||
|
||
import { Tokens } from '../../config/Tokens'; | ||
import { InstrumentDataSource } from '../../datasources/InstrumentDataSource'; | ||
import { ProposalDataSource } from '../../datasources/ProposalDataSource'; | ||
import { QuestionaryDataSource } from '../../datasources/QuestionaryDataSource'; | ||
import { ApplicationEvent } from '../../events/applicationEvents'; | ||
import { Event } from '../../events/event.enum'; | ||
import { DataType } from '../../models/Template'; | ||
|
||
export default function createHandler() { | ||
const questionaryDataSource = container.resolve<QuestionaryDataSource>( | ||
Tokens.QuestionaryDataSource | ||
); | ||
|
||
const instrumentDataSource = container.resolve<InstrumentDataSource>( | ||
Tokens.InstrumentDataSource | ||
); | ||
|
||
const proposalDataSource = container.resolve<ProposalDataSource>( | ||
Tokens.ProposalDataSource | ||
); | ||
|
||
return async function proposalWorkflowHandler(event: ApplicationEvent) { | ||
if (event.isRejection) { | ||
return; | ||
} | ||
|
||
switch (event.type) { | ||
case Event.TOPIC_ANSWERED: { | ||
const { | ||
questionarystep: { questionaryId }, | ||
} = event; | ||
|
||
const instrumentPickerAnswer = | ||
This comment has been minimized.
Sorry, something went wrong. |
||
await questionaryDataSource.getLatestAnswerByQuestionaryIdAndDataType( | ||
questionaryId, | ||
DataType.INSTRUMENT_PICKER | ||
); | ||
|
||
const instrumentId = instrumentPickerAnswer?.answer.answer.value; | ||
if (!instrumentId) | ||
throw new Error(`Invalid Instrument id ${instrumentId}`); | ||
|
||
const instrument = await instrumentDataSource.getInstrument( | ||
instrumentId | ||
); | ||
|
||
if (!instrument) | ||
throw new Error(`Instrument with id ${instrumentId} not found`); | ||
|
||
const proposal = await proposalDataSource.getByQuestionaryid( | ||
questionaryId | ||
); | ||
if (!proposal) | ||
throw new Error( | ||
`Proposal with questionary id ${questionaryId} not found` | ||
); | ||
|
||
await instrumentDataSource.assignProposalsToInstrument( | ||
[proposal.primaryKey], | ||
instrumentId | ||
); | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This assumes there is only one question about the instrument. Could there ever be two?