Add warn for proportions mutation for product (#40)

This commit is contained in:
Niklas Fondberg
2021-09-13 15:27:28 +02:00
committed by GitHub
parent 84bed9a7ce
commit 0a786d6754
5 changed files with 81 additions and 7 deletions
+41 -2
View File
@@ -15,9 +15,10 @@ import {
ProductBlacklistMarketInput, ProductBlacklistMarketInput,
ProductMaterials, ProductMaterials,
ProductSizeTypes, ProductSizeTypes,
ProductProportionsInput,
} from '../types/product-types'; } from '../types/product-types';
import { Maybe } from '../types/types'; import { Maybe } from '../types/types';
import { nullOrNumber } from './utils'; import { booleanStringField, nullOrNumber } from './utils';
const MINUTE = 60; const MINUTE = 60;
@@ -107,7 +108,9 @@ export class ProductAPI extends BaseSQLDataSource {
fields['wallpaperResolution'] = nullOrNumber( fields['wallpaperResolution'] = nullOrNumber(
fields['wallpaperResolution'] ?? null, fields['wallpaperResolution'] ?? null,
); );
fields['proportionsWarning?'] = fields['proportionsWarning?'] ?? ''; fields['proportionsWarning'] = booleanStringField(
fields['proportionsWarning'] ?? null,
);
fields['imageResolution'] = nullOrNumber(fields['imageResolution'] ?? null); fields['imageResolution'] = nullOrNumber(fields['imageResolution'] ?? null);
return <ProductFields>fields; return <ProductFields>fields;
} }
@@ -432,4 +435,40 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(insertMaterials); 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);
}
} }
+7
View File
@@ -25,3 +25,10 @@ export function convertToPossibleType(n: InputType) {
export function nullOrNumber(n: InputType) { export function nullOrNumber(n: InputType) {
return n === null || '' === n ? null : Number(n); return n === null || '' === n ? null : Number(n);
} }
export function booleanStringField(v: string | null) {
if (v === null || v === '0') {
return false;
}
return true;
}
+11
View File
@@ -129,6 +129,17 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); 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( async addOwnInteriorToPrintProduct(
_, _,
{ printId, uploadedS3Key }, { printId, uploadedS3Key },
+13 -3
View File
@@ -270,8 +270,6 @@ type Product {
Will be single values return in later release Will be single values return in later release
""" """
type: [ProductType] type: [ProductType]
# Below are for debug and will be removed soon
fields_json: JSON
} }
type ProductFields { type ProductFields {
@@ -283,7 +281,7 @@ type ProductFields {
canvasResolution: Int canvasResolution: Int
wallpaperResolution: Int wallpaperResolution: Int
copyright: String! copyright: String!
proportionsWarning: String proportionsWarning: Boolean!
marginWidthMax: Int marginWidthMax: Int
marginWidthMin: Int marginWidthMin: Int
marginHeightMax: Int marginHeightMax: Int
@@ -419,6 +417,14 @@ input ProductBlacklistingInput {
groupIds: [Int] groupIds: [Int]
} }
input ProductProportionsInput {
proportionsWarning: Boolean
marginWidthMax: Int!
marginWidthMin: Int!
marginHeightMax: Int!
marginHeightMin: Int!
}
type IdNumberResult { type IdNumberResult {
id: Int! id: Int!
} }
@@ -436,6 +442,10 @@ type Mutation {
): Product ): Product
productGroup(productId: Int!, groupIds: [Int]): Product productGroup(productId: Int!, groupIds: [Int]): Product
productKeywords(productId: Int!, keywordIds: [Int]): Product productKeywords(productId: Int!, keywordIds: [Int]): Product
productProportionsWarning(
productId: Int!
proportions: ProductProportionsInput!
): Product
addOwnInteriorToPrintProduct( addOwnInteriorToPrintProduct(
printId: Int! printId: Int!
uploadedS3Key: String! uploadedS3Key: String!
+9 -2
View File
@@ -27,6 +27,14 @@ export interface ProductBlacklistInput {
markets: Array<ProductBlacklistMarketInput>; markets: Array<ProductBlacklistMarketInput>;
} }
export interface ProductProportionsInput {
proportionsWarning: boolean;
marginWidthMax: number;
marginWidthMin: number;
marginHeightMax: number;
marginHeightMin: number;
}
// query types // query types
export interface ProductsFilterInput { export interface ProductsFilterInput {
pagination: PaginationInput; pagination: PaginationInput;
@@ -117,7 +125,6 @@ export interface Product {
blacklisting: [ProductBlacklist]; blacklisting: [ProductBlacklist];
type: [ProductType]; type: [ProductType];
fields: ProductFields; fields: ProductFields;
fields_json: JSON; // remove later
} }
// TODO: test stock products to see what props can be mandatory // TODO: test stock products to see what props can be mandatory
@@ -130,7 +137,7 @@ export interface ProductFields {
canvasResolution?: number; canvasResolution?: number;
wallpaperResolution?: number; wallpaperResolution?: number;
copyright?: string; copyright?: string;
proportionsWarning?: string; proportionsWarning?: boolean;
marginWidthMax?: number; marginWidthMax?: number;
marginWidthMin?: number; marginWidthMin?: number;
marginHeightMax?: number; marginHeightMax?: number;