Skip to content

Commit 46fceb8

Browse files
authored
Merge pull request #67 from Bostads-AB-Mimer/feature/mim-531-grundinformation-yta
MIM-531: Fetch size (yta) from xpand and display in residence basic information
2 parents 5b025fb + ebf9a35 commit 46fceb8

File tree

11 files changed

+120
-6
lines changed

11 files changed

+120
-6
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
model QuantityCategoryLink {
2+
id String @id @map("keycmvap") @db.Char(15)
3+
quantityTypeId String @map("keycmvat") @db.Char(15)
4+
categoryId String @map("keycmtyp") @db.Char(15)
5+
timestamp String @map("timestamp") @db.Char(10)
6+
7+
quantityType QuantityType @relation(fields: [quantityTypeId], references: [id])
8+
category QuantityCategory @relation(fields: [categoryId], references: [id])
9+
10+
@@unique([quantityTypeId, categoryId])
11+
@@index([categoryId])
12+
@@index([quantityTypeId])
13+
@@map("cmvap")
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
model QuantityCategory {
2+
id String @id @map("keycmtyp") @db.Char(15)
3+
parentCategoryId String? @map("keycmtyp2") @db.Char(15)
4+
name String @map("caption") @db.VarChar(60)
5+
sortOrder Int @default(0) @map("sortorder") @db.SmallInt
6+
allowTextValues Int @default(0) @map("txtallow") @db.TinyInt
7+
allowSubCategories Int @default(0) @map("sublvls") @db.TinyInt
8+
isPublished Int @default(1) @map("publish") @db.TinyInt
9+
module String? @map("validmdl") @db.VarChar(80)
10+
isHidden Int @default(0) @map("hidetype") @db.TinyInt
11+
systemStandard Int @default(0) @map("repab") @db.TinyInt
12+
timestamp String @map("timestamp") @db.Char(10)
13+
14+
parent QuantityCategory? @relation("CategoryHierarchy", fields: [parentCategoryId], references: [id], onDelete: NoAction, onUpdate: NoAction)
15+
subtypes QuantityCategory[] @relation("CategoryHierarchy")
16+
links QuantityCategoryLink[]
17+
18+
@@index([parentCategoryId])
19+
@@map("cmtyp")
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
model QuantityType {
2+
id String @id @map("keycmvat") @db.Char(15)
3+
unitId String? @map("keycmuni") @db.Char(15)
4+
name String @map("caption") @db.VarChar(30)
5+
inputMask String? @map("inputmask") @db.VarChar(30)
6+
locked Int @default(0) @map("locked") @db.TinyInt
7+
systemStandard Int @default(0) @map("repabkod") @db.TinyInt
8+
timestamp String @map("timestamp") @db.Char(10)
9+
10+
quantityValues QuantityValue[]
11+
categoryLinks QuantityCategoryLink[]
12+
13+
@@index([unitId])
14+
@@index([name])
15+
@@map("cmvat")
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
model QuantityValue {
2+
id String @id @map("keycmval") @db.Char(15)
3+
tableName String @map("keydbtbl") @db.Char(15)
4+
code String @map("keycode") @db.Char(15)
5+
quantityTypeId String @map("keycmvat") @db.Char(15)
6+
value Float @default(0.0) @db.Money
7+
timestamp String @map("timestamp") @db.Char(10)
8+
9+
quantityType QuantityType @relation(fields: [quantityTypeId], references: [id])
10+
11+
@@unique([quantityTypeId, code])
12+
@@index([quantityTypeId])
13+
@@index([code])
14+
@@index([tableName])
15+
@@map("cmval")
16+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ model Residence {
3636
toDate DateTime @map("tdate") @db.DateTime
3737
timestamp String @map("timestamp") @db.Char(10) // TODO: consider changing timestamp later
3838
39-
residenceType ResidenceType @relation(fields: [residenceTypeId], references: [id], onUpdate: NoAction, map: "fkbalghkeybalgt ")
40-
propertyObject PropertyObject @relation(fields: [propertyObjectId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fkbalghkeycmobj")
41-
comments TypeText[] @relation("ResidenceToTypeText")
39+
residenceType ResidenceType @relation(fields: [residenceTypeId], references: [id], onUpdate: NoAction, map: "fkbalghkeybalgt ")
40+
propertyObject PropertyObject @relation(fields: [propertyObjectId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fkbalghkeycmobj")
41+
comments TypeText[] @relation("ResidenceToTypeText")
42+
4243
// TODO: Verify relation for checklistId as the InspectionProtocol model was provided but fields need to be verified
4344
// inspectionProtocol InspectionProtocol? @relation(fields: [checklistId], references: [inspectionProtocolId], onUpdate: NoAction, map: "fkbalghkeylbpro ")
4445

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,47 @@ export type ResidenceSearchResult = Prisma.ResidenceGetPayload<{
176176
}
177177
}>
178178

179+
export const getResidenceSizeByRentalId = async (rentalId: string) => {
180+
try {
181+
// Get property structure information for the residence
182+
const propertyInfo = await prisma.propertyStructure.findFirst({
183+
where: {
184+
rentalId,
185+
propertyObject: { objectTypeId: 'balgh' },
186+
NOT: { propertyCode: null },
187+
},
188+
select: {
189+
name: true,
190+
propertyObject: {
191+
select: {
192+
id: true,
193+
},
194+
},
195+
},
196+
})
197+
198+
if (propertyInfo === null) {
199+
logger.warn(
200+
'residence-adapter.getResidenceSizeByRentalId: No property structure found for rentalId'
201+
)
202+
return null
203+
}
204+
205+
// Get area size for the property object
206+
const areaSize = await prisma.quantityValue.findFirst({
207+
where: {
208+
code: propertyInfo.propertyObject.id,
209+
quantityTypeId: 'BOA',
210+
},
211+
})
212+
213+
return areaSize
214+
} catch (err) {
215+
logger.error({ err }, 'residence-adapter.getResidenceSizeById')
216+
throw err
217+
}
218+
}
219+
179220
export const searchResidences = async (
180221
q: string
181222
): Promise<Array<ResidenceSearchResult>> => {

packages/property-base/src/routes/residences-route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from 'zod'
44

55
import {
66
getResidenceById,
7+
getResidenceSizeByRentalId,
78
getResidencesByBuildingCode,
89
getResidencesByBuildingCodeAndStaircaseCode,
910
searchResidences,
@@ -234,14 +235,16 @@ export const routes = (router: KoaRouter) => {
234235
ctx.status = 404
235236
return
236237
}
237-
238238
// TODO: find out why building is null in residence
239239

240240
const rentalId =
241241
residence.propertyObject?.propertyStructures?.length > 0
242242
? residence.propertyObject.propertyStructures[0].rentalId
243243
: null
244244

245+
// Get area size for the residence (yta)
246+
const size = rentalId ? await getResidenceSizeByRentalId(rentalId) : null
247+
245248
const mappedResidence = {
246249
id: residence.id,
247250
code: residence.code,
@@ -331,6 +334,7 @@ export const routes = (router: KoaRouter) => {
331334
name: residence.propertyObject.propertyStructures[0].buildingName,
332335
},
333336
malarEnergiFacilityId: residence.comments?.[0]?.text || null,
337+
size: size?.value || null,
334338
} satisfies ResidenceDetails
335339

336340
ctx.status = 200

packages/property-base/src/types/residence.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const ResidenceDetailedSchema = z.object({
125125
code: z.string().nullable(),
126126
}),
127127
malarEnergiFacilityId: z.string().nullable(),
128+
size: z.number().nullable(),
128129
})
129130

130131
export type ExternalResidence = z.infer<typeof ResidenceSchema>

packages/property-tree/src/components/residence/ResidenceBasicInfo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export const ResidenceBasicInfo = ({ residence }: ResidenceBasicInfoProps) => {
7171
<div>
7272
<p className="text-sm text-muted-foreground">Yta</p>
7373
<p className="font-medium">
74-
N/A
75-
{/* {residence.size ? `${residence.size} m²` : '-'} */}
74+
{residence.size ? `${residence.size} m²` : '-'}
7675
</p>
7776
</div>
7877
<div>

packages/property-tree/src/services/api/core/generated/api-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,7 @@ export interface components {
24382438
code: string | null;
24392439
};
24402440
malarEnergiFacilityId: string | null;
2441+
size: number | null;
24412442
};
24422443
Staircase: {
24432444
id: string;

0 commit comments

Comments
 (0)