@defra-fish/sales-api-service 1.63.0-rc.12 → 1.63.0-rc.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra-fish/sales-api-service",
3
- "version": "1.63.0-rc.12",
3
+ "version": "1.63.0-rc.14",
4
4
  "description": "Rod Licensing Sales API",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,9 +35,9 @@
35
35
  "test": "echo \"Error: run tests from root\" && exit 1"
36
36
  },
37
37
  "dependencies": {
38
- "@defra-fish/business-rules-lib": "1.63.0-rc.12",
39
- "@defra-fish/connectors-lib": "1.63.0-rc.12",
40
- "@defra-fish/dynamics-lib": "1.63.0-rc.12",
38
+ "@defra-fish/business-rules-lib": "1.63.0-rc.14",
39
+ "@defra-fish/connectors-lib": "1.63.0-rc.14",
40
+ "@defra-fish/dynamics-lib": "1.63.0-rc.14",
41
41
  "@hapi/boom": "^9.1.2",
42
42
  "@hapi/hapi": "^20.1.3",
43
43
  "@hapi/inert": "^6.0.3",
@@ -52,5 +52,5 @@
52
52
  "moment-timezone": "^0.5.34",
53
53
  "uuid": "^8.3.2"
54
54
  },
55
- "gitHead": "077b17c4a39822d8db2419d99e0a8dce2bb4a8ff"
55
+ "gitHead": "7b43e86ea607a9e8c8c8aa15d24c5fe92f6b6853"
56
56
  }
@@ -62,7 +62,9 @@ describe('permissions service', () => {
62
62
  const number = await generatePermissionNumber(
63
63
  getSamplePermission({
64
64
  permitId: MOCK_12MONTH_DISABLED_PERMIT.id,
65
- birthDate: moment().subtract(JUNIOR_MAX_AGE, 'years').format('YYYY-MM-DD')
65
+ birthDate: moment()
66
+ .subtract(JUNIOR_MAX_AGE + 1, 'years')
67
+ .format('YYYY-MM-DD')
66
68
  }),
67
69
  'Telesales'
68
70
  )
@@ -1,5 +1,5 @@
1
1
  import { Permission, Permit } from '@defra-fish/dynamics-lib'
2
- import { isJunior, isSenior, SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
2
+ import { SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
3
3
  import { getGlobalOptionSetValue, getReferenceDataForEntityAndId } from './reference-data.service.js'
4
4
  import { redis } from './ioredis.service.js'
5
5
  import moment from 'moment-timezone'
@@ -76,6 +76,9 @@ export const calculateEndDateMoment = async ({ permitId, startDate }) => {
76
76
  */
77
77
  export const calculateEndDate = async ({ permitId, startDate }) => (await calculateEndDateMoment({ permitId, startDate })).toISOString()
78
78
 
79
+ const ADULT_AGE = 17
80
+ const SENIOR_AGE = 66
81
+
79
82
  /**
80
83
  * Determine the appropriate age category code for use in a permission number
81
84
  * @param birthDate The birth date of the licensee
@@ -85,14 +88,16 @@ export const calculateEndDate = async ({ permitId, startDate }) => (await calcul
85
88
  const getAgeCategory = (birthDate, issueDate) => {
86
89
  const dob = moment(birthDate)
87
90
  const issue = moment(issueDate)
88
- const diff = issue.diff(dob, 'years', true)
91
+ const seventeenthBirthday = dob.clone().add(ADULT_AGE, 'years')
92
+ const sixtysixthBirthday = dob.clone().add(SENIOR_AGE, 'years')
89
93
 
90
- if (isJunior(diff)) {
94
+ if (issue.isBefore(seventeenthBirthday)) {
91
95
  return 'J'
92
- } else if (isSenior(diff)) {
96
+ } else if (issue.isSameOrAfter(sixtysixthBirthday)) {
93
97
  return 'S'
98
+ } else {
99
+ return 'F'
94
100
  }
95
- return 'F'
96
101
  }
97
102
 
98
103
  /**