Skip to content

Commit

Permalink
Assign all instruments to proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfernandes committed Jul 1, 2024
1 parent 6e34a39 commit ace69e4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/backend/src/models/questionTypes/TechniquePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { GraphQLError } from 'graphql';
import { container } from 'tsyringe';

import { Tokens } from '../../config/Tokens';
import { InstrumentDataSource } from '../../datasources/InstrumentDataSource';
import { ProposalDataSource } from '../../datasources/ProposalDataSource';
import { TechniqueDataSource } from '../../datasources/TechniqueDataSource';
import InstrumentMutations from '../../mutations/InstrumentMutations';
import TechniqueMutations from '../../mutations/TechniqueMutations';
import { TechniquePickerConfig } from '../../resolvers/types/FieldConfig';
import { QuestionFilterCompareOperator } from '../Questionary';
Expand Down Expand Up @@ -80,6 +82,12 @@ export const techniquePickerDefinition: Question<DataType.TECHNIQUE_PICKER> = {
Tokens.ProposalDataSource
);

const instrumentDataSource = container.resolve<InstrumentDataSource>(
Tokens.InstrumentDataSource
);

const instrumentMutations = container.resolve(InstrumentMutations);

const techniqueMutations = container.resolve(TechniqueMutations);

const proposal = await proposalDataSource.getByQuestionaryId(questionaryId);
Expand All @@ -103,5 +111,15 @@ export const techniquePickerDefinition: Question<DataType.TECHNIQUE_PICKER> = {
techniqueIds,
proposalPk: proposal.primaryKey,
});

const allInstrumentsOnCall =
await instrumentDataSource.getInstrumentsByCallId(
Array.from([proposal.callId])
);

await instrumentMutations.assignProposalsToInstrumentsInternal(null, {
proposalPks: [proposal.primaryKey],
instrumentIds: allInstrumentsOnCall.map((inst) => inst.id),
});
},
};

0 comments on commit ace69e4

Please sign in to comment.