Skip to content

Commit fceabb4

Browse files
Merge pull request #257 from Bostads-AB-Mimer/feature/mim-374-hantera-skyddade-personuppgifter
MIM-374: getWorkOrderData gets leases on contactCode instead of pnr
2 parents 3ac830d + 4a5f43a commit fceabb4

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

src/adapters/leasing-adapter/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ const getLeasesForPnr = async (
6060
return leasesResponse.data.content
6161
}
6262

63+
const getLeasesForContactCode = async (
64+
contactCode: string,
65+
includeTerminatedLeases: boolean,
66+
includeContacts: boolean
67+
): Promise<Lease[]> => {
68+
const queryParams = new URLSearchParams({
69+
includeTerminatedLeases: includeTerminatedLeases.toString(),
70+
includeContacts: includeContacts.toString(),
71+
})
72+
73+
const leasesResponse = await axios.get(
74+
`${tenantsLeasesServiceUrl}/leases/for/contactCode/${contactCode}?${queryParams.toString()}`
75+
)
76+
77+
return leasesResponse.data.content
78+
}
79+
6380
const getLeasesForPropertyId = async (
6481
propertyId: string,
6582
includeTerminatedLeases: string | string[] | undefined,
@@ -591,6 +608,7 @@ export {
591608
getInternalCreditInformation,
592609
getLease,
593610
getLeasesForPnr,
611+
getLeasesForContactCode,
594612
getLeasesForPropertyId,
595613
getDetailedApplicantsByListingId,
596614
getTenantByContactCode,

src/services/work-order-service/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,24 @@ export const routes = (router: KoaRouter) => {
163163
ctx.params.identifier
164164
)
165165
if (contact) {
166-
const leases = await leasingAdapter.getLeasesForPnr(
167-
contact.nationalRegistrationNumber,
166+
const leases = await leasingAdapter.getLeasesForContactCode(
167+
contact.contactCode,
168168
false,
169-
true
169+
false
170170
)
171171
if (leases) {
172172
await getRentalPropertyInfoWithLeases(leases)
173173
}
174174
}
175175
},
176176
contactCode: async () => {
177-
const contactResult = await leasingAdapter.getContactByContactCode(
178-
ctx.params.identifier
177+
const leases = await leasingAdapter.getLeasesForContactCode(
178+
ctx.params.identifier,
179+
false,
180+
true
179181
)
180-
if (contactResult.ok) {
181-
const leases = await leasingAdapter.getLeasesForPnr(
182-
contactResult.data.nationalRegistrationNumber,
183-
false,
184-
true
185-
)
186-
if (leases) {
187-
await getRentalPropertyInfoWithLeases(leases)
188-
}
182+
if (leases) {
183+
await getRentalPropertyInfoWithLeases(leases)
189184
}
190185
},
191186
}

src/services/work-order-service/tests/index.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ describe('work-order-service index', () => {
113113
const getContactByPhoneNumberSpy = jest
114114
.spyOn(tenantLeaseAdapter, 'getContactByPhoneNumber')
115115
.mockResolvedValue(contactMock)
116-
const getLeaseSpy = jest
117-
.spyOn(tenantLeaseAdapter, 'getLease')
118-
.mockResolvedValue(leaseMock)
116+
const getLeasesForContactCodeSpy = jest
117+
.spyOn(tenantLeaseAdapter, 'getLeasesForContactCode')
118+
.mockResolvedValue([leaseMock])
119119

120120
const getRentalPropertyInfoSpy = jest
121121
.spyOn(propertyManagementAdapter, 'getRentalPropertyInfo')
@@ -127,18 +127,19 @@ describe('work-order-service index', () => {
127127

128128
expect(res.status).toBe(200)
129129
expect(getContactByPhoneNumberSpy).toHaveBeenCalledWith('1234567890')
130-
expect(getLeaseSpy).toHaveBeenCalledWith('123', 'true')
130+
expect(getLeasesForContactCodeSpy).toHaveBeenCalledWith(
131+
'P158770',
132+
false,
133+
false
134+
)
131135
expect(getRentalPropertyInfoSpy).toHaveBeenCalledWith('123-456-789')
132136
expect(res.body.content).toBeDefined()
133137
})
134138

135139
it('should handle contactCode case', async () => {
136-
const getContactByContactCodeSpy = jest
137-
.spyOn(tenantLeaseAdapter, 'getContactByContactCode')
138-
.mockResolvedValue({ ok: true, data: contactMock })
139-
const getLeaseSpy = jest
140-
.spyOn(tenantLeaseAdapter, 'getLease')
141-
.mockResolvedValue(leaseMock)
140+
const getLeasesForContactCodeSpy = jest
141+
.spyOn(tenantLeaseAdapter, 'getLeasesForContactCode')
142+
.mockResolvedValue([leaseMock])
142143

143144
const getRentalPropertyInfoSpy = jest
144145
.spyOn(propertyManagementAdapter, 'getRentalPropertyInfo')
@@ -149,8 +150,11 @@ describe('work-order-service index', () => {
149150
)
150151

151152
expect(res.status).toBe(200)
152-
expect(getContactByContactCodeSpy).toHaveBeenCalledWith('P965339')
153-
expect(getLeaseSpy).toHaveBeenCalledWith('123', 'true')
153+
expect(getLeasesForContactCodeSpy).toHaveBeenCalledWith(
154+
'P965339',
155+
false,
156+
true
157+
)
154158
expect(getRentalPropertyInfoSpy).toHaveBeenCalledWith('123-456-789')
155159
expect(res.body.content).toBeDefined()
156160
})

0 commit comments

Comments
 (0)