diff --git a/src/datasources/interior-api.ts b/src/datasources/interior-api.ts index 92d590f..716358c 100644 --- a/src/datasources/interior-api.ts +++ b/src/datasources/interior-api.ts @@ -3,7 +3,7 @@ import { InteriorsFilter, InteriorType, } from '../types/interior-types'; -import { Orientation } from '../types/product-types'; +import { Orientation, ProductGroup } from '../types/product-types'; import { Maybe } from '../types/types'; import { BaseSQLDataSource } from './BaseSQLDataSource'; import { ImageServerApi } from './imageserver-api'; @@ -18,18 +18,22 @@ export class InteriorAPI extends BaseSQLDataSource { this.imageServerApi = imageServerApi; } - getInteriorType(roomTypePart: string): string { - switch (roomTypePart) { - case 'wallpaper': + getInteriorType(productGroup: ProductGroup): string { + switch (productGroup) { + case ProductGroup.DESIGNER_WALLPAPER: + case ProductGroup.WALLPAPER: + case ProductGroup.PHOTO_WALLPAPER: return InteriorType[InteriorType.WALLPAPER]; - case 'painting': + case ProductGroup.CANVAS: return InteriorType[InteriorType.PAINTING]; - case 'poster': + case ProductGroup.POSTER: return InteriorType[InteriorType.POSTER]; - case 'framed-print': + case ProductGroup.FRAMED_PRINT: return InteriorType[InteriorType.FRAMED_PRINT]; default: - throw new Error(`Unknown room type: ${roomTypePart}`); + throw new Error( + `Could not define interior type from product group [${productGroup}]`, + ); } } @@ -51,10 +55,12 @@ export class InteriorAPI extends BaseSQLDataSource { } decorateRow(row: any): Interior { - const parts = row.roomName.split('_'); - row.roomNumber = this.getInteriorRoomNumber(parts[0]); - row.type = this.getInteriorType(parts[1]); - row.orientation = this.getInteriorOrientation(parts[2]); + if (row.roomName) { + const parts = row.roomName.split('_'); + row.roomNumber = this.getInteriorRoomNumber(parts[0]); + row.orientation = this.getInteriorOrientation(parts[2]); + } + row.type = this.getInteriorType(row.productGroup); return row; } @@ -112,7 +118,7 @@ export class InteriorAPI extends BaseSQLDataSource { return rows.map((row) => { const res = { ...row, - id: row.roomId, + id: row.interiorId, }; this.decorateRow(res); return res;