Skip to content

Commit

Permalink
fix: add instrument to msg for Queue.SCICAT_PROPOSAL (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jekabs-karklins authored Feb 16, 2023
1 parent 9a67d59 commit 1a89269
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/user-office-backend/src/eventHandlers/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ApplicationEvent } from '../events/applicationEvents';
import { Event } from '../events/event.enum';
import { EventHandler } from '../events/eventBus';
import { AllocationTimeUnits } from '../models/Call';
import { Instrument } from '../models/Instrument';
import { Proposal, ProposalEndStatus } from '../models/Proposal';
import { ScheduledEventCore } from '../models/ScheduledEventCore';
import { markProposalEventAsDoneAndCallWorkflowEngine } from '../workflowEngine';
Expand All @@ -36,6 +37,7 @@ type ProposalMessageData = {
newStatus?: string;
members: Member[];
proposer?: Member;
instrument?: Pick<Instrument, 'id' | 'shortCode'>;
};

let rabbitMQCachedBroker: null | RabbitMQMessageBroker = null;
Expand Down Expand Up @@ -82,6 +84,9 @@ const getProposalMessageData = async (proposal: Proposal) => {
container.resolve<ProposalSettingsDataSource>(
Tokens.ProposalSettingsDataSource
);
const instrumentDataSource = container.resolve<InstrumentDataSource>(
Tokens.InstrumentDataSource
);
const proposalStatus = await proposalSettingsDataSource.getProposalStatus(
proposal.statusId
);
Expand All @@ -90,9 +95,21 @@ const getProposalMessageData = async (proposal: Proposal) => {
proposal.primaryKey
);

const maybeInstrument = await instrumentDataSource.getInstrumentByProposalPk(
proposal.primaryKey
);

const instrument = maybeInstrument
? {
id: maybeInstrument.id,
shortCode: maybeInstrument.shortCode,
}
: undefined;

const messageData: ProposalMessageData = {
proposalPk: proposal.primaryKey,
shortCode: proposal.proposalId,
instrument: instrument,
title: proposal.title,
abstract: proposal.abstract,
members: proposalUsers.map((proposalUser) => ({
Expand Down

0 comments on commit 1a89269

Please sign in to comment.