3769 - Differentiate forbidden and unauthenticated - add product group filter (#153)
This commit is contained in:
@@ -51,7 +51,7 @@ function throwForbidden() {
|
||||
extensions: {
|
||||
code: 'FORBIDDEN',
|
||||
http: {
|
||||
status: 401,
|
||||
status: 403,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -187,7 +187,7 @@ const verifyAuthentication = async (req: IncomingMessage) => {
|
||||
const notAuthorizedError = () => {
|
||||
throw new GraphQLError('You are not authorized', {
|
||||
extensions: {
|
||||
code: 'FORBIDDEN',
|
||||
code: 'UNAUTHENTICATED',
|
||||
http: {
|
||||
status: 401,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Orientation,
|
||||
PrintProduct,
|
||||
Product,
|
||||
ProductGroup,
|
||||
ProductListResult,
|
||||
ProductsFilterInput,
|
||||
ProductsSearchResult,
|
||||
@@ -32,6 +33,17 @@ const ProductBlacklist = {
|
||||
};
|
||||
|
||||
const Product = {
|
||||
async printProducts(
|
||||
product: { printProducts: PrintProduct[] },
|
||||
input: { groups: ProductGroup[] },
|
||||
) {
|
||||
if (!input.groups) {
|
||||
return product.printProducts;
|
||||
}
|
||||
return product.printProducts.filter((printProduct) => {
|
||||
return input.groups.includes(printProduct.group);
|
||||
});
|
||||
},
|
||||
async categories({ id }, _args, { dataSources }): Promise<Array<Category>> {
|
||||
return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id);
|
||||
},
|
||||
|
||||
+1
-1
@@ -254,7 +254,7 @@ type Product {
|
||||
inserted: DateTime!
|
||||
updated: DateTime
|
||||
publishingDate: DateTime!
|
||||
printProducts: [PrintProduct]
|
||||
printProducts(groups: [ProductGroup]): [PrintProduct]
|
||||
blacklisting: [ProductBlacklist]
|
||||
categories: [Category]
|
||||
designerId: Int
|
||||
|
||||
Reference in New Issue
Block a user