Skip to content

Commit

Permalink
fix(aapd-951): get user by email from session, ensure correct user
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanH1990 committed Feb 15, 2024
1 parent 0bb0984 commit 89bc712
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/common/src/view-model-maps/appeal-headline.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { APPEAL_USER_ROLES } = require('@pins/common/src/constants');
const { formatAddress } = require('../lib/format-address');

/**
* @param {import("../client/appeals-api-client").AppealCaseWithAppellant} caseData
* @param {import('@pins/common/src/constants').AppealToUserRoles} userType
* @param {import('@pins/common/src/constants').AppealToUserRoles|string|null} userType
*/
exports.formatHeadlineData = (caseData, userType = 'interestedParty') => {
exports.formatHeadlineData = (caseData, userType = APPEAL_USER_ROLES.INTERESTED_PARTY) => {
const {
caseReference,
LPAName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ exports.get = async (req, res) => {
//i.e '/appeals/' = appellant | agent
const userType = determineUser(userRouteUrl);

let caseData;

if (userType) {
// TODO: determine user ID (can get from API via email, in session)
caseData = await apiClient.getUsersAppealCase({
caseReference: appealNumber,
role: userType,
userId: ''
});
} else {
// TODO: handle LPA
caseData = await apiClient.getAppealCaseDataByCaseReference(appealNumber);
if (userType === null) {
throw new Error('Unknown role');
}

let userEmail;

if (req.session.lpaUser) {
userEmail = req.session.lpaUser.email;
} else if (req.session.email) {
userEmail = req.session.email;
}

const user = await apiClient.getUserByEmailV2(userEmail);

const caseData = await apiClient.getUsersAppealCase({
caseReference: appealNumber,
role: userType,
userId: user.id
});

const headlineData = formatHeadlineData(caseData, userType);

const viewContext = {
Expand Down
3 changes: 2 additions & 1 deletion packages/forms-web-app/src/lib/determine-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const determineUser = (url) => {
return APPEAL_USER_ROLES.APPELLANT;
} else if (url.includes('/manage-appeals/')) {
return LPA_USER_ROLE;
} else {
return null;
}
return null;
};

module.exports = { determineUser };

0 comments on commit 89bc712

Please sign in to comment.