Add mutation for wallpaper types (#41)
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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<ProductWallpaperType>,
|
||||
): Promise<any[]> {
|
||||
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<any[]> {
|
||||
// Fetch the current state
|
||||
const allPrintProducts = await this.knex.raw(
|
||||
|
||||
@@ -127,4 +127,15 @@ export const productMutationTypeDefs = {
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
async productWallpaperType(
|
||||
_,
|
||||
{ productId, wallpaperTypes },
|
||||
{ dataSources },
|
||||
) {
|
||||
await (<ProductAPI>dataSources.productApi).setWallpaperTypes(
|
||||
productId,
|
||||
wallpaperTypes,
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
};
|
||||
|
||||
+9
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user