Add mutation to copy new s3 image as product image (#45)

This commit is contained in:
Niklas Fondberg
2021-09-16 15:58:33 +02:00
committed by GitHub
parent e52c7d4522
commit 9059bc5d8d
3 changed files with 38 additions and 2 deletions
+1 -1
View File
@@ -199,7 +199,7 @@ export class ProductAPI extends BaseSQLDataSource {
}
// mutations below
private async updateProductField(
async updateProductField(
productId: number,
field: string,
value: string,
+31 -1
View File
@@ -13,6 +13,7 @@ import { MarketLocaleAPI } from '../datasources/market-locale-api';
import { InteriorAPI } from '../datasources/interior-api';
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
import { IdNumberResult } from '../types/types';
import { moveS3File } from '../s3';
const ProductBlacklist = {
async market(parent, _args, { dataSources }) {
@@ -173,6 +174,36 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
async updateProductImage(
_,
{ productId, uploadedS3Key, width, height },
{ dataSources },
) {
await moveS3File(
CONFIG.uploadBucket,
uploadedS3Key,
CONFIG.imageBucket,
`products/${productId}.jpg`,
);
await (<ProductAPI>dataSources.productApi).updateProductField(
productId,
'width',
width.toString(),
);
await (<ProductAPI>dataSources.productApi).updateProductField(
productId,
'height',
height.toString(),
);
const product = await (<ProductAPI>dataSources.productApi).getProduct(
productId,
);
await (<InteriorsLambdaAPI>(
dataSources.interiorsLambdaApi
)).generateNewInteriors(product);
return 'success';
},
async addRelatedProducts(_, { productId, articleNumbers }, { dataSources }) {
await (<ProductAPI>dataSources.productApi).addRelatedProducts(
productId,
@@ -180,7 +211,6 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
async removeRelatedProducts(
_,
{ productId, relatedProductIds },
+6
View File
@@ -455,6 +455,12 @@ type Mutation {
productId: Int!
wallpaperTypes: [ProductWallpaperType]!
): Product
updateProductImage(
productId: Int!
uploadedS3Key: String!
width: Int!
height: Int!
): String
addRelatedProducts(productId: Int!, articleNumbers: [String]!): Product
removeRelatedProducts(productId: Int!, relatedProductIds: [Int]!): Product