diff --git a/src/services/lease-service/priority-list-service.ts b/src/services/lease-service/priority-list-service.ts index c2930934..e0e79e2e 100644 --- a/src/services/lease-service/priority-list-service.ts +++ b/src/services/lease-service/priority-list-service.ts @@ -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 } @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -145,6 +173,10 @@ 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, @@ -152,6 +184,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( } //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, diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index 3f829112..41594370 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -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) + }) })