Add product blacklisting mutation (#18)
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
Orientation,
|
||||
ProductsFilterInput,
|
||||
ProductInfoInput,
|
||||
ProductBlacklistInput,
|
||||
ProductBlacklistMarketInput,
|
||||
} from '../types/product-types';
|
||||
import { Maybe } from '../types/types';
|
||||
import { convertToPossibleType } from './utils';
|
||||
@@ -200,4 +202,31 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
async updateBlacklisting(
|
||||
productId: number,
|
||||
markets: Array<ProductBlacklistMarketInput>,
|
||||
) {
|
||||
const sql = /* sql */ `
|
||||
INSERT INTO product_blacklist (product_id, group_id, market_id, created_at, updated_at)
|
||||
VALUES (?, ?, ?, now(), now())
|
||||
ON CONFLICT (product_id, group_id, market_id)
|
||||
DO NOTHING`;
|
||||
|
||||
const insertsPromises = [];
|
||||
const deleteQuery = this.knex.raw(
|
||||
/* sql */ `
|
||||
DELETE FROM product_blacklist WHERE product_id = ?
|
||||
`,
|
||||
[productId],
|
||||
);
|
||||
insertsPromises.push(deleteQuery);
|
||||
markets.forEach((market) => {
|
||||
market.groupIds.forEach((groupId) => {
|
||||
const query = this.knex.raw(sql, [productId, groupId, market.marketId]);
|
||||
insertsPromises.push(query);
|
||||
});
|
||||
});
|
||||
return Promise.all(insertsPromises);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ async function main() {
|
||||
resolvers,
|
||||
dataSources,
|
||||
context,
|
||||
introspection: false,
|
||||
introspection: true,
|
||||
});
|
||||
|
||||
await server.listen();
|
||||
|
||||
@@ -87,4 +87,11 @@ export const productMutationTypeDefs = {
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
async productBlacklisting(_, { productId, markets }, { dataSources }) {
|
||||
await (<ProductAPI>dataSources.productApi).updateBlacklisting(
|
||||
productId,
|
||||
markets,
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -382,6 +382,18 @@ input ProductInfoInput {
|
||||
visible: Boolean!
|
||||
}
|
||||
|
||||
input ProductBlacklistingInput {
|
||||
"""
|
||||
Only ones used are ProductGroup: PHOTO_WALLPAPER CANVAS WALLPAPER POSTER
|
||||
"""
|
||||
marketId: Int!
|
||||
groupIds: [Int]
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
productInfo(productId: Int!, info: ProductInfoInput!): Product
|
||||
productBlacklisting(
|
||||
productId: Int!
|
||||
markets: [ProductBlacklistingInput]
|
||||
): Product
|
||||
}
|
||||
|
||||
@@ -15,6 +15,16 @@ export interface ProductInfoInput {
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
export interface ProductBlacklistMarketInput {
|
||||
marketId: number;
|
||||
groupIds: Array<number>;
|
||||
}
|
||||
export interface ProductBlacklistInput {
|
||||
productId: number;
|
||||
markets: Array<ProductBlacklistMarketInput>;
|
||||
}
|
||||
|
||||
// query types
|
||||
export interface ProductsFilterInput {
|
||||
pagination: PaginationInput;
|
||||
filter?: ProductsFilter;
|
||||
|
||||
Reference in New Issue
Block a user