Skip to content
Merged
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
144 changes: 143 additions & 1 deletion core/src/adapters/property-base-adapter/generated/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ export interface paths {
};
};
};
"/facilities/rental-id/{rentalId}": {
"/facilities/by-rental-id/{rentalId}": {
/**
* Get a facility by rental ID
* @description Returns a facility with the specified rental ID
Expand Down Expand Up @@ -726,6 +726,66 @@ export interface paths {
};
};
};
"/facilities/by-property-code/{propertyCode}": {
/**
* Get facilities by property code
* @description Returns a list of facilities for the specified property code
*/
get: {
parameters: {
path: {
/** @description The property code of the property */
propertyCode: string;
};
};
responses: {
/** @description Successfully retrieved the facilities */
200: {
content: {
"application/json": components["schemas"]["GetFacilitiesByPropertyCodeResponse"];
};
};
/** @description Facilities not found */
404: {
content: never;
};
/** @description Internal server error */
500: {
content: never;
};
};
};
};
"/facilities/by-building-code/{buildingCode}": {
/**
* Get facilities by building code
* @description Returns a list of facilities for the specified building code
*/
get: {
parameters: {
path: {
/** @description The building code of the building */
buildingCode: string;
};
};
responses: {
/** @description Successfully retrieved the facilities */
200: {
content: {
"application/json": components["schemas"]["GetFacilitiesByBuildingCodeResponse"];
};
};
/** @description Facilities not found */
404: {
content: never;
};
/** @description Internal server error */
500: {
content: never;
};
};
};
};
"/health": {
/**
* Check system health status
Expand Down Expand Up @@ -1394,6 +1454,88 @@ export interface components {
};
};
};
GetFacilitiesByPropertyCodeResponse: {
content: ({
id: string;
code: string;
name: string | null;
entrance: string | null;
deleted: boolean;
type: {
code: string;
name: string | null;
};
rentalInformation: ({
apartmentNumber: string | null;
rentalId: string | null;
type: {
code: string;
name: string | null;
};
}) | null;
property: {
id: string | null;
name: string | null;
code: string | null;
};
building: {
id: string | null;
name: string | null;
code: string | null;
};
areaSize: number | null;
})[];
_links: {
self: {
href: string;
};
link: {
href: string;
templated: boolean;
};
};
};
GetFacilitiesByBuildingCodeResponse: {
content: ({
id: string;
code: string;
name: string | null;
entrance: string | null;
deleted: boolean;
type: {
code: string;
name: string | null;
};
rentalInformation: ({
apartmentNumber: string | null;
rentalId: string | null;
type: {
code: string;
name: string | null;
};
}) | null;
property: {
id: string | null;
name: string | null;
code: string | null;
};
building: {
id: string | null;
name: string | null;
code: string | null;
};
areaSize: number | null;
})[];
_links: {
self: {
href: string;
};
link: {
href: string;
templated: boolean;
};
};
};
};
responses: never;
parameters: never;
Expand Down
63 changes: 62 additions & 1 deletion core/src/adapters/property-base-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export async function getFacilityByRentalId(
> {
try {
const fetchResponse = await client().GET(
'/facilities/rental-id/{rentalId}',
'/facilities/by-rental-id/{rentalId}',
{
params: { path: { rentalId } },
}
Expand Down Expand Up @@ -475,3 +475,64 @@ export async function getMaintenanceUnitsByPropertyCode(
return { ok: false, err: 'unknown' }
}
}

type GetFacilitiesByPropertyCodeResponse =
components['schemas']['GetFacilitiesByPropertyCodeResponse']['content']

export async function getFacilitiesByPropertyCode(
propertyCode: string
): Promise<
AdapterResult<GetFacilitiesByPropertyCodeResponse, 'not-found' | 'unknown'>
> {
try {
const fetchResponse = await client().GET(
'/facilities/by-property-code/{propertyCode}',
{
params: { path: { propertyCode } },
}
)

if (fetchResponse.response.status === 404) {
return { ok: false, err: 'not-found' }
}

if (!fetchResponse.data?.content) {
return { ok: false, err: 'unknown' }
}

return { ok: true, data: fetchResponse.data.content }
} catch (err) {
logger.error({ err }, 'property-base-adapter.getFacilitiesByPropertyCode')
return { ok: false, err: 'unknown' }
}
}

type GetFacilitiesByBuildingCodeResponse =
components['schemas']['GetFacilitiesByBuildingCodeResponse']['content']
export async function getFacilitiesByBuildingCode(
buildingCode: string
): Promise<
AdapterResult<GetFacilitiesByBuildingCodeResponse, 'not-found' | 'unknown'>
> {
try {
const fetchResponse = await client().GET(
'/facilities/by-building-code/{buildingCode}',
{
params: { path: { buildingCode } },
}
)

if (fetchResponse.response.status === 404) {
return { ok: false, err: 'not-found' }
}

if (!fetchResponse.data?.content) {
return { ok: false, err: 'unknown' }
}

return { ok: true, data: fetchResponse.data.content }
} catch (err) {
logger.error({ err }, 'property-base-adapter.getFacilitiesByBuildingCode')
return { ok: false, err: 'unknown' }
}
}
144 changes: 144 additions & 0 deletions core/src/services/property-base-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,148 @@ export const routes = (router: KoaRouter) => {
ctx.body = { error: 'Internal server error', ...metadata }
}
})

/**
* @swagger
* /propertyBase/facilities/by-property-code/{propertyCode}:
* get:
* summary: Get facilities by property code.
* description: Returns all facilities belonging to a property.
* tags:
* - Property base Service
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: propertyCode
* required: true
* schema:
* type: string
* description: The code of the property for which to retrieve facilities.
* responses:
* 200:
* description: Successfully retrieved the facilities.
* content:
* application/json:
* schema:
* type: object
* properties:
* content:
* type: array
* items:
* type: object
* 404:
* description: Facilities not found.
* 500:
* description: Internal server error.
*/
router.get('(.*)/facilities/by-property-code/:propertyCode', async (ctx) => {
const metadata = generateRouteMetadata(ctx)
const { propertyCode } = ctx.params

logger.info(`GET /facilities/by-property-code/${propertyCode}`, metadata)

try {
const result =
await propertyBaseAdapter.getFacilitiesByPropertyCode(propertyCode)

if (!result.ok) {
if (result.err === 'not-found') {
ctx.status = 404
ctx.body = { error: 'Facilities not found', ...metadata }
return
}

logger.error(
result.err,
'Error getting facilities from property-base',
metadata
)
ctx.status = 500
ctx.body = { error: 'Internal server error', ...metadata }
return
}

ctx.body = {
content: result.data satisfies Array<schemas.FacilityDetails>,
...metadata,
}
} catch (error) {
logger.error(error, 'Internal server error', metadata)
ctx.status = 500
ctx.body = { error: 'Internal server error', ...metadata }
}
})

/**
* @swagger
* /propertyBase/facilities/by-building-code/{buildingCode}:
* get:
* summary: Get facilities by building code.
* description: Returns all facilities belonging to a building.
* tags:
* - Property base Service
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: buildingCode
* required: true
* schema:
* type: string
* description: The code of the building for which to retrieve facilities.
* responses:
* 200:
* description: Successfully retrieved the facilities.
* content:
* application/json:
* schema:
* type: object
* properties:
* content:
* type: array
* items:
* type: object
* 404:
* description: Facilities not found.
* 500:
* description: Internal server error.
*/
router.get('(.*)/facilities/by-building-code/:buildingCode', async (ctx) => {
const metadata = generateRouteMetadata(ctx)
const { buildingCode } = ctx.params

logger.info(`GET /facilities/by-building-code/${buildingCode}`, metadata)

try {
const result =
await propertyBaseAdapter.getFacilitiesByBuildingCode(buildingCode)

if (!result.ok) {
if (result.err === 'not-found') {
ctx.status = 404
ctx.body = { error: 'Facilities not found', ...metadata }
return
}

logger.error(
result.err,
'Error getting facilities from property-base',
metadata
)
ctx.status = 500
ctx.body = { error: 'Internal server error', ...metadata }
return
}

ctx.body = {
content: result.data satisfies Array<schemas.FacilityDetails>,
...metadata,
}
} catch (error) {
logger.error(error, 'Internal server error', metadata)
ctx.status = 500
ctx.body = { error: 'Internal server error', ...metadata }
}
})
}
Loading