added comments in code (#81)

This commit is contained in:
Arwid Thornström
2021-10-29 07:22:42 +02:00
committed by GitHub
parent ee16ff44c6
commit 48972d7090
2 changed files with 134 additions and 1 deletions
+54 -1
View File
@@ -243,9 +243,11 @@ export class ProductAPI extends BaseSQLDataSource {
async searchByBatch(name: string): Promise<Array<Batch>> { async searchByBatch(name: string): Promise<Array<Batch>> {
return this.searchByFieldValue<Batch>(name, 36, 'batch'); return this.searchByFieldValue<Batch>(name, 36, 'batch');
} }
async searchByCopyright(name: string): Promise<Array<Copyright>> { async searchByCopyright(name: string): Promise<Array<Copyright>> {
return this.searchByFieldValue<Copyright>(name, 25, 'copyright'); return this.searchByFieldValue<Copyright>(name, 25, 'copyright');
} }
async searchByFieldValue<T>( async searchByFieldValue<T>(
name: string, name: string,
fieldNo: number, fieldNo: number,
@@ -307,6 +309,11 @@ export class ProductAPI extends BaseSQLDataSource {
); );
} }
/**
* @function getUniqueProductPath
* @description Returns a unique product path, ex if foggy-forest is take it will return foggy-forest-1
* foggy-forest-2 and so on.
*/
async getUniqueProductPath( async getUniqueProductPath(
path: string, path: string,
productId?: number, productId?: number,
@@ -359,6 +366,11 @@ export class ProductAPI extends BaseSQLDataSource {
return newPath; return newPath;
} }
/**
* @function addProduct
* @description Adds a new product to system, will use batchname and name to
* set a unique path, artNo is the productId with e infront.
*/
async addProduct(name: string, batch: string): Promise<number> { async addProduct(name: string, batch: string): Promise<number> {
const path = batch ? batch + ' ' + name : name; const path = batch ? batch + ' ' + name : name;
const productPath = slug(path); const productPath = slug(path);
@@ -379,6 +391,10 @@ export class ProductAPI extends BaseSQLDataSource {
return id; return id;
} }
/**
* @function updateProductInfo
* @description Update base info for a product
*/
async updateProductInfo( async updateProductInfo(
productId: number, productId: number,
info: ProductInfoInput, info: ProductInfoInput,
@@ -436,6 +452,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises); return Promise.all(promises);
} }
/**
* @function updateFocusPoint
* @description Updates the focus point on a motif
*/
async updateFocusPoint( async updateFocusPoint(
productId: number, productId: number,
focusXpoint2: number, focusXpoint2: number,
@@ -461,6 +481,10 @@ export class ProductAPI extends BaseSQLDataSource {
return this.updateProductField(productId, 'comments', comments); return this.updateProductField(productId, 'comments', comments);
} }
/**
* @function updateBlacklisting
* @description Updates the blacklisted countries and sections
*/
async updateBlacklisting( async updateBlacklisting(
productId: number, productId: number,
markets: Array<ProductBlacklistMarketInput>, markets: Array<ProductBlacklistMarketInput>,
@@ -488,6 +512,11 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(insertsPromises); return Promise.all(insertsPromises);
} }
/**
* @function setWallpaperTypes
* @description Sets what wallpaper type a product is sold as, meaning the sections on site
* like wallpaper or design-wallpaper
*/
async setWallpaperTypes( async setWallpaperTypes(
productId: number, productId: number,
wallpaperTypes: Array<ProductWallpaperType>, wallpaperTypes: Array<ProductWallpaperType>,
@@ -506,6 +535,11 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises); return Promise.all(promises);
} }
/**
* @function updateGroups
* @description Updates the groups that a product is sold in, like wallpaper, canvas or
* poster. Note that group 3 is repeating wallpapers.
*/
async updateGroups(productId: number, groupIds: number[]): Promise<any[]> { async updateGroups(productId: number, groupIds: number[]): Promise<any[]> {
// Fetch the current state // Fetch the current state
const allPrintProducts = await this.knex.raw( const allPrintProducts = await this.knex.raw(
@@ -627,6 +661,7 @@ export class ProductAPI extends BaseSQLDataSource {
/** /**
* @func productGroupInteriors * @func productGroupInteriors
* @description Sets interiors to a product and product group
* *
* @param productId The product id for the targeted product * @param productId The product id for the targeted product
* @param groupId The targeted group id, if product does not have group it will be created * @param groupId The targeted group id, if product does not have group it will be created
@@ -728,6 +763,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(insertPromises); return Promise.all(insertPromises);
} }
/**
* @function setProportionsWarning
* @description Sets propotion warning-values to a product
*/
async setProportionsWarning( async setProportionsWarning(
productId: number, productId: number,
proportions: ProductProportionsInput, proportions: ProductProportionsInput,
@@ -764,6 +803,11 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises); return Promise.all(promises);
} }
/**
* @function addRelatedProducts
* @description Adds a related product to a product, when settings a related product
* the target product will get the same related connection.
*/
async addRelatedProducts( async addRelatedProducts(
productId: number, productId: number,
articleNumbers: Array<string>, articleNumbers: Array<string>,
@@ -802,7 +846,8 @@ export class ProductAPI extends BaseSQLDataSource {
} }
/** /**
* Removes variant products from productid as well as the sent in * @function removeRelatedProducts
* @description Removes variant products from productid as well as the sent in
* productid from its variants * productid from its variants
*/ */
async removeRelatedProducts( async removeRelatedProducts(
@@ -825,6 +870,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises); return Promise.all(promises);
} }
/**
* @function addCategoriesToProduct
* @description Adds a list of categories to a product
*/
async addCategoriesToProduct( async addCategoriesToProduct(
productId, productId,
categoryIds, categoryIds,
@@ -838,6 +887,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises); return Promise.all(promises);
} }
/**
* @function removeCategoriesFromProduct
* @description Removes list of categories from a product
*/
async removeCategoriesFromProduct( async removeCategoriesFromProduct(
productId, productId,
categoryIds, categoryIds,
+80
View File
@@ -117,6 +117,10 @@ export const productQueryTypeDefs = {
/////////////////// ///////////////////
// Mutations below // Mutations below
export const productMutationTypeDefs = { export const productMutationTypeDefs = {
/**
* @function addProduct
* @description Will add a product
*/
async addProduct(_, { name, batch }, { dataSources, auth }) { async addProduct(_, { name, batch }, { dataSources, auth }) {
checkAccess(['products.write'], auth); checkAccess(['products.write'], auth);
const id = await (<ProductAPI>dataSources.productApi).addProduct( const id = await (<ProductAPI>dataSources.productApi).addProduct(
@@ -125,6 +129,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(id); return (<ProductAPI>dataSources.productApi).getProduct(id);
}, },
/**
* @function productInfo
* @description Mutate base information about a product
*/
async productInfo(_, { productId, info }, { dataSources, auth }) { async productInfo(_, { productId, info }, { dataSources, auth }) {
checkAccess(['products.write'], auth); checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateProductInfo( await (<ProductAPI>dataSources.productApi).updateProductInfo(
@@ -133,6 +142,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function productFocusPoint
* @description Mutate the focuspoint for a product
*/
async productFocusPoint( async productFocusPoint(
_, _,
{ productId, focusXpoint2, focusYpoint2 }, { productId, focusXpoint2, focusYpoint2 },
@@ -154,6 +168,11 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product); )).generateNewInteriors(product);
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function productBlacklisting
* @description Mutate the product blacklist
*/
async productBlacklisting(_, { productId, markets }, { dataSources, auth }) { async productBlacklisting(_, { productId, markets }, { dataSources, auth }) {
checkAccess(['products.write'], auth); checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateBlacklisting( await (<ProductAPI>dataSources.productApi).updateBlacklisting(
@@ -162,6 +181,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function productGroup
* @description Mutate the product groups, when changing group interiors lambda is triggered.
*/
async productGroup(_, { productId, groupIds }, { dataSources, auth }) { async productGroup(_, { productId, groupIds }, { dataSources, auth }) {
checkAccess(['products.write'], auth); checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateGroups( await (<ProductAPI>dataSources.productApi).updateGroups(
@@ -176,6 +200,11 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product); )).generateNewInteriors(product);
return product; return product;
}, },
/**
* @function productGroupInteriors
* @description Mutate the list of interiors on a product and its groups.
*/
async productGroupInteriors( async productGroupInteriors(
_, _,
{ productId, groupId, uris }, { productId, groupId, uris },
@@ -189,6 +218,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function productKeywords
* @description Mutate the keywords for a product
*/
async productKeywords(_, { productId, keywordIds }, { dataSources, auth }) { async productKeywords(_, { productId, keywordIds }, { dataSources, auth }) {
checkAccess(['products.write'], auth); checkAccess(['products.write'], auth);
await (<KeywordAPI>dataSources.keywordApi).setProductKeywords( await (<KeywordAPI>dataSources.keywordApi).setProductKeywords(
@@ -197,6 +231,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function productProportionsWarning
* @description Mutate the values for proportion warnings on a product
*/
async productProportionsWarning( async productProportionsWarning(
_, _,
{ productId, proportions }, { productId, proportions },
@@ -209,6 +248,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function addOwnInteriorToPrintProduct
* @description Add a uploaded interior image to a product and its groups.
*/
async addOwnInteriorToPrintProduct( async addOwnInteriorToPrintProduct(
_, _,
{ printId, uploadedS3Key }, { printId, uploadedS3Key },
@@ -220,6 +264,11 @@ export const productMutationTypeDefs = {
uploadedS3Key, uploadedS3Key,
); );
}, },
/**
* @function productWallpaperType
* @description Set the wallpapertype for a wallpaper product
*/
async productWallpaperType( async productWallpaperType(
_, _,
{ productId, wallpaperTypes }, { productId, wallpaperTypes },
@@ -232,6 +281,13 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function updateProductImage
* @description Set a new image for the product, image is first uploaded to inquiries
* bucket then moved to photowall-images. When new image is uploaded interiors are
* generated.
*/
async updateProductImage( async updateProductImage(
_, _,
{ productId, uploadedS3Key, width, height }, { productId, uploadedS3Key, width, height },
@@ -263,6 +319,12 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product); )).generateNewInteriors(product);
return 'success'; return 'success';
}, },
/**
* @function addRelatedProducts
* @description Adds a related product to a product, when doing this the related product
* gets the same relationship back. So products are always related to eachother.
*/
async addRelatedProducts( async addRelatedProducts(
_, _,
{ productId, articleNumbers }, { productId, articleNumbers },
@@ -275,6 +337,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function removeRelatedProducts
* @description remove relation between products
*/
async removeRelatedProducts( async removeRelatedProducts(
_, _,
{ productId, relatedProductIds }, { productId, relatedProductIds },
@@ -288,6 +355,10 @@ export const productMutationTypeDefs = {
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function addCategoriesToProduct
* @description Add categories to a product
*/
async addCategoriesToProduct( async addCategoriesToProduct(
_, _,
{ productId, categoryIds }, { productId, categoryIds },
@@ -301,6 +372,10 @@ export const productMutationTypeDefs = {
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function removeCategoriesFromProduct
* @description Remove categories from a product
*/
async removeCategoriesFromProduct( async removeCategoriesFromProduct(
_, _,
{ productId, categoryIds }, { productId, categoryIds },
@@ -313,6 +388,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
/**
* @function updateProductComments
* @description Mutate product comments
*/
async updateProductComments( async updateProductComments(
_, _,
{ productId, comments }, { productId, comments },