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,
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;