3769 - Differentiate forbidden and unauthenticated - add product group filter (#153)

This commit is contained in:
Anders Gustafsson
2023-05-23 08:40:44 +02:00
committed by GitHub
parent 7f341f510e
commit 6feb7ee388
7 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ function throwForbidden() {
extensions: {
code: 'FORBIDDEN',
http: {
status: 401,
status: 403,
},
},
});
+1 -1
View File
@@ -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,
},
+12
View File
@@ -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
View File
@@ -254,7 +254,7 @@ type Product {
inserted: DateTime!
updated: DateTime
publishingDate: DateTime!
printProducts: [PrintProduct]
printProducts(groups: [ProductGroup]): [PrintProduct]
blacklisting: [ProductBlacklist]
categories: [Category]
designerId: Int