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 // mutations below
private async updateProductField( async updateProductField(
productId: number, productId: number,
field: string, field: string,
value: 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 { InteriorAPI } from '../datasources/interior-api';
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api'; import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
import { IdNumberResult } from '../types/types'; import { IdNumberResult } from '../types/types';
import { moveS3File } from '../s3';
const ProductBlacklist = { const ProductBlacklist = {
async market(parent, _args, { dataSources }) { async market(parent, _args, { dataSources }) {
@@ -173,6 +174,36 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); 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 }) { async addRelatedProducts(_, { productId, articleNumbers }, { dataSources }) {
await (<ProductAPI>dataSources.productApi).addRelatedProducts( await (<ProductAPI>dataSources.productApi).addRelatedProducts(
productId, productId,
@@ -180,7 +211,6 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
async removeRelatedProducts( async removeRelatedProducts(
_, _,
{ productId, relatedProductIds }, { productId, relatedProductIds },
+6
View File
@@ -455,6 +455,12 @@ type Mutation {
productId: Int! productId: Int!
wallpaperTypes: [ProductWallpaperType]! wallpaperTypes: [ProductWallpaperType]!
): Product ): Product
updateProductImage(
productId: Int!
uploadedS3Key: String!
width: Int!
height: Int!
): String
addRelatedProducts(productId: Int!, articleNumbers: [String]!): Product addRelatedProducts(productId: Int!, articleNumbers: [String]!): Product
removeRelatedProducts(productId: Int!, relatedProductIds: [Int]!): Product removeRelatedProducts(productId: Int!, relatedProductIds: [Int]!): Product