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
+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(