@ministryofjustice/hmpps-prison-permissions-lib 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Please use this to capture reasoning behind changes:
4
4
 
5
+ # 2.0.1
6
+ Fixes incorrect usage of `previousPrisonId` and `previousPrisonLeavingDate` when checking contacts read permissions. These are only used in the context of transfers, not releases. The correct ones now in use are `lastPrisonId` and `releaseDate`.
7
+
5
8
  # 2.0.0
6
9
  Replaced contacts read permissions check with one that handles released prisoners differently. Checks for current prisoners are unaffected.
7
10
 
@@ -5,4 +5,6 @@ export default interface Prisoner {
5
5
  supportingPrisonId?: string;
6
6
  previousPrisonId?: string;
7
7
  previousPrisonLeavingDate?: string;
8
+ lastPrisonId?: string;
9
+ releaseDate?: string;
8
10
  }
package/dist/index.cjs CHANGED
@@ -122,8 +122,8 @@ const isTransferring = (prisoner) => {
122
122
  };
123
123
  const wasReleasedWithinThreeYears = (prisoner) => {
124
124
  return (isReleased(prisoner) &&
125
- !!prisoner.previousPrisonLeavingDate &&
126
- Date.parse(prisoner.previousPrisonLeavingDate) > Date.now() - 3 * 365 * 24 * 60 * 60 * 1000);
125
+ !!prisoner.releaseDate &&
126
+ Date.parse(prisoner.releaseDate) > Date.now() - 3 * 365 * 24 * 60 * 60 * 1000);
127
127
  };
128
128
  function userHasSomeRolesFrom(rolesToCheck, user) {
129
129
  return (rolesToCheck.length === 0 ||
@@ -758,7 +758,7 @@ const contactsReadCheck = matchBaseCheckAnd({
758
758
  return exports.PermissionCheckStatus.ROLE_NOT_PRESENT;
759
759
  if (!wasReleasedWithinThreeYears(prisoner))
760
760
  return exports.PermissionCheckStatus.EXCEEDS_TIME_RESTRICTION;
761
- if (!isInUsersCaseLoad(prisoner.previousPrisonId, user))
761
+ if (!isInUsersCaseLoad(prisoner.lastPrisonId, user))
762
762
  return exports.PermissionCheckStatus.NOT_IN_CASELOAD;
763
763
  return exports.PermissionCheckStatus.OK;
764
764
  }