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
7 changes: 7 additions & 0 deletions apps/backend/src/datasources/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ export interface UserDataSource {
): Promise<boolean>;
getRoleByShortCode(roleShortCode: Roles): Promise<Role>;
mergeUsers(fromUserId: number, intoUserId: number): Promise<void>;
getApprovedProposalVisitorsWithInstitution(proposalPk: number): Promise<
{
user: User;
institution: Institution;
country: Country;
}[]
>;
}
10 changes: 10 additions & 0 deletions apps/backend/src/datasources/mockups/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,14 @@ export class UserDataSourceMock implements UserDataSource {
},
];
}

async getApprovedProposalVisitorsWithInstitution(proposalPk: number): Promise<
{
user: User;
institution: Institution;
country: Country;
}[]
> {
return [];
}
}
25 changes: 25 additions & 0 deletions apps/backend/src/datasources/postgres/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,29 @@ export default class PostgresUserDataSource implements UserDataSource {
});
});
}

async getApprovedProposalVisitorsWithInstitution(proposalPk: number): Promise<
{
user: User;
institution: Institution;
country: Country;
}[]
> {
return database
.distinct('i.*', 'c.*', 'u.*')
.from('users as u')
.join('visits_has_users as vu', { 'u.user_id': 'vu.user_id' })
.join('visits as v', { 'v.visit_id': 'vu.visit_id' })
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
.leftJoin('countries as c', { 'c.country_id': 'i.country_id' })
.where('v.proposal_pk', proposalPk)
.andWhere('vu.status', 'APPROVED')
.then((users: (UserRecord & InstitutionRecord & CountryRecord)[]) => {
return users.map((user) => ({
user: createUserObject(user),
institution: createInstitutionObject(user),
country: createCountryObject(user),
}));
});
}
}
6 changes: 6 additions & 0 deletions apps/backend/src/datasources/stfc/StfcUserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,4 +774,10 @@ export class StfcUserDataSource implements UserDataSource {
this.roleAssignmentMap.get(roleId) ?? ''
);
}

async getApprovedProposalVisitorsWithInstitution(
proposalPk: number
): Promise<{ user: User; institution: Institution; country: Country }[]> {
throw new Error('Method not implemented.');
}
}
17 changes: 16 additions & 1 deletion apps/backend/src/eventHandlers/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ProposalMessageData = {
instruments?: { id: number; shortCode: string; allocatedTime: number }[];
members: Member[];
dataAccessUsers: Member[];
visitors: Member[];
newStatus?: string;
proposalPk: number;
proposer?: Member;
Expand Down Expand Up @@ -129,10 +130,17 @@ export const getProposalMessageData = async (proposal: Proposal) => {

const proposalUsersWithInstitution =
await userDataSource.getProposalUsersWithInstitution(proposal.primaryKey);

const dataAccessUsersWithInstitution =
await dataAccessUsersDataSource.getDataAccessUsersWithInstitution(
proposal.primaryKey
);

const visitorsWithInstitution =
await userDataSource.getApprovedProposalVisitorsWithInstitution(
proposal.primaryKey
);

const maybeInstruments =
await instrumentDataSource.getInstrumentsByProposalPk(proposal.primaryKey);

Expand Down Expand Up @@ -177,9 +185,11 @@ export const getProposalMessageData = async (proposal: Proposal) => {
dataAccessUsers: dataAccessUsersWithInstitution.map(
mapUserWithInstitutionToMember
),
visitors: visitorsWithInstitution.map(mapUserWithInstitutionToMember),
newStatus: proposalStatus?.shortCode,
submitted: proposal.submitted,
};

const proposerWithInstitution = await userDataSource.getUserWithInstitution(
proposal.proposerId
);
Expand Down Expand Up @@ -242,7 +252,6 @@ export async function createPostToRabbitMQHandler() {
case Event.PROPOSAL_DELETED:
case Event.PROPOSAL_STATUS_ACTION_EXECUTED: {
const jsonMessage = await getProposalMessageData(event.proposal);

await rabbitMQ.sendMessageToExchange(
event.exchange || EXCHANGE_NAME,
event.type,
Expand Down Expand Up @@ -380,6 +389,12 @@ export async function createPostToRabbitMQHandler() {
: RABBITMQ_VISIT_EVENT_TYPE.VISIT_DELETED,
jsonMessage
);

await rabbitMQ.sendMessageToExchange(
EXCHANGE_NAME,
Event.PROPOSAL_UPDATED,
proposalPayload
);
break;
}
case Event.DATA_ACCESS_USERS_UPDATED: {
Expand Down
Loading