22: fixed error when roomName null (#23)

* 22: fixed error when roomName null

* id now from new interiorId

* removed null optional
This commit is contained in:
Arwid Thornström
2021-09-03 13:04:01 +02:00
committed by GitHub
parent 596d21dce8
commit a4b847c7be
+19 -13
View File
@@ -3,7 +3,7 @@ import {
InteriorsFilter, InteriorsFilter,
InteriorType, InteriorType,
} from '../types/interior-types'; } from '../types/interior-types';
import { Orientation } from '../types/product-types'; import { Orientation, ProductGroup } from '../types/product-types';
import { Maybe } from '../types/types'; import { Maybe } from '../types/types';
import { BaseSQLDataSource } from './BaseSQLDataSource'; import { BaseSQLDataSource } from './BaseSQLDataSource';
import { ImageServerApi } from './imageserver-api'; import { ImageServerApi } from './imageserver-api';
@@ -18,18 +18,22 @@ export class InteriorAPI extends BaseSQLDataSource {
this.imageServerApi = imageServerApi; this.imageServerApi = imageServerApi;
} }
getInteriorType(roomTypePart: string): string { getInteriorType(productGroup: ProductGroup): string {
switch (roomTypePart) { switch (productGroup) {
case 'wallpaper': case ProductGroup.DESIGNER_WALLPAPER:
case ProductGroup.WALLPAPER:
case ProductGroup.PHOTO_WALLPAPER:
return InteriorType[InteriorType.WALLPAPER]; return InteriorType[InteriorType.WALLPAPER];
case 'painting': case ProductGroup.CANVAS:
return InteriorType[InteriorType.PAINTING]; return InteriorType[InteriorType.PAINTING];
case 'poster': case ProductGroup.POSTER:
return InteriorType[InteriorType.POSTER]; return InteriorType[InteriorType.POSTER];
case 'framed-print': case ProductGroup.FRAMED_PRINT:
return InteriorType[InteriorType.FRAMED_PRINT]; return InteriorType[InteriorType.FRAMED_PRINT];
default: 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 { decorateRow(row: any): Interior {
const parts = row.roomName.split('_'); if (row.roomName) {
row.roomNumber = this.getInteriorRoomNumber(parts[0]); const parts = row.roomName.split('_');
row.type = this.getInteriorType(parts[1]); row.roomNumber = this.getInteriorRoomNumber(parts[0]);
row.orientation = this.getInteriorOrientation(parts[2]); row.orientation = this.getInteriorOrientation(parts[2]);
}
row.type = this.getInteriorType(row.productGroup);
return row; return row;
} }
@@ -112,7 +118,7 @@ export class InteriorAPI extends BaseSQLDataSource {
return rows.map((row) => { return rows.map((row) => {
const res = { const res = {
...row, ...row,
id: row.roomId, id: row.interiorId,
}; };
this.decorateRow(res); this.decorateRow(res);
return res; return res;