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>> {
return this.searchByFieldValue<Batch>(name, 36, 'batch');
}
async searchByCopyright(name: string): Promise<Array<Copyright>> {
return this.searchByFieldValue<Copyright>(name, 25, 'copyright');
}
async searchByFieldValue<T>(
name: string,
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(
path: string,
productId?: number,
@@ -359,6 +366,11 @@ export class ProductAPI extends BaseSQLDataSource {
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> {
const path = batch ? batch + ' ' + name : name;
const productPath = slug(path);
@@ -379,6 +391,10 @@ export class ProductAPI extends BaseSQLDataSource {
return id;
}
/**
* @function updateProductInfo
* @description Update base info for a product
*/
async updateProductInfo(
productId: number,
info: ProductInfoInput,
@@ -436,6 +452,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises);
}
/**
* @function updateFocusPoint
* @description Updates the focus point on a motif
*/
async updateFocusPoint(
productId: number,
focusXpoint2: number,
@@ -461,6 +481,10 @@ export class ProductAPI extends BaseSQLDataSource {
return this.updateProductField(productId, 'comments', comments);
}
/**
* @function updateBlacklisting
* @description Updates the blacklisted countries and sections
*/
async updateBlacklisting(
productId: number,
markets: Array<ProductBlacklistMarketInput>,
@@ -488,6 +512,11 @@ export class ProductAPI extends BaseSQLDataSource {
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(
productId: number,
wallpaperTypes: Array<ProductWallpaperType>,
@@ -506,6 +535,11 @@ export class ProductAPI extends BaseSQLDataSource {
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[]> {
// Fetch the current state
const allPrintProducts = await this.knex.raw(
@@ -627,6 +661,7 @@ export class ProductAPI extends BaseSQLDataSource {
/**
* @func productGroupInteriors
* @description Sets interiors to a product and product group
*
* @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
@@ -728,6 +763,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(insertPromises);
}
/**
* @function setProportionsWarning
* @description Sets propotion warning-values to a product
*/
async setProportionsWarning(
productId: number,
proportions: ProductProportionsInput,
@@ -764,6 +803,11 @@ export class ProductAPI extends BaseSQLDataSource {
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(
productId: number,
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
*/
async removeRelatedProducts(
@@ -825,6 +870,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises);
}
/**
* @function addCategoriesToProduct
* @description Adds a list of categories to a product
*/
async addCategoriesToProduct(
productId,
categoryIds,
@@ -838,6 +887,10 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises);
}
/**
* @function removeCategoriesFromProduct
* @description Removes list of categories from a product
*/
async removeCategoriesFromProduct(
productId,
categoryIds,
+80
View File
@@ -117,6 +117,10 @@ export const productQueryTypeDefs = {
///////////////////
// Mutations below
export const productMutationTypeDefs = {
/**
* @function addProduct
* @description Will add a product
*/
async addProduct(_, { name, batch }, { dataSources, auth }) {
checkAccess(['products.write'], auth);
const id = await (<ProductAPI>dataSources.productApi).addProduct(
@@ -125,6 +129,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(id);
},
/**
* @function productInfo
* @description Mutate base information about a product
*/
async productInfo(_, { productId, info }, { dataSources, auth }) {
checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateProductInfo(
@@ -133,6 +142,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function productFocusPoint
* @description Mutate the focuspoint for a product
*/
async productFocusPoint(
_,
{ productId, focusXpoint2, focusYpoint2 },
@@ -154,6 +168,11 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function productBlacklisting
* @description Mutate the product blacklist
*/
async productBlacklisting(_, { productId, markets }, { dataSources, auth }) {
checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateBlacklisting(
@@ -162,6 +181,11 @@ export const productMutationTypeDefs = {
);
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 }) {
checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).updateGroups(
@@ -176,6 +200,11 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product);
return product;
},
/**
* @function productGroupInteriors
* @description Mutate the list of interiors on a product and its groups.
*/
async productGroupInteriors(
_,
{ productId, groupId, uris },
@@ -189,6 +218,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function productKeywords
* @description Mutate the keywords for a product
*/
async productKeywords(_, { productId, keywordIds }, { dataSources, auth }) {
checkAccess(['products.write'], auth);
await (<KeywordAPI>dataSources.keywordApi).setProductKeywords(
@@ -197,6 +231,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function productProportionsWarning
* @description Mutate the values for proportion warnings on a product
*/
async productProportionsWarning(
_,
{ productId, proportions },
@@ -209,6 +248,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function addOwnInteriorToPrintProduct
* @description Add a uploaded interior image to a product and its groups.
*/
async addOwnInteriorToPrintProduct(
_,
{ printId, uploadedS3Key },
@@ -220,6 +264,11 @@ export const productMutationTypeDefs = {
uploadedS3Key,
);
},
/**
* @function productWallpaperType
* @description Set the wallpapertype for a wallpaper product
*/
async productWallpaperType(
_,
{ productId, wallpaperTypes },
@@ -232,6 +281,13 @@ export const productMutationTypeDefs = {
);
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(
_,
{ productId, uploadedS3Key, width, height },
@@ -263,6 +319,12 @@ export const productMutationTypeDefs = {
)).generateNewInteriors(product);
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(
_,
{ productId, articleNumbers },
@@ -275,6 +337,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function removeRelatedProducts
* @description remove relation between products
*/
async removeRelatedProducts(
_,
{ productId, relatedProductIds },
@@ -288,6 +355,10 @@ export const productMutationTypeDefs = {
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function addCategoriesToProduct
* @description Add categories to a product
*/
async addCategoriesToProduct(
_,
{ productId, categoryIds },
@@ -301,6 +372,10 @@ export const productMutationTypeDefs = {
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function removeCategoriesFromProduct
* @description Remove categories from a product
*/
async removeCategoriesFromProduct(
_,
{ productId, categoryIds },
@@ -313,6 +388,11 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function updateProductComments
* @description Mutate product comments
*/
async updateProductComments(
_,
{ productId, comments },