Add warn for proportions mutation for product (#40)
This commit is contained in:
@@ -15,9 +15,10 @@ import {
|
||||
ProductBlacklistMarketInput,
|
||||
ProductMaterials,
|
||||
ProductSizeTypes,
|
||||
ProductProportionsInput,
|
||||
} from '../types/product-types';
|
||||
import { Maybe } from '../types/types';
|
||||
import { nullOrNumber } from './utils';
|
||||
import { booleanStringField, nullOrNumber } from './utils';
|
||||
|
||||
const MINUTE = 60;
|
||||
|
||||
@@ -107,7 +108,9 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
fields['wallpaperResolution'] = nullOrNumber(
|
||||
fields['wallpaperResolution'] ?? null,
|
||||
);
|
||||
fields['proportionsWarning?'] = fields['proportionsWarning?'] ?? '';
|
||||
fields['proportionsWarning'] = booleanStringField(
|
||||
fields['proportionsWarning'] ?? null,
|
||||
);
|
||||
fields['imageResolution'] = nullOrNumber(fields['imageResolution'] ?? null);
|
||||
return <ProductFields>fields;
|
||||
}
|
||||
@@ -432,4 +435,40 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
return Promise.all(insertMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
async setProportionsWarning(
|
||||
productId: number,
|
||||
proportions: ProductProportionsInput,
|
||||
): Promise<Promise<void>[]> {
|
||||
const promises = [];
|
||||
promises.push(
|
||||
this.updateProductField(
|
||||
productId,
|
||||
'proportions_warning',
|
||||
proportions.proportionsWarning ? '1' : '0',
|
||||
),
|
||||
this.updateProductField(
|
||||
productId,
|
||||
'margin_width_max',
|
||||
proportions.marginWidthMax.toString(),
|
||||
),
|
||||
this.updateProductField(
|
||||
productId,
|
||||
'margin_width_min',
|
||||
proportions.marginWidthMin.toString(),
|
||||
),
|
||||
this.updateProductField(
|
||||
productId,
|
||||
'margin_height_max',
|
||||
proportions.marginHeightMax.toString(),
|
||||
),
|
||||
this.updateProductField(
|
||||
productId,
|
||||
'margin_height_min',
|
||||
proportions.marginHeightMin.toString(),
|
||||
),
|
||||
);
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +25,10 @@ export function convertToPossibleType(n: InputType) {
|
||||
export function nullOrNumber(n: InputType) {
|
||||
return n === null || '' === n ? null : Number(n);
|
||||
}
|
||||
|
||||
export function booleanStringField(v: string | null) {
|
||||
if (v === null || v === '0') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -129,6 +129,17 @@ export const productMutationTypeDefs = {
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
async productProportionsWarning(
|
||||
_,
|
||||
{ productId, proportions },
|
||||
{ dataSources },
|
||||
) {
|
||||
await (<ProductAPI>dataSources.productApi).setProportionsWarning(
|
||||
productId,
|
||||
proportions,
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
async addOwnInteriorToPrintProduct(
|
||||
_,
|
||||
{ printId, uploadedS3Key },
|
||||
|
||||
+13
-3
@@ -270,8 +270,6 @@ type Product {
|
||||
Will be single values return in later release
|
||||
"""
|
||||
type: [ProductType]
|
||||
# Below are for debug and will be removed soon
|
||||
fields_json: JSON
|
||||
}
|
||||
|
||||
type ProductFields {
|
||||
@@ -283,7 +281,7 @@ type ProductFields {
|
||||
canvasResolution: Int
|
||||
wallpaperResolution: Int
|
||||
copyright: String!
|
||||
proportionsWarning: String
|
||||
proportionsWarning: Boolean!
|
||||
marginWidthMax: Int
|
||||
marginWidthMin: Int
|
||||
marginHeightMax: Int
|
||||
@@ -419,6 +417,14 @@ input ProductBlacklistingInput {
|
||||
groupIds: [Int]
|
||||
}
|
||||
|
||||
input ProductProportionsInput {
|
||||
proportionsWarning: Boolean
|
||||
marginWidthMax: Int!
|
||||
marginWidthMin: Int!
|
||||
marginHeightMax: Int!
|
||||
marginHeightMin: Int!
|
||||
}
|
||||
|
||||
type IdNumberResult {
|
||||
id: Int!
|
||||
}
|
||||
@@ -436,6 +442,10 @@ type Mutation {
|
||||
): Product
|
||||
productGroup(productId: Int!, groupIds: [Int]): Product
|
||||
productKeywords(productId: Int!, keywordIds: [Int]): Product
|
||||
productProportionsWarning(
|
||||
productId: Int!
|
||||
proportions: ProductProportionsInput!
|
||||
): Product
|
||||
addOwnInteriorToPrintProduct(
|
||||
printId: Int!
|
||||
uploadedS3Key: String!
|
||||
|
||||
@@ -27,6 +27,14 @@ export interface ProductBlacklistInput {
|
||||
markets: Array<ProductBlacklistMarketInput>;
|
||||
}
|
||||
|
||||
export interface ProductProportionsInput {
|
||||
proportionsWarning: boolean;
|
||||
marginWidthMax: number;
|
||||
marginWidthMin: number;
|
||||
marginHeightMax: number;
|
||||
marginHeightMin: number;
|
||||
}
|
||||
|
||||
// query types
|
||||
export interface ProductsFilterInput {
|
||||
pagination: PaginationInput;
|
||||
@@ -117,7 +125,6 @@ export interface Product {
|
||||
blacklisting: [ProductBlacklist];
|
||||
type: [ProductType];
|
||||
fields: ProductFields;
|
||||
fields_json: JSON; // remove later
|
||||
}
|
||||
|
||||
// TODO: test stock products to see what props can be mandatory
|
||||
@@ -130,7 +137,7 @@ export interface ProductFields {
|
||||
canvasResolution?: number;
|
||||
wallpaperResolution?: number;
|
||||
copyright?: string;
|
||||
proportionsWarning?: string;
|
||||
proportionsWarning?: boolean;
|
||||
marginWidthMax?: number;
|
||||
marginWidthMin?: number;
|
||||
marginHeightMax?: number;
|
||||
|
||||
Reference in New Issue
Block a user