Add mutation to copy new s3 image as product image (#45)
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user