Skip to content

Commit a31bfcf

Browse files
committed
bugfix
1 parent e8182c5 commit a31bfcf

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

backend/services/genericData/organizationInternalTypeTreater.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const { getPartnerOrganizationsHelper } = require("../partnerOrganization");
55
const afterUpdateOrganization = async function (data, oldGeneric, req) {
66
const wasHomeOrganization = oldGeneric.status === 'Home';
77
const isHomeOrganization = data.fields?.[PredefinedCharacteristics['Organization Status']?._uri.split('#')[1]] === 'Home';
8+
9+
// If the organization is not a home organization, do not send a notification.
10+
// If the organization changed to a home organization or vice versa, send a notification to all partners.
811
if (!wasHomeOrganization && !isHomeOrganization) {
912
return;
1013
}

backend/services/partnerNetwork/appointments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {getClient, getReferralPartnerGeneric} = require("./referrals");
1111
const {createNotificationHelper} = require("../notification/notification");
1212
const {sanitize} = require("../../helpers/sanitizer");
1313
const {regexBuilder} = require("graphdb-utils");
14+
const {frontend} = require("../../config");
1415

1516
/**
1617
* Converts an appointment generic into a format in which it can be sent to a partner deployment
@@ -108,7 +109,7 @@ async function sendAppointment(req, res, next) {
108109
'Content-Type': 'application/json',
109110
'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]],
110111
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
111-
'Referer': new URL(req.headers.origin).hostname,
112+
'Referer': new URL(frontend.addr).hostname,
112113
},
113114
body: JSON.stringify(appointment),
114115
});

backend/services/partnerNetwork/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {getProviderById} = require("../genericData/serviceProvider");
1010
const {getDynamicFormsByFormTypeHelper, getIndividualsInClass} = require("../dynamicForm");
1111
const {convertAddressForSerialization, convertAddressForDeserialization} = require("../address/misc");
1212
const {GDBVolunteerModel} = require("../../models/volunteer");
13+
const {frontend} = require("../../config");
1314

1415
/**
1516
* Requests that a partner deployment represented locally as the partner
@@ -45,7 +46,7 @@ async function fetchOrganizationHelper(req, genericId) {
4546
'X-RECEIVER-API-KEY': organization.apiKey,
4647
...(!!senderApiKey && {'X-SENDER-API-KEY': senderApiKey}),
4748
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
48-
'Referer': new URL(req.headers.origin).hostname,
49+
'Referer': new URL(frontend.addr).hostname,
4950
},
5051
});
5152
clearTimeout(timeout);

backend/services/partnerNetwork/referrals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {getGenericAssets} = require("./index");
1414
const {createNotificationHelper} = require("../notification/notification");
1515
const {sanitize} = require("../../helpers/sanitizer");
1616
const {regexBuilder} = require("graphdb-utils");
17+
const {frontend} = require("../../config");
1718

1819
/**
1920
* Converts a referral generic into a format in which it can be sent to a partner deployment.
@@ -173,7 +174,7 @@ async function sendReferral(req, res, next) {
173174
'Content-Type': 'application/json',
174175
'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]],
175176
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
176-
'Referer': new URL(req.headers.origin).hostname,
177+
'Referer': new URL(frontend.addr).hostname,
177178
},
178179
body: JSON.stringify(referral),
179180
});

backend/services/partnerNetwork/update.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ const {GDBOrganizationModel} = require("../../models/organization");
55
const {getIndividualsInClass} = require("../dynamicForm");
66
const {createNotificationHelper} = require("../notification/notification");
77
const {regexBuilder} = require("graphdb-utils");
8+
const {frontend} = require("../../config");
89

10+
/**
11+
* Send a notification to a partner organization to update its home organization.
12+
* This is triggered when
13+
* - the home organization is updated
14+
* - a program is created, updated, or deleted
15+
* - a volunteer is created, updated, or deleted
16+
* @param req - The request object.
17+
* @param partnerId - The ID of the partner organization.
18+
* @returns {Promise<void>}
19+
*/
920
async function sendPartnerUpdateNotification(req, partnerId) {
1021
const { fetchSingleGenericHelper } = require("../genericData");
1122
const { getOrganization } = require(".");
@@ -33,7 +44,7 @@ async function sendPartnerUpdateNotification(req, partnerId) {
3344
'X-RECEIVER-API-KEY': organization.apiKey,
3445
...(!!senderApiKey && { 'X-SENDER-API-KEY': senderApiKey }),
3546
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
36-
'Referer': new URL(req.headers.origin).hostname,
47+
'Referer': new URL(frontend.addr).hostname,
3748
},
3849
});
3950
clearTimeout(timeout);
@@ -68,6 +79,13 @@ async function printAddress(address) {
6879
return sanitize(formatLocation(address, addressInfo));
6980
}
7081

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

0 commit comments

Comments
 (0)