Add mutation for wallpaper types (#41)

This commit is contained in:
Niklas Fondberg
2021-09-13 09:25:42 +02:00
committed by GitHub
parent f0079086d9
commit 0a4be2b081
4 changed files with 39 additions and 4 deletions
-2
View File
@@ -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() {
+19 -1
View File
@@ -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(
+11
View File
@@ -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
View File
@@ -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
}