More careful default types 2 (#37)
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
ProductSizeTypes,
|
||||
} from '../types/product-types';
|
||||
import { Maybe } from '../types/types';
|
||||
import { convertToPossibleType } from './utils';
|
||||
import { convertToPossibleType, nullOrNumber } from './utils';
|
||||
|
||||
const MINUTE = 60;
|
||||
|
||||
@@ -75,11 +75,40 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
if (!row.fields) {
|
||||
return null; // 53460 for example
|
||||
}
|
||||
// Convert to camelCase first
|
||||
const fields = Object.keys(row.fields).reduce((mem, key) => {
|
||||
mem[camelcase(key)] = convertToPossibleType(row.fields[key]);
|
||||
mem[camelcase(key)] = row.fields[key];
|
||||
return mem;
|
||||
}, {});
|
||||
|
||||
fields['artNo'] = fields['artNo'];
|
||||
fields['name'] = fields['name'];
|
||||
fields['copyright'] = fields['copyright'] ?? '';
|
||||
fields['batch'] = fields['batch'] ?? '';
|
||||
fields['height'] = nullOrNumber(fields['height'] ?? null);
|
||||
fields['width'] = nullOrNumber(fields['width'] ?? null);
|
||||
fields['printFileWidth'] = nullOrNumber(fields['printFileWidth'] ?? null);
|
||||
fields['printFileHeight'] = nullOrNumber(fields['printFileHeight'] ?? null);
|
||||
fields['printFileDpi'] = nullOrNumber(fields['printFileDpi'] ?? null);
|
||||
fields['marginWidthMax'] = nullOrNumber(fields['marginWidthMax'] ?? null);
|
||||
fields['marginWidthMin'] = nullOrNumber(fields['marginWidthMin'] ?? null);
|
||||
fields['marginHeightMax'] = nullOrNumber(fields['marginHeightMax'] ?? null);
|
||||
fields['marginHeightMin'] = nullOrNumber(fields['marginHeightMin'] ?? null);
|
||||
fields['focusXpoint2'] = nullOrNumber(fields['focusXpoint2'] ?? null);
|
||||
fields['focusYpoint2'] = nullOrNumber(fields['focusYpoint2'] ?? null);
|
||||
fields['focusXpoint'] = nullOrNumber(fields['focusXpoint'] ?? null);
|
||||
fields['focusYpoint'] = nullOrNumber(fields['focusYpoint'] ?? null);
|
||||
fields['photowallResolution'] = nullOrNumber(
|
||||
fields['photowallResolution'] ?? null,
|
||||
);
|
||||
fields['canvasResolution'] = nullOrNumber(
|
||||
fields['canvasResolution'] ?? null,
|
||||
);
|
||||
fields['wallpaperResolution'] = nullOrNumber(
|
||||
fields['wallpaperResolution'] ?? null,
|
||||
);
|
||||
fields['proportionsWarning?'] = fields['proportionsWarning?'] ?? '';
|
||||
fields['imageResolution'] = nullOrNumber(fields['imageResolution'] ?? null);
|
||||
return <ProductFields>fields;
|
||||
}
|
||||
|
||||
@@ -104,8 +133,6 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
row.fields = this.getProductFields(row);
|
||||
row.designerId = row.designerid;
|
||||
row.orientation = this.getOrientation(row.fields);
|
||||
row.copyright = row.copyright ?? '';
|
||||
row.batch = row.batch ?? '';
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -114,7 +141,7 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
const res = await this.cachedRaw(query)
|
||||
.cache(MINUTE * 60)
|
||||
.then((data) => data.rows);
|
||||
return convertToPossibleType(res[0]['count']); // Optimize later to return Promise
|
||||
return res[0]['count'] as number; // Optimize later to return Promise
|
||||
}
|
||||
|
||||
async getProducts(input: ProductsFilterInput): Promise<Array<Product>> {
|
||||
|
||||
Reference in New Issue
Block a user