Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/null priority #177

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions src/services/lease-service/priority-list-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const addPriorityToApplicantsBasedOnRentalRules = (
applicants: DetailedApplicant[]
) => {
const applicantsWithAssignedPriority: DetailedApplicant[] = []
logger.info(
`Adding priority to applicants based on rental rules for listing ${listing.id}`
)
for (const applicant of applicants) {
applicantsWithAssignedPriority.push(
assignPriorityToApplicantBasedOnRentalRules(listing, applicant)
)
}

logger.info(`Priority assigned to applicants for ${listing.id}`)
return applicantsWithAssignedPriority
}

Expand Down Expand Up @@ -65,22 +68,31 @@ const assignPriorityToApplicantBasedOnRentalRules = (
)
) {
//special residential area rental rules apply to this listing
//applicant is not allowed to rent this object, return priority:undefined
//applicant is not allowed to rent this object, return priority:null
logger.info(
applicant.name +
': priority null - special residential area rental rules apply to this listing. applicant is not allowed to rent this object'
)
return {
...applicant,
priority: null,
}
}

//priority 1

//Applicant has no active parking space contract and is tenant in same area as listing
if (!applicant.parkingSpaceContracts?.length) {
//priority 1

//Applicant has no active parking space contract and is tenant in same area as listing
if (applicant.currentHousingContract) {
if (
applicant.currentHousingContract?.residentialArea?.code ===
listing.districtCode
) {
logger.info(
applicant.name +
': priority 1 - Applicant has no active parking space contract and is tenant in same area as listing'
)

return {
...applicant,
priority: 1,
Expand All @@ -94,6 +106,10 @@ const assignPriorityToApplicantBasedOnRentalRules = (
applicant.upcomingHousingContract?.residentialArea?.code ===
listing.districtCode
) {
logger.info(
applicant.name +
': priority 1 - Applicant has no active parking space contract and has upcoming housing contract in same area as listing'
)
return {
...applicant,
priority: 1,
Expand All @@ -107,6 +123,10 @@ const assignPriorityToApplicantBasedOnRentalRules = (
applicant.parkingSpaceContracts?.length === 1 &&
applicant.applicationType === 'Replace'
) {
logger.info(
applicant.name +
': priority 1 - Applicant has 1 active contract for parking space and wishes to replace current parking space'
)
return {
...applicant,
priority: 1,
Expand All @@ -120,6 +140,10 @@ const assignPriorityToApplicantBasedOnRentalRules = (
applicant.parkingSpaceContracts?.length === 1 &&
applicant.applicationType === 'Additional'
) {
logger.info(
applicant.name +
': priority 2 - Applicant has 1 active parking space contract and wishes to rent an additional parking space'
)
return {
...applicant,
priority: 2,
Expand All @@ -132,6 +156,10 @@ const assignPriorityToApplicantBasedOnRentalRules = (
applicant.parkingSpaceContracts.length > 1 &&
applicant.applicationType === 'Replace'
) {
logger.info(
applicant.name +
': priority 2 - Applicant has more than 1 active parking space contract and wishes to replace 1 parking space contract'
)
return {
...applicant,
priority: 2,
Expand All @@ -145,13 +173,21 @@ const assignPriorityToApplicantBasedOnRentalRules = (
applicant.parkingSpaceContracts &&
applicant.parkingSpaceContracts.length >= 2
) {
logger.info(
applicant.name +
': priority 3 - Applicant has 2 or more active parking space and wishes to rent an additional parking space'
)
return {
...applicant,
priority: 3,
}
}

//Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract
logger.info(
applicant.name +
": priority null - Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract"
)
return {
...applicant,
priority: null,
Expand Down
47 changes: 47 additions & 0 deletions src/services/lease-service/tests/priority-list-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,51 @@ describe('sortApplicantsBasedOnRentalRules', () => {
applicant2.contactCode
)
})

it('should assign priority null if applicant has no upcoming housing contracts or active parking space contracts', () => {
const listing = factory.listing.build({
rentalObjectCode: '307-706-00-0015',
districtCaption: 'Vallby',
districtCode: 'VAL',
objectTypeCaption: 'Parkeringsplats med el',
objectTypeCode: 'PPLMEL',
rentalObjectTypeCaption: 'Standard hyresobjektstyp',
publishedFrom: new Date('2024-10-21T07:55:51.000Z'),
publishedTo: new Date('2024-10-19T22:59:59.000Z'),
vacantFrom: new Date('2022-04-30T22:00:00.000Z'),
status: 4,
waitingListType: 'Bilplats (intern)',
})

const detailedApplicant3 = factory.detailedApplicant
.params({
applicationDate: new Date('2024-11-07T14:44:40.610Z'),
applicationType: 'Additional',
status: 1,
listingId: listing.id,
currentHousingContract: {
leaseId: '705-008-04-0101/04',
leaseNumber: '04',
rentalPropertyId: '705-008-04-0101',
type: 'Bostadskontrakt ',
leaseStartDate: new Date('2013-03-01T00:00:00.000Z'),
status: 0,
noticeTimeTenant: '3',
contractDate: new Date('2013-01-23T00:00:00.000Z'),
approvalDate: new Date('2013-01-23T00:00:00.000Z'),
residentialArea: {
code: 'MAL',
caption: 'Malmaberg',
},
},
parkingSpaceContracts: [],
})
.build()

const result3 = assignPriorityToApplicantBasedOnRentalRules(
listing,
detailedApplicant3
)
expect(result3.priority).toBe(null)
})
})
Loading