Skip to content

Commit be6373d

Browse files
authored
MIM-537: Get residence by rental id (#71)
* base: wip get rental property information for residence * wip * wip * base: its a one-to-one relationship * base: map response object properties to existing property info type * base: add route to swagger * base: fixup and remove unused query fields * base: add todo * base: change route name * base: wip get residence and rental info by rental id separately * base: jus use get residence by rental id * base: what is this * base: bit of error handling * base: try generic response schema * tree: update generated types * types * types * base: fix area size * ci: dont always run lint
1 parent f9563c7 commit be6373d

File tree

10 files changed

+548
-96
lines changed

10 files changed

+548
-96
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
branches: ['**']
66
push:
7-
branches: ['**']
7+
branches: ['main']
88
workflow_call:
99

1010
jobs:

packages/property-base/prisma/schema/PropertyObject_cmobj.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ model PropertyObject {
2323
administrativeUnit AdministrativeUnit? //@relation("PropertyObjectToAdministrativeUnit")
2424
propertyArea PropertyArea[] //@relation("PropertyObjectToPropertyArea")
2525
property Property? //@relation("PropertyObjectToProperty") //todo: fix this relation
26-
rentalInformation RentalInformation? @relation("PropertyObjectToRentalInformation")
26+
rentalInformation RentalInformation? @relation("PropertyObjectToRentalInformation")
2727
2828
rentalObject RentalObject? //@relation("PropertyObjectToRentalObject")
2929
//company Company? @relation("PropertyObjectToCompany")
@@ -53,7 +53,7 @@ model PropertyObject {
5353
//actionRentalRows ActionRentalRow[] @relation("PropertyObjectToActionRentalRow")
5454
5555
rooms Room[]
56-
residence Residence[]
56+
residence Residence?
5757
maintenanceUnit MaintenanceUnit[]
5858
5959
@@index([objectTypeId], map: "fkcmobjcmobt")
Lines changed: 91 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,84 @@
11
model RentalInformation {
2-
@@map("hyinf")
3-
id String @id(map: "pkhyinf") @map("keyhyinf") @db.Char(15)
4-
propertyObjectId String @unique(map: "akhyinf1") @map("keycmobj") @db.Char(15)
5-
rentalInformationTypeId String @map("keyhyint") @db.Char(15)
2+
id String @id(map: "pkhyinf") @map("keyhyinf") @db.Char(15)
3+
propertyObjectId String @unique(map: "akhyinf1") @map("keycmobj") @db.Char(15)
4+
rentalInformationTypeId String @map("keyhyint") @db.Char(15)
5+
apartmentNumber String? @map("lmnr") @db.Char(5)
66
// Exclude unused fields
77
8-
// shownByUserId String? @map("keybkvis") @db.Char(15) // TODO: Confirm relation name if changed
9-
// indexSeriesId String? @map("keycmind") @db.Char(15)
10-
// indexValueId String? @map("keycminv") @db.Char(15)
11-
// quantityTypeId String? @map("keycmvat") @db.Char(15)
12-
// quantityTypeId2 String? @map("keycmvat2") @db.Char(15)
13-
// quantityTypeId3 String? @map("keycmvat3") @db.Char(15)
14-
// quantityTypeId4 String? @map("keycmvat4") @db.Char(15)
15-
// taxAreaId String? @map("keyhyvaa") @db.Char(15)
16-
// heatingId String? @map("keybahea") @db.Char(15)
17-
// renovationExemptionId String? @map("keybarex") @db.Char(15)
18-
// creditTemplateId String? @map("keycmcte") @db.Char(15)
19-
// rentId String? @map("hyresid") @db.VarChar(30)
20-
// generation Int? @map("generation") @db.SmallInt
21-
// startGeneration Int? @map("startgen") @db.TinyInt
22-
// apartmentNumber String? @map("lmnr") @db.Char(5)
23-
// housingNumber String? @map("prynumber") @db.VarChar(30)
24-
// shareNumber String? @map("shareno") @db.VarChar(60)
25-
// tenureForm Int? @map("upplform") @db.TinyInt
26-
// currentTenureForm Int? @map("upplformnu") @db.TinyInt
27-
// isShortTermRental Int @map("shortstay") @db.TinyInt
28-
// sharePercentage Decimal? @map("andelstal") @db.Decimal(22, 7)
29-
// rentDistributionFactor Decimal? @map("aixrent") @db.Decimal(8, 7)
30-
// shareValue Float? @map("sharevalue") @db.Money
31-
// voteCount Int? @map("votecount") @db.TinyInt
32-
// depositAdvance Float? @map("insatspre") @db.Money
33-
// depositForfeit Float? @map("insatsfors") @db.Money // deposit Float? @map("insats") @db.Money // depositDate DateTime? @map("inputdate") @db.DateTime
34-
// tenureFee Float? @map("upplavg") @db.Money
35-
// tenureFeeDate DateTime? @map("letfeedate") @db.DateTime
36-
// irrevocableCapitalContribution Float? @map("oaterkap") @db.Money
37-
// originalAnnualFee Float? @map("planarsavg") @db.Money
38-
// firstOccupancyDate DateTime? @map("inflyttdat") @db.DateTime
39-
// queueManagement Int? @map("direktuth") @db.TinyInt
40-
// baseRentAmount Float? @map("akthyratot") @db.Money
41-
// contractBaseRent Float? @map("konthyra") @db.Money
42-
// isDraft Int @default(0, map: "DF__hyinf__draft__535320DE") @map("draft") @db.TinyInt
43-
// doNotInvoiceDeposit Int @map("ejbrinsats") @db.TinyInt
44-
// doNotAllocateToInternalFund Int @map("ejbrfnd") @db.TinyInt
45-
// statisticsFrom DateTime @map("statfrom") @db.DateTime
46-
// statisticsTo DateTime @map("stattom") @db.DateTime
47-
// rentLossFrom DateTime? @map("lossfrom") @db.DateTime
48-
// rentLossTo DateTime? @map("lossto") @db.DateTime
49-
// salesStop Int @map("saljstopp") @db.TinyInt
50-
// housingEvaluationType Int @default(0, map: "DF__hyinf__pointtype__54474517") @map("pointtype") @db.TinyInt
51-
// housingAllowance Int @default(0, map: "DF__hyinf__allowance__553B6950") @map("allowance") @db.TinyInt
52-
// housingEnergyClass Int @default(0, map: "DF__hyinf__fohenergy__562F8D89") @map("fohenergyc") @db.TinyInt
53-
// targetRentPercentage Decimal? @map("targetperc") @db.Decimal(4, 1)
54-
// targetRentAmount Float? @map("targetrent") @db.Money
55-
// evaluationPoints Int? @map("points") @db.SmallInt
56-
// minOccupants Int? @map("persmin") @db.TinyInt
57-
// maxOccupants Int? @map("persmax") @db.TinyInt
58-
// minAge Int? @map("persagemin") @db.TinyInt
59-
// maxAge Int? @map("persagemax") @db.TinyInt
60-
// minTenureMonths Int? @map("tentimemin") @db.TinyInt
61-
// minIncomeRentFactor Decimal? @map("increntmin") @db.Decimal(4, 2)
62-
// additionalInfo String? @map("otherinfo") @db.VarChar(200)
63-
// renovationExemptionComment String? @map("rexcomment") @db.VarChar(200)
64-
// firstClassId Int @default(0, map: "DF__hyinf__fcobject__5723B1C2") @map("fcobject") @db.TinyInt
65-
// upgradeStandard Int @default(0, map: "DF__hyinf__fcstatus__5817D5FB") @map("fcstatus") @db.TinyInt
66-
// upgradeNeed Int @default(0, map: "DF__hyinf__fcupgneed__590BFA34") @map("fcupgneed") @db.TinyInt
67-
// lastUpgradeDate DateTime? @map("fcdate") @db.DateTime
68-
// upgradeComment String? @map("fccomment") @db.VarChar(250)
69-
// isBGUCovered Int @default(0, map: "DF__hyinf__bguused__5A001E6D") @map("bguused") @db.TinyInt
70-
// hasLakeView Int @default(0, map: "DF__hyinf__lakeview__5AF442A6") @map("lakeview") @db.TinyInt
71-
// vatRate Decimal @default(0, map: "DF__hyinf__vatstat__5BE866DF") @map("vatstat") @db.Decimal(4, 2)
72-
// purposeLabel Int @default(1, map: "DF__hyinf__label__5CDC8B18") @map("label") @db.TinyInt
73-
// isRenovated Int @default(0, map: "DF__hyinf__renovatio__5DD0AF51") @map("renovation") @db.TinyInt
74-
// daebStatus Int @default(1, map: "DF__hyinf__daeb__5EC4D38A") @map("daeb") @db.TinyInt
75-
// standardYearRent Float? @map("stdyrrent") @db.Money
76-
// discountFee Float @default(0, map: "DF__hyinf__discfee__5FB8F7C3") @map("discfee") @db.Money
77-
// rentCalculationMethod Int @default(0, map: "DF__hyinf__rentcalcm__60AD1BFC") @map("rentcalcm") @db.TinyInt
78-
// deleteMark Int @default(0, map: "DF__hyinf__deletemar__61A14035") @map("deletemark") @db.TinyInt
79-
// timestamp String @map("timestamp") @db.Char(10)
8+
// shownByUserId String? @map("keybkvis") @db.Char(15) // TODO: Confirm relation name if changed
9+
// indexSeriesId String? @map("keycmind") @db.Char(15)
10+
// indexValueId String? @map("keycminv") @db.Char(15)
11+
// quantityTypeId String? @map("keycmvat") @db.Char(15)
12+
// quantityTypeId2 String? @map("keycmvat2") @db.Char(15)
13+
// quantityTypeId3 String? @map("keycmvat3") @db.Char(15)
14+
// quantityTypeId4 String? @map("keycmvat4") @db.Char(15)
15+
// taxAreaId String? @map("keyhyvaa") @db.Char(15)
16+
// heatingId String? @map("keybahea") @db.Char(15)
17+
// renovationExemptionId String? @map("keybarex") @db.Char(15)
18+
// creditTemplateId String? @map("keycmcte") @db.Char(15)
19+
// rentId String? @map("hyresid") @db.VarChar(30)
20+
// generation Int? @map("generation") @db.SmallInt
21+
// startGeneration Int? @map("startgen") @db.TinyInt
22+
// housingNumber String? @map("prynumber") @db.VarChar(30)
23+
// shareNumber String? @map("shareno") @db.VarChar(60)
24+
// tenureForm Int? @map("upplform") @db.TinyInt
25+
// currentTenureForm Int? @map("upplformnu") @db.TinyInt
26+
// isShortTermRental Int @map("shortstay") @db.TinyInt
27+
// sharePercentage Decimal? @map("andelstal") @db.Decimal(22, 7)
28+
// rentDistributionFactor Decimal? @map("aixrent") @db.Decimal(8, 7)
29+
// shareValue Float? @map("sharevalue") @db.Money
30+
// voteCount Int? @map("votecount") @db.TinyInt
31+
// depositAdvance Float? @map("insatspre") @db.Money
32+
// depositForfeit Float? @map("insatsfors") @db.Money // deposit Float? @map("insats") @db.Money // depositDate DateTime? @map("inputdate") @db.DateTime
33+
// tenureFee Float? @map("upplavg") @db.Money
34+
// tenureFeeDate DateTime? @map("letfeedate") @db.DateTime
35+
// irrevocableCapitalContribution Float? @map("oaterkap") @db.Money
36+
// originalAnnualFee Float? @map("planarsavg") @db.Money
37+
// firstOccupancyDate DateTime? @map("inflyttdat") @db.DateTime
38+
// queueManagement Int? @map("direktuth") @db.TinyInt
39+
// baseRentAmount Float? @map("akthyratot") @db.Money
40+
// contractBaseRent Float? @map("konthyra") @db.Money
41+
// isDraft Int @default(0, map: "DF__hyinf__draft__535320DE") @map("draft") @db.TinyInt
42+
// doNotInvoiceDeposit Int @map("ejbrinsats") @db.TinyInt
43+
// doNotAllocateToInternalFund Int @map("ejbrfnd") @db.TinyInt
44+
// statisticsFrom DateTime @map("statfrom") @db.DateTime
45+
// statisticsTo DateTime @map("stattom") @db.DateTime
46+
// rentLossFrom DateTime? @map("lossfrom") @db.DateTime
47+
// rentLossTo DateTime? @map("lossto") @db.DateTime
48+
// salesStop Int @map("saljstopp") @db.TinyInt
49+
// housingEvaluationType Int @default(0, map: "DF__hyinf__pointtype__54474517") @map("pointtype") @db.TinyInt
50+
// housingAllowance Int @default(0, map: "DF__hyinf__allowance__553B6950") @map("allowance") @db.TinyInt
51+
// housingEnergyClass Int @default(0, map: "DF__hyinf__fohenergy__562F8D89") @map("fohenergyc") @db.TinyInt
52+
// targetRentPercentage Decimal? @map("targetperc") @db.Decimal(4, 1)
53+
// targetRentAmount Float? @map("targetrent") @db.Money
54+
// evaluationPoints Int? @map("points") @db.SmallInt
55+
// minOccupants Int? @map("persmin") @db.TinyInt
56+
// maxOccupants Int? @map("persmax") @db.TinyInt
57+
// minAge Int? @map("persagemin") @db.TinyInt
58+
// maxAge Int? @map("persagemax") @db.TinyInt
59+
// minTenureMonths Int? @map("tentimemin") @db.TinyInt
60+
// minIncomeRentFactor Decimal? @map("increntmin") @db.Decimal(4, 2)
61+
// additionalInfo String? @map("otherinfo") @db.VarChar(200)
62+
// renovationExemptionComment String? @map("rexcomment") @db.VarChar(200)
63+
// firstClassId Int @default(0, map: "DF__hyinf__fcobject__5723B1C2") @map("fcobject") @db.TinyInt
64+
// upgradeStandard Int @default(0, map: "DF__hyinf__fcstatus__5817D5FB") @map("fcstatus") @db.TinyInt
65+
// upgradeNeed Int @default(0, map: "DF__hyinf__fcupgneed__590BFA34") @map("fcupgneed") @db.TinyInt
66+
// lastUpgradeDate DateTime? @map("fcdate") @db.DateTime
67+
// upgradeComment String? @map("fccomment") @db.VarChar(250)
68+
// isBGUCovered Int @default(0, map: "DF__hyinf__bguused__5A001E6D") @map("bguused") @db.TinyInt
69+
// hasLakeView Int @default(0, map: "DF__hyinf__lakeview__5AF442A6") @map("lakeview") @db.TinyInt
70+
// vatRate Decimal @default(0, map: "DF__hyinf__vatstat__5BE866DF") @map("vatstat") @db.Decimal(4, 2)
71+
// purposeLabel Int @default(1, map: "DF__hyinf__label__5CDC8B18") @map("label") @db.TinyInt
72+
// isRenovated Int @default(0, map: "DF__hyinf__renovatio__5DD0AF51") @map("renovation") @db.TinyInt
73+
// daebStatus Int @default(1, map: "DF__hyinf__daeb__5EC4D38A") @map("daeb") @db.TinyInt
74+
// standardYearRent Float? @map("stdyrrent") @db.Money
75+
// discountFee Float @default(0, map: "DF__hyinf__discfee__5FB8F7C3") @map("discfee") @db.Money
76+
// rentCalculationMethod Int @default(0, map: "DF__hyinf__rentcalcm__60AD1BFC") @map("rentcalcm") @db.TinyInt
77+
// deleteMark Int @default(0, map: "DF__hyinf__deletemar__61A14035") @map("deletemark") @db.TinyInt
78+
// timestamp String @map("timestamp") @db.Char(10)
8079
81-
// heating Heating? @relation(fields: [heatingId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fkhyinfbahea")
82-
// creditTemplate CreditTemplate? @relation(fields: [creditTemplateId], references: [id], onUpdate: NoAction, map: "fkhyinfcmcte")
80+
// heating Heating? @relation(fields: [heatingId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fkhyinfbahea")
81+
// creditTemplate CreditTemplate? @relation(fields: [creditTemplateId], references: [id], onUpdate: NoAction, map: "fkhyinfcmcte")
8382
8483
// TODO: change relations when knowing the new model names
8584
// indexSeries cmind? @relation(fields: [indexSeriesId], references: [keycmind], onDelete: NoAction, onUpdate: NoAction, map: "fkhyinfkeycmind")
@@ -90,16 +89,18 @@ model RentalInformation {
9089
// quantityType3 cmvat_hyinf_keycmvat3Tocmvat cmvat? @relation("hyinf_keycmvat3Tocmvat", fields: [quantityTypeId3], references: [keycmvat], onDelete: NoAction, onUpdate: NoAction, map: "fkhyinfkeycmvat3")
9190
// quantityType4 cmvat_hyinf_keycmvat4Tocmvat cmvat? @relation("hyinf_keycmvat4Tocmvat", fields: [quantityTypeId4], references: [keycmvat], onDelete: NoAction, onUpdate: NoAction, map: "fkhyinfkeycmvat4")
9291
rentalInformationType RentalInformationType @relation(fields: [rentalInformationTypeId], references: [id], onUpdate: NoAction, map: "fkhyinfkeyhyint")
93-
propertyObject PropertyObject @relation("PropertyObjectToRentalInformation", fields: [propertyObjectId], references: [id], map: "fkhyinfkeycmobj")
94-
// @@index([heatingId], map: "fkhyinfbahea")
95-
// @@index([shownByUserId], map: "fkhyinfbkvis")
96-
// @@index([creditTemplateId], map: "fkhyinfcmcte")
97-
// @@index([indexSeriesId], map: "fkhyinfcmind")
98-
// @@index([indexValueId], map: "fkhyinfcminv")
99-
// @@index([quantityTypeId], map: "fkhyinfcmvat")
100-
// @@index([quantityTypeId2], map: "fkhyinfcmvat2")
101-
// @@index([quantityTypeId3], map: "fkhyinfcmvat3")
102-
// @@index([quantityTypeId4], map: "fkhyinfcmvat4")
103-
// @@index([rentalInformationTypeId], map: "fkhyinfhyint")
104-
// @@index([rentId], map: "inhyinf_2J70GWSR9")
92+
propertyObject PropertyObject @relation("PropertyObjectToRentalInformation", fields: [propertyObjectId], references: [id], map: "fkhyinfkeycmobj")
93+
// @@index([heatingId], map: "fkhyinfbahea")
94+
// @@index([shownByUserId], map: "fkhyinfbkvis")
95+
// @@index([creditTemplateId], map: "fkhyinfcmcte")
96+
// @@index([indexSeriesId], map: "fkhyinfcmind")
97+
// @@index([indexValueId], map: "fkhyinfcminv")
98+
// @@index([quantityTypeId], map: "fkhyinfcmvat")
99+
// @@index([quantityTypeId2], map: "fkhyinfcmvat2")
100+
// @@index([quantityTypeId3], map: "fkhyinfcmvat3")
101+
// @@index([quantityTypeId4], map: "fkhyinfcmvat4")
102+
// @@index([rentalInformationTypeId], map: "fkhyinfhyint")
103+
// @@index([rentId], map: "inhyinf_2J70GWSR9")
104+
105+
@@map("hyinf")
105106
}

packages/property-base/src/adapters/residence-adapter.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Prisma } from '@prisma/client'
22
import { map } from 'lodash'
3+
import { logger } from 'onecore-utilities'
4+
import assert from 'node:assert'
35

46
import { trimStrings } from '@src/utils/data-conversion'
57

68
import { prisma } from './db'
7-
import { logger } from 'onecore-utilities'
89

910
//todo: add types
1011

@@ -59,6 +60,76 @@ const residenceSelect: Prisma.ResidenceSelect = {
5960
toDate: true,
6061
}
6162

63+
export const getResidenceByRentalId = async (rentalId: string) => {
64+
try {
65+
const propertyStructure = await prisma.propertyStructure.findFirst({
66+
where: {
67+
rentalId,
68+
propertyObject: { objectTypeId: 'balgh' },
69+
},
70+
select: {
71+
buildingCode: true,
72+
buildingName: true,
73+
propertyCode: true,
74+
propertyName: true,
75+
propertyId: true,
76+
buildingId: true,
77+
rentalId: true,
78+
propertyObject: {
79+
select: {
80+
rentalInformation: {
81+
select: {
82+
apartmentNumber: true,
83+
rentalInformationType: { select: { name: true, code: true } },
84+
},
85+
},
86+
residence: {
87+
select: {
88+
id: true,
89+
elevator: true,
90+
entrance: true,
91+
deleted: true,
92+
code: true,
93+
hygieneFacility: true,
94+
name: true,
95+
wheelchairAccessible: true,
96+
residenceType: {
97+
select: {
98+
code: true,
99+
name: true,
100+
roomCount: true,
101+
kitchen: true,
102+
},
103+
},
104+
},
105+
},
106+
},
107+
},
108+
},
109+
})
110+
111+
assert(propertyStructure, 'property-structure-not-found')
112+
assert(propertyStructure.propertyObject, 'property-object-not-found')
113+
assert(propertyStructure.propertyObject.residence, 'residence-not-found')
114+
assert(
115+
propertyStructure.propertyObject.rentalInformation,
116+
'rentalinformation-not-found'
117+
)
118+
119+
const {
120+
propertyObject: { residence, rentalInformation },
121+
} = propertyStructure
122+
123+
return trimStrings({
124+
...propertyStructure,
125+
propertyObject: { residence, rentalInformation },
126+
})
127+
} catch (err) {
128+
logger.error({ err }, 'residence-adapter.getResidenceByRentalId')
129+
throw err
130+
}
131+
}
132+
62133
export const getResidenceById = async (
63134
id: string
64135
): Promise<ResidenceWithRelations | null> => {

0 commit comments

Comments
 (0)