diff --git a/src/datasources/imageserver-api.ts b/src/datasources/imageserver-api.ts index cf6915c..b9ab7eb 100644 --- a/src/datasources/imageserver-api.ts +++ b/src/datasources/imageserver-api.ts @@ -1,6 +1,4 @@ import { RESTDataSource } from 'apollo-datasource-rest'; -import { InteriorType } from '../types/interior-types'; -import { Orientation } from '../types/product-types'; export class ImageServerApi extends RESTDataSource { constructor() { diff --git a/src/datasources/product-api.ts b/src/datasources/product-api.ts index 84506c2..5762a74 100644 --- a/src/datasources/product-api.ts +++ b/src/datasources/product-api.ts @@ -17,7 +17,7 @@ import { ProductSizeTypes, } from '../types/product-types'; import { Maybe } from '../types/types'; -import { convertToPossibleType, nullOrNumber } from './utils'; +import { nullOrNumber } from './utils'; const MINUTE = 60; @@ -296,6 +296,24 @@ export class ProductAPI extends BaseSQLDataSource { return Promise.all(insertsPromises); } + async setWallpaperTypes( + productId: number, + wallpaperTypes: Array, + ): Promise { + await this.knex('product_wallpapertypes') + .where('product_id', productId) + .del(); + + const promises = wallpaperTypes.map((wpt) => { + const typeId = ProductWallpaperType[wpt]; + return this.knex('product_wallpapertypes').insert({ + product_id: productId, + wallpapertype_id: typeId, + }); + }); + return Promise.all(promises); + } + async updateGroups(productId: number, groupIds: number[]): Promise { // Fetch the current state const allPrintProducts = await this.knex.raw( diff --git a/src/resolvers/products-resolver.ts b/src/resolvers/products-resolver.ts index 320563b..781db77 100644 --- a/src/resolvers/products-resolver.ts +++ b/src/resolvers/products-resolver.ts @@ -127,4 +127,15 @@ export const productMutationTypeDefs = { ); return (dataSources.productApi).getProduct(productId); }, + async productWallpaperType( + _, + { productId, wallpaperTypes }, + { dataSources }, + ) { + await (dataSources.productApi).setWallpaperTypes( + productId, + wallpaperTypes, + ); + return (dataSources.productApi).getProduct(productId); + }, }; diff --git a/src/schema.graphql b/src/schema.graphql index 1944340..5f36b2e 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -396,12 +396,20 @@ input ProductBlacklistingInput { type Mutation { productInfo(productId: Int!, info: ProductInfoInput!): Product - productFocusPoint(productId: Int!, focusXpoint2: Float!, focusYpoint2: Float!): Product + productFocusPoint( + productId: Int! + focusXpoint2: Float! + focusYpoint2: Float! + ): Product productBlacklisting( productId: Int! markets: [ProductBlacklistingInput] ): Product productGroup(productId: Int!, groupIds: [Int]): Product productKeywords(productId: Int!, keywordIds: [Int]): Product + productWallpaperType( + productId: Int! + wallpaperTypes: [ProductWallpaperType]! + ): Product addKeyword(name: String!, type: KeywordType): Keyword }