Add mutation to copy new s3 image as product image (#45)
This commit is contained in:
@@ -199,7 +199,7 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
}
|
||||
|
||||
// mutations below
|
||||
private async updateProductField(
|
||||
async updateProductField(
|
||||
productId: number,
|
||||
field: string,
|
||||
value: string,
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user