Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 additions & 27 deletions apps/backend/src/mutations/ProposalMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
);
Expand Down
15 changes: 10 additions & 5 deletions apps/e2e/cypress/e2e/proposals.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }],
});
});
}
});

Expand Down