@defra-fish/sales-api-service 1.64.0-rc.20 → 1.64.0-rc.22

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.64.0-rc.20",
3
+ "version": "1.64.0-rc.22",
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.64.0-rc.20",
39
- "@defra-fish/connectors-lib": "1.64.0-rc.20",
40
- "@defra-fish/dynamics-lib": "1.64.0-rc.20",
38
+ "@defra-fish/business-rules-lib": "1.64.0-rc.22",
39
+ "@defra-fish/connectors-lib": "1.64.0-rc.22",
40
+ "@defra-fish/dynamics-lib": "1.64.0-rc.22",
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": "853e2b2a4d2e9ce0160d941b3e108e972a108ae5"
55
+ "gitHead": "59cf978328d7b22c739da1a6709326ad1ed97d1c"
56
56
  }
@@ -32,7 +32,7 @@ const getAuthenticatedPermission = async request => {
32
32
 
33
33
  const contactIds = contacts.map(contact => contact.entity.id)
34
34
  const permissions = await executeWithErrorLog(permissionForContacts(contactIds))
35
- const results = permissions.filter(p => p.entity.referenceNumber.endsWith(request.params.referenceNumber))
35
+ const results = permissions.filter(p => p.entity.referenceNumber.endsWith(request.params.referenceNumber.toUpperCase()))
36
36
 
37
37
  if (results.length === 0) {
38
38
  throw Boom.unauthorized(failAuthenticate)
@@ -42,23 +42,20 @@ const getAuthenticatedPermission = async request => {
42
42
  throw new Error('Unable to authenticate, non-unique results for query')
43
43
  }
44
44
 
45
- const [matched] = results
46
- const concessionProofEntities = matched.expanded.concessionProofs
47
-
48
- const concessionProofs =
49
- concessionProofEntities.length > 0 ? await executeWithErrorLog(concessionsByIds(concessionProofEntities.map(f => f.entity.id))) : []
45
+ const [permission] = results
46
+ const concessionIds = permission.expanded.concessionProofs.map(f => f.entity.id)
47
+ const concessionProofs = permission.expanded.concessionProofs.length ? await executeWithErrorLog(concessionsByIds(concessionIds)) : []
50
48
 
51
49
  return {
52
50
  permission: {
53
- ...matched.entity.toJSON(),
54
- licensee: matched.expanded.licensee.entity.toJSON(),
51
+ ...permission.entity.toJSON(),
52
+ licensee: permission.expanded.licensee.entity.toJSON(),
55
53
  concessions: concessionProofs.map(c => ({
56
54
  id: c.expanded.concession.entity.id,
57
55
  proof: c.entity.toJSON()
58
56
  })),
59
- permit: matched.expanded.permit.entity.toJSON()
60
- },
61
- permissionId: matched.entity.id
57
+ permit: permission.expanded.permit.entity.toJSON()
58
+ }
62
59
  }
63
60
  }
64
61
 
@@ -68,39 +65,8 @@ export default [
68
65
  path: '/authenticate/renewal/{referenceNumber}',
69
66
  options: {
70
67
  handler: async (request, h) => {
71
- const { licenseeBirthDate, licenseePostcode } = request.query
72
- const contacts = await executeWithErrorLog(contactForLicenseeNoReference(licenseeBirthDate, licenseePostcode))
73
- if (contacts.length > 0) {
74
- const contactIds = contacts.map(contact => contact.entity.id)
75
- const permissions = await executeWithErrorLog(permissionForContacts(contactIds))
76
- const results = permissions.filter(p => p.entity.referenceNumber.endsWith(request.params.referenceNumber.toUpperCase()))
77
- if (results.length === 1) {
78
- let concessionProofs = []
79
- if (results[0].expanded.concessionProofs.length > 0) {
80
- const ids = results[0].expanded.concessionProofs.map(f => f.entity.id)
81
- concessionProofs = await executeWithErrorLog(concessionsByIds(ids))
82
- }
83
- return h
84
- .response({
85
- permission: {
86
- ...results[0].entity.toJSON(),
87
- licensee: results[0].expanded.licensee.entity.toJSON(),
88
- concessions: concessionProofs.map(c => ({
89
- id: c.expanded.concession.entity.id,
90
- proof: c.entity.toJSON()
91
- })),
92
- permit: results[0].expanded.permit.entity.toJSON()
93
- }
94
- })
95
- .code(200)
96
- } else if (results.length === 0) {
97
- throw Boom.unauthorized(failAuthenticate)
98
- } else {
99
- throw new Error('Unable to authenticate, non-unique results for query')
100
- }
101
- } else {
102
- throw Boom.unauthorized(failAuthenticate)
103
- }
68
+ const permissionData = await getAuthenticatedPermission(request)
69
+ return h.response(permissionData).code(HTTP_OK)
104
70
  },
105
71
  description: 'Authenticate a licensee by checking the licence number corresponds with the provided contact details',
106
72
  notes: `
@@ -127,8 +93,8 @@ export default [
127
93
  path: '/authenticate/rcp/{referenceNumber}',
128
94
  options: {
129
95
  handler: async (request, h) => {
130
- const { permission, permissionId } = await getAuthenticatedPermission(request)
131
- const recurringPayment = await findLinkedRecurringPayment(permissionId)
96
+ const { permission } = await getAuthenticatedPermission(request)
97
+ const recurringPayment = await findLinkedRecurringPayment(permission.id)
132
98
  return h.response({ permission, recurringPayment }).code(HTTP_OK)
133
99
  },
134
100
  description: