diff --git a/apps/backend/src/mutations/ProposalMutations.ts b/apps/backend/src/mutations/ProposalMutations.ts index e4a1030b90..cbf9467167 100644 --- a/apps/backend/src/mutations/ProposalMutations.ts +++ b/apps/backend/src/mutations/ProposalMutations.ts @@ -47,6 +47,7 @@ import { WorkflowEngineProposalType } from '../workflowEngine/proposal'; import { ProposalAuthorization } from './../auth/ProposalAuthorization'; import { CallDataSource } from './../datasources/CallDataSource'; import { CloneUtils } from './../utils/CloneUtils'; +import FapMutations from './FapMutations'; import InstrumentMutations from './InstrumentMutations'; @injectable() @@ -846,33 +847,6 @@ export default class ProposalMutations { true ); - const sourceProposalInstrumentId = - await this.instrumentDataSource.getInstrumentsByProposalPk( - sourceProposal.primaryKey - ); - - if (sourceProposalInstrumentId.length > 0) { - const instrumentMutations = container.resolve(InstrumentMutations); - - try { - instrumentMutations.assignProposalsToInstrumentsInternal(agent, { - instrumentIds: sourceProposalInstrumentId.map( - (instrument) => instrument.id - ), - proposalPks: [clonedProposal.primaryKey], - }); - } catch (error) { - logger.logWarn( - 'Could not assign cloned proposals to the same instruments', - { - error, - clonedProposal, - sourceProposal, - } - ); - } - } - // TODO: Check if we need to also clone the technical review when cloning the proposal. clonedProposal = await this.proposalDataSource.update({ primaryKey: clonedProposal.primaryKey, @@ -897,6 +871,55 @@ export default class ProposalMutations { fileId: null, }); + const sourceProposalInstrumentId = + await this.instrumentDataSource.getInstrumentsByProposalPk( + sourceProposal.primaryKey + ); + + if (sourceProposalInstrumentId.length > 0) { + const instrumentMutations = container.resolve(InstrumentMutations); + const fapMutations = container.resolve(FapMutations); + + try { + await instrumentMutations.assignProposalsToInstrumentsInternal( + agent, + { + instrumentIds: sourceProposalInstrumentId.map( + (instrument) => instrument.id + ), + proposalPks: [clonedProposal.primaryKey], + } + ); + } catch (error) { + logger.logWarn( + 'Could not assign cloned proposals to the same instruments', + { + error, + clonedProposal, + sourceProposal, + } + ); + } + + try { + await fapMutations.assignProposalsToFapsUsingCallInstrumentsInternal( + null, + { + instrumentIds: sourceProposalInstrumentId.map( + (instrument) => instrument.id + ), + proposalPks: [clonedProposal.primaryKey], + } + ); + } catch (error) { + logger.logWarn('Could not assign cloned proposals to faps', { + error, + clonedProposal, + sourceProposal, + }); + } + } + const proposalUsers = await this.userDataSource.getProposalUsers( sourceProposal.primaryKey ); diff --git a/apps/e2e/cypress/e2e/proposals.cy.ts b/apps/e2e/cypress/e2e/proposals.cy.ts index 8d36ba4e07..bb4058d2b0 100644 --- a/apps/e2e/cypress/e2e/proposals.cy.ts +++ b/apps/e2e/cypress/e2e/proposals.cy.ts @@ -650,11 +650,6 @@ context('Proposal tests', () => { }); it('Should be able clone proposal to another call. Cloned proposals should be assigned the source proposals instruments', () => { - cy.createCall({ - ...newCall, - proposalWorkflowId: createdWorkflowId, - }); - // Create an ended call to test if it is not available for cloning. cy.createCall({ ...newCall, @@ -676,6 +671,16 @@ context('Proposal tests', () => { instrumentIds: [result.createInstrument.id], proposalPks: [createdProposalPk], }); + + cy.createCall({ + ...newCall, + proposalWorkflowId: createdWorkflowId, + }).then((call) => { + cy.assignInstrumentToCall({ + callId: call.createCall.id, + instrumentFapIds: [{ instrumentId: result.createInstrument.id }], + }); + }); } });