Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
LesterLyu committed Feb 4, 2025
1 parent e8182c5 commit a31bfcf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const { getPartnerOrganizationsHelper } = require("../partnerOrganization");
const afterUpdateOrganization = async function (data, oldGeneric, req) {
const wasHomeOrganization = oldGeneric.status === 'Home';
const isHomeOrganization = data.fields?.[PredefinedCharacteristics['Organization Status']?._uri.split('#')[1]] === 'Home';

// If the organization is not a home organization, do not send a notification.
// If the organization changed to a home organization or vice versa, send a notification to all partners.
if (!wasHomeOrganization && !isHomeOrganization) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion backend/services/partnerNetwork/appointments.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {getClient, getReferralPartnerGeneric} = require("./referrals");
const {createNotificationHelper} = require("../notification/notification");
const {sanitize} = require("../../helpers/sanitizer");
const {regexBuilder} = require("graphdb-utils");
const {frontend} = require("../../config");

/**
* Converts an appointment generic into a format in which it can be sent to a partner deployment
Expand Down Expand Up @@ -108,7 +109,7 @@ async function sendAppointment(req, res, next) {
'Content-Type': 'application/json',
'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]],
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
'Referer': new URL(req.headers.origin).hostname,
'Referer': new URL(frontend.addr).hostname,
},
body: JSON.stringify(appointment),
});
Expand Down
3 changes: 2 additions & 1 deletion backend/services/partnerNetwork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {getProviderById} = require("../genericData/serviceProvider");
const {getDynamicFormsByFormTypeHelper, getIndividualsInClass} = require("../dynamicForm");
const {convertAddressForSerialization, convertAddressForDeserialization} = require("../address/misc");
const {GDBVolunteerModel} = require("../../models/volunteer");
const {frontend} = require("../../config");

/**
* Requests that a partner deployment represented locally as the partner
Expand Down Expand Up @@ -45,7 +46,7 @@ async function fetchOrganizationHelper(req, genericId) {
'X-RECEIVER-API-KEY': organization.apiKey,
...(!!senderApiKey && {'X-SENDER-API-KEY': senderApiKey}),
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
'Referer': new URL(req.headers.origin).hostname,
'Referer': new URL(frontend.addr).hostname,
},
});
clearTimeout(timeout);
Expand Down
3 changes: 2 additions & 1 deletion backend/services/partnerNetwork/referrals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {getGenericAssets} = require("./index");
const {createNotificationHelper} = require("../notification/notification");
const {sanitize} = require("../../helpers/sanitizer");
const {regexBuilder} = require("graphdb-utils");
const {frontend} = require("../../config");

/**
* Converts a referral generic into a format in which it can be sent to a partner deployment.
Expand Down Expand Up @@ -173,7 +174,7 @@ async function sendReferral(req, res, next) {
'Content-Type': 'application/json',
'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]],
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
'Referer': new URL(req.headers.origin).hostname,
'Referer': new URL(frontend.addr).hostname,
},
body: JSON.stringify(referral),
});
Expand Down
20 changes: 19 additions & 1 deletion backend/services/partnerNetwork/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ const {GDBOrganizationModel} = require("../../models/organization");
const {getIndividualsInClass} = require("../dynamicForm");
const {createNotificationHelper} = require("../notification/notification");
const {regexBuilder} = require("graphdb-utils");
const {frontend} = require("../../config");

/**
* Send a notification to a partner organization to update its home organization.
* This is triggered when
* - the home organization is updated
* - a program is created, updated, or deleted
* - a volunteer is created, updated, or deleted
* @param req - The request object.
* @param partnerId - The ID of the partner organization.
* @returns {Promise<void>}
*/
async function sendPartnerUpdateNotification(req, partnerId) {
const { fetchSingleGenericHelper } = require("../genericData");
const { getOrganization } = require(".");
Expand Down Expand Up @@ -33,7 +44,7 @@ async function sendPartnerUpdateNotification(req, partnerId) {
'X-RECEIVER-API-KEY': organization.apiKey,
...(!!senderApiKey && { 'X-SENDER-API-KEY': senderApiKey }),
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
'Referer': new URL(req.headers.origin).hostname,
'Referer': new URL(frontend.addr).hostname,
},
});
clearTimeout(timeout);
Expand Down Expand Up @@ -68,6 +79,13 @@ async function printAddress(address) {
return sanitize(formatLocation(address, addressInfo));
}

/**
* Receive a notification from a partner organization to update its home organization.
* @param req - The request object.
* @param res - The response object.
* @param next - The next middleware function.
* @returns {Promise<*>}
*/
async function receivePartnerUpdateNotification(req, res, next) {
const { fetchOrganizationHelper, deleteOrganizationHelper, updateOrganizationHelper } = require(".");

Expand Down

0 comments on commit a31bfcf

Please sign in to comment.